8ca7207de60376a784542d549b2de85166e97540
diff --git a/libsoup/soup-cookie-jar.c b/libsoup/soup-cookie-jar.c
index bf41476..9af0560 100644
--- a/libsoup/soup-cookie-jar.c
+++ b/libsoup/soup-cookie-jar.c
@@ -167,6 +167,7 @@ soup_cookie_jar_get_cookies (SoupCookieJar *jar, SoupURI *uri,
 	SoupCookieJarPrivate *priv;
 	GSList *cookies, *domain_cookies;
 	char *domain, *cur, *next, *result;
+	GSList *new_head, *cookies_to_remove = NULL, *p;
 
 	g_return_val_if_fail (SOUP_IS_COOKIE_JAR (jar), NULL);
 	priv = SOUP_COOKIE_JAR_GET_PRIVATE (jar);
@@ -180,14 +181,23 @@ soup_cookie_jar_get_cookies (SoupCookieJar *jar, SoupURI *uri,
 	domain = cur = g_strdup_printf (".%s", uri->host);
 	next = domain + 1;
 	do {
-		domain_cookies = g_hash_table_lookup (priv->domains, cur);
+		new_head = domain_cookies = g_hash_table_lookup (priv->domains, cur);
 		while (domain_cookies) {
+			GSList *next = domain_cookies->next;
 			SoupCookie *cookie = domain_cookies->data;
 
-			if (soup_cookie_applies_to_uri (cookie, uri) &&
-			    (for_http || !cookie->http_only))
+			if (cookie->expires && soup_date_is_past (cookie->expires)) {
+				cookies_to_remove = g_slist_append (cookies_to_remove,
+								    cookie);
+				new_head = g_slist_delete_link (new_head, domain_cookies);
+				g_hash_table_insert (priv->domains,
+						     g_strdup (cur),
+						     new_head);
+			} else if (soup_cookie_applies_to_uri (cookie, uri) &&
+				   (for_http || !cookie->http_only))
 				cookies = g_slist_append (cookies, cookie);
-			domain_cookies = domain_cookies->next;
+
+			domain_cookies = next;
 		}
 		cur = next;
 		if (cur)
@@ -195,6 +205,15 @@ soup_cookie_jar_get_cookies (SoupCookieJar *jar, SoupURI *uri,
 	} while (cur);
 	g_free (domain);
 
+	for (p = cookies_to_remove; p; p = p->next) {
+		SoupCookie *cookie = p->data;
+
+		g_signal_emit (jar, signals[CHANGED], 0,
+			       cookie, NULL);
+		soup_cookie_free (cookie);
+	}
+	g_slist_free (cookies_to_remove);
+
 	if (cookies) {
 		/* FIXME: sort? */
 		result = soup_cookies_to_cookie_header (cookies);
