soup_message_headers_append (headers, name, value);
}
+static char *hop_by_hop_headers[] = {"Connection", "Keep-Alive", "Proxy-Authenticate", "Proxy-Authorization", "TE", "Trailer", "Transfer-Encoding", "Upgrade"};
+
static void
-update_headers (const char *name, const char *value, SoupMessageHeaders *headers)
+copy_end_to_end_headers (SoupMessageHeaders *source, SoupMessageHeaders *destination)
{
- if (soup_message_headers_get (headers, name))
- soup_message_headers_replace (headers, name, value);
- else
- soup_message_headers_append (headers, name, value);
+ int i;
+
+ soup_message_headers_foreach (source, (SoupMessageHeadersForeachFunc) copy_headers, destination);
+ for (i = 0; i < G_N_ELEMENTS (hop_by_hop_headers); i++)
+ soup_message_headers_remove (destination, hop_by_hop_headers[i]);
+ soup_message_headers_clean_connection_headers (destination);
}
static guint
soup_cache_entry_new (SoupCache *cache, SoupMessage *msg, time_t request_time, time_t response_time)
{
SoupCacheEntry *entry;
- SoupMessageHeaders *headers;
const char *date;
char *md5;
g_free (md5);
/* Headers */
- headers = soup_message_headers_new (SOUP_MESSAGE_HEADERS_RESPONSE);
- soup_message_headers_foreach (msg->response_headers,
- (SoupMessageHeadersForeachFunc)copy_headers,
- headers);
- entry->headers = headers;
+ entry->headers = soup_message_headers_new (SOUP_MESSAGE_HEADERS_RESPONSE);
+ copy_end_to_end_headers (msg->response_headers, entry->headers);
/* LRU list */
entry->hits = 0;
*/
if (entry) {
entry->being_validated = FALSE;
-
- /* We update the headers of the existing cache item,
- plus its age */
- soup_message_headers_foreach (msg->response_headers,
- (SoupMessageHeadersForeachFunc)update_headers,
- entry->headers);
+ copy_end_to_end_headers (msg->response_headers, entry->headers);
soup_cache_entry_set_freshness (entry, msg, cache);
}
}
entry->being_validated = FALSE;
/* Headers */
- soup_message_headers_foreach (entry->headers,
- (SoupMessageHeadersForeachFunc)update_headers,
- msg->response_headers);
+ copy_end_to_end_headers (entry->headers, msg->response_headers);
/* Add 'Age' header with the current age */
current_age = g_strdup_printf ("%d", soup_cache_entry_get_current_age (entry));
return success;
}
-/* RFC 2616 14.10 */
-static void
-soup_headers_clean_for_10 (SoupMessageHeaders *hdrs)
-{
- const char *connection;
- GSList *tokens, *t;
-
- connection = soup_message_headers_get_list (hdrs, "Connection");
- if (!connection)
- return;
-
- tokens = soup_header_parse_list (connection);
- for (t = tokens; t; t = t->next)
- soup_message_headers_remove (hdrs, t->data);
- soup_header_free_list (tokens);
-}
-
/**
* soup_headers_parse_request:
* @str: the header string (including the trailing blank line)
if (soup_message_headers_get_expectations (req_headers) &
SOUP_EXPECTATION_UNRECOGNIZED)
return SOUP_STATUS_EXPECTATION_FAILED;
+ /* RFC 2616 14.10 */
if (minor_version == 0)
- soup_headers_clean_for_10 (req_headers);
+ soup_message_headers_clean_connection_headers (req_headers);
if (req_method)
*req_method = g_strndup (method, method_end - method);
if (ver)
*ver = version;
+ /* RFC 2616 14.10 */
if (version == SOUP_HTTP_1_0)
- soup_headers_clean_for_10 (headers);
+ soup_message_headers_clean_connection_headers (headers);
return TRUE;
}
}
/**
+ * soup_message_headers_clean_connection_headers:
+ * @hdrs: a #SoupMessageHeaders
+ *
+ * Removes all the headers listed in the Connection header.
+ *
+ **/
+void
+soup_message_headers_clean_connection_headers (SoupMessageHeaders *hdrs)
+{
+ /* RFC 2616 14.10 */
+ const char *connection;
+ GSList *tokens, *t;
+
+ connection = soup_message_headers_get_list (hdrs, "Connection");
+ if (!connection)
+ return;
+
+ tokens = soup_header_parse_list (connection);
+ for (t = tokens; t; t = t->next)
+ soup_message_headers_remove (hdrs, t->data);
+ soup_header_free_list (tokens);
+}
+
+/**
* soup_message_headers_append:
* @hdrs: a #SoupMessageHeaders
* @name: the header name to add