diff --git a/libs/libsoup/libsoup/soup-cookie.c b/libs/libsoup/libsoup/soup-cookie.c
index 731a4a5..f497f84 100755
--- a/libs/libsoup/libsoup/soup-cookie.c
+++ b/libs/libsoup/libsoup/soup-cookie.c
@@ -89,7 +89,7 @@ soup_cookie_copy (SoupCookie *cookie)
 
 	copy->name = g_strdup (cookie->name);
 	copy->value = g_strdup (cookie->value);
-	copy->domain = g_strdup (cookie->domain);
+	soup_cookie_set_domain(copy, cookie->domain);
 	copy->path = g_strdup (cookie->path);
 	if (cookie->expires)
 		copy->expires = soup_date_copy(cookie->expires);
@@ -233,11 +233,9 @@ parse_one_cookie (const char *header, SoupURI *origin)
 #define MATCH_NAME(name) ((end - start == strlen (name)) && !g_ascii_strncasecmp (start, name, end - start))
 
 		if (MATCH_NAME ("domain") && has_value) {
-			cookie->domain = parse_value (&p, TRUE);
-			if (!*cookie->domain) {
-				g_free (cookie->domain);
-				cookie->domain = NULL;
-			}
+			char* domain = parse_value (&p, TRUE);
+			soup_cookie_set_domain (cookie, domain);
+			g_free (domain);
 		} else if (MATCH_NAME ("expires") && has_value) {
 			cookie->expires = parse_date (&p);
 		} else if (MATCH_NAME ("httponly")) {
@@ -283,16 +281,6 @@ parse_one_cookie (const char *header, SoupURI *origin)
 			soup_cookie_free (cookie);
 			return NULL;
 		}
-
-		/* If the domain string isn't an IP addr, and doesn't
-		 * start with a '.', prepend one.
-		 */
-		if (!g_hostname_is_ip_address (cookie->domain) &&
-		    cookie->domain[0] != '.') {
-			char *tmp = g_strdup_printf (".%s", cookie->domain);
-			g_free (cookie->domain);
-			cookie->domain = tmp;
-		}
 	}
 
 	if (origin) {
@@ -303,7 +291,7 @@ parse_one_cookie (const char *header, SoupURI *origin)
 				return NULL;
 			}
 		} else
-			cookie->domain = g_strdup (origin->host);
+			soup_cookie_set_domain(cookie, origin->host);
 
 		/* The original cookie spec didn't say that pages
 		 * could only set cookies for paths they were under.
@@ -339,7 +327,7 @@ cookie_new_internal (const char *name, const char *value,
 	cookie = g_slice_new0 (SoupCookie);
 	cookie->name = g_strdup (name);
 	cookie->value = g_strdup (value);
-	cookie->domain = g_strdup (domain);
+	soup_cookie_set_domain(cookie, domain);
 	cookie->path = g_strdup (path);
 	soup_cookie_set_max_age (cookie, max_age);
 
@@ -512,7 +500,13 @@ void
 soup_cookie_set_domain (SoupCookie *cookie, const char *domain)
 {
 	g_free (cookie->domain);
-	cookie->domain = g_strdup (domain);
+	if (!domain || !domain[0]) {
+		cookie->domain = NULL;
+	} else if (!g_hostname_is_ip_address(domain) && domain[0] != '.') {
+		cookie->domain = g_strdup_printf (".%s", domain);
+	} else {
+		cookie->domain = g_strdup (domain);
+	}
 }
 
 /**
