[libsoup/carlosgc/headers-no-intern: 5/5] Use header fast paths internally whenever possible




commit f507bb27d0de469cd5a0442ab79b75fc106be58a
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Thu Jun 3 09:30:09 2021 +0200

    Use header fast paths internally whenever possible

 libsoup/auth/soup-auth-digest.c                |  9 +--
 libsoup/auth/soup-auth-manager.c               | 15 ++---
 libsoup/auth/soup-auth-negotiate.c             |  5 +-
 libsoup/auth/soup-auth-ntlm.c                  |  5 +-
 libsoup/cache/soup-cache.c                     | 54 +++++++++-------
 libsoup/content-decoder/soup-content-decoder.c | 14 ++---
 libsoup/content-sniffer/soup-content-sniffer.c |  3 +-
 libsoup/cookies/soup-cookie-jar.c              |  5 +-
 libsoup/cookies/soup-cookie.c                  | 15 ++---
 libsoup/http1/soup-client-message-io-http1.c   | 13 ++--
 libsoup/server/soup-auth-domain-basic.c        |  5 +-
 libsoup/server/soup-auth-domain-digest.c       |  5 +-
 libsoup/server/soup-auth-domain.c              | 19 +++---
 libsoup/server/soup-server-io.c                | 16 ++---
 libsoup/server/soup-server-message.c           | 29 +++++----
 libsoup/server/soup-server.c                   | 12 ++--
 libsoup/soup-message-headers.c                 | 58 +++++++++--------
 libsoup/soup-message.c                         | 36 ++++++-----
 libsoup/soup-multipart.c                       |  9 +--
 libsoup/soup-session.c                         | 15 ++---
 libsoup/websocket/soup-websocket.c             | 87 +++++++++++++-------------
 21 files changed, 233 insertions(+), 196 deletions(-)
---
diff --git a/libsoup/auth/soup-auth-digest.c b/libsoup/auth/soup-auth-digest.c
index a46a23f8..05c2ce12 100644
--- a/libsoup/auth/soup-auth-digest.c
+++ b/libsoup/auth/soup-auth-digest.c
@@ -14,6 +14,7 @@
 #include "auth/soup-auth-digest-private.h"
 #include "soup.h"
 #include "soup-message-private.h"
+#include "soup-message-headers-private.h"
 #include "soup-uri-utils-private.h"
 
 #ifdef G_OS_WIN32
@@ -391,10 +392,10 @@ authentication_info_cb (SoupMessage *msg, gpointer data)
        if (auth != soup_message_get_auth (msg))
                return;
 
-       header = soup_message_headers_get_one (soup_message_get_response_headers (msg),
-                                              soup_auth_is_for_proxy (auth) ?
-                                              "Proxy-Authentication-Info" :
-                                              "Authentication-Info");
+       header = soup_message_headers_get_one_common (soup_message_get_response_headers (msg),
+                                                      soup_auth_is_for_proxy (auth) ?
+                                                      SOUP_HEADER_PROXY_AUTHENTICATION_INFO :
+                                                      SOUP_HEADER_AUTHENTICATION_INFO);
        g_return_if_fail (header != NULL);
 
        auth_params = soup_header_parse_param_list (header);
diff --git a/libsoup/auth/soup-auth-manager.c b/libsoup/auth/soup-auth-manager.c
index 6ef5377c..266f88c5 100644
--- a/libsoup/auth/soup-auth-manager.c
+++ b/libsoup/auth/soup-auth-manager.c
@@ -15,6 +15,7 @@
 #include "soup.h"
 #include "soup-connection-auth.h"
 #include "soup-message-private.h"
+#include "soup-message-headers-private.h"
 #include "soup-path-map.h"
 #include "soup-session-private.h"
 #include "soup-session-feature-private.h"
@@ -242,11 +243,11 @@ static inline const char *
 auth_header_for_message (SoupMessage *msg)
 {
        if (soup_message_get_status (msg) == SOUP_STATUS_PROXY_UNAUTHORIZED) {
-               return soup_message_headers_get_list (soup_message_get_response_headers (msg),
-                                                     "Proxy-Authenticate");
+               return soup_message_headers_get_list_common (soup_message_get_response_headers (msg),
+                                                             SOUP_HEADER_PROXY_AUTHENTICATE);
        } else {
-               return soup_message_headers_get_list (soup_message_get_response_headers (msg),
-                                                     "WWW-Authenticate");
+               return soup_message_headers_get_list_common (soup_message_get_response_headers (msg),
+                                                             SOUP_HEADER_WWW_AUTHENTICATE);
        }
 }
 
@@ -442,11 +443,11 @@ make_auto_ntlm_auth (SoupAuthManagerPrivate *priv, SoupAuthHost *host)
 static void
 update_authorization_header (SoupMessage *msg, SoupAuth *auth, gboolean is_proxy)
 {
-       const char *authorization_header = is_proxy ? "Proxy-Authorization" : "Authorization";
+        SoupHeaderName authorization_header = is_proxy ? SOUP_HEADER_PROXY_AUTHORIZATION : 
SOUP_HEADER_AUTHORIZATION;
        char *token;
 
        if (soup_message_get_auth (msg))
-               soup_message_headers_remove (soup_message_get_request_headers (msg), authorization_header);
+               soup_message_headers_remove_common (soup_message_get_request_headers (msg), 
authorization_header);
 
        if (!auth)
                return;
@@ -455,7 +456,7 @@ update_authorization_header (SoupMessage *msg, SoupAuth *auth, gboolean is_proxy
        if (!token)
                return;
 
-       soup_message_headers_replace (soup_message_get_request_headers (msg), authorization_header, token);
+       soup_message_headers_replace_common (soup_message_get_request_headers (msg), authorization_header, 
token);
        g_free (token);
 }
 
diff --git a/libsoup/auth/soup-auth-negotiate.c b/libsoup/auth/soup-auth-negotiate.c
index 17a58364..11672973 100644
--- a/libsoup/auth/soup-auth-negotiate.c
+++ b/libsoup/auth/soup-auth-negotiate.c
@@ -20,6 +20,7 @@
 #include "soup-headers.h"
 #include "soup-message.h"
 #include "soup-message-private.h"
+#include "soup-message-headers-private.h"
 #include "soup-misc.h"
 #include "soup-uri-utils-private.h"
 
@@ -357,8 +358,8 @@ check_server_response (SoupMessage *msg, gpointer auth)
                return;
 
        /* FIXME: need to check for proxy-auth too */
-       auth_headers = soup_message_headers_get_one (soup_message_get_response_headers (msg),
-                                                    "WWW-Authenticate");
+       auth_headers = soup_message_headers_get_one_common (soup_message_get_response_headers (msg),
+                                                            SOUP_HEADER_WWW_AUTHENTICATE);
        if (!auth_headers || g_ascii_strncasecmp (auth_headers, "Negotiate ", 10) != 0) {
                g_warning ("Failed to parse auth header");
                conn->state = SOUP_NEGOTIATE_FAILED;
diff --git a/libsoup/auth/soup-auth-ntlm.c b/libsoup/auth/soup-auth-ntlm.c
index e54c8381..61c4a38a 100644
--- a/libsoup/auth/soup-auth-ntlm.c
+++ b/libsoup/auth/soup-auth-ntlm.c
@@ -19,6 +19,7 @@
 #include "soup-auth-ntlm.h"
 #include "soup.h"
 #include "soup-message-private.h"
+#include "soup-message-headers-private.h"
 
 static void        soup_ntlm_lanmanager_hash   (const char  *password,
                                                guchar       hash[21]);
@@ -326,8 +327,8 @@ soup_auth_ntlm_update_connection (SoupConnectionAuth *auth, SoupMessage *msg,
                         */
                        conn->state = SOUP_NTLM_FAILED;
                        if (soup_message_is_keepalive (msg)) {
-                               soup_message_headers_append (soup_message_get_response_headers (msg),
-                                                            "Connection", "close");
+                               soup_message_headers_append_common (soup_message_get_response_headers (msg),
+                                                                    SOUP_HEADER_CONNECTION, "close");
                        }
                        return TRUE;
                }
diff --git a/libsoup/cache/soup-cache.c b/libsoup/cache/soup-cache.c
index 8dfef003..2ff9777d 100644
--- a/libsoup/cache/soup-cache.c
+++ b/libsoup/cache/soup-cache.c
@@ -39,6 +39,7 @@
 #include "soup-cache-private.h"
 #include "soup-content-processor.h"
 #include "soup-message-private.h"
+#include "soup-message-headers-private.h"
 #include "soup.h"
 #include "soup-message-metrics-private.h"
 #include "soup-misc.h"
@@ -184,7 +185,7 @@ get_cacheability (SoupCache *cache, SoupMessage *msg)
        if (content_type && !g_ascii_strcasecmp (content_type, "multipart/x-mixed-replace"))
                return SOUP_CACHE_UNCACHEABLE;
 
-       cache_control = soup_message_headers_get_list (soup_message_get_response_headers (msg), 
"Cache-Control");
+       cache_control = soup_message_headers_get_list_common (soup_message_get_response_headers (msg), 
SOUP_HEADER_CACHE_CONTROL);
        if (cache_control && *cache_control) {
                GHashTable *hash;
 
@@ -222,7 +223,7 @@ get_cacheability (SoupCache *cache, SoupMessage *msg)
 
        /* Section 13.9 */
        if ((g_uri_get_query (soup_message_get_uri (msg))) &&
-           !soup_message_headers_get_one (soup_message_get_response_headers (msg), "Expires") &&
+           !soup_message_headers_get_one_common (soup_message_get_response_headers (msg), 
SOUP_HEADER_EXPIRES) &&
            !has_max_age)
                return SOUP_CACHE_UNCACHEABLE;
 
@@ -307,7 +308,16 @@ remove_headers (const char *name, const char *value, SoupMessageHeaders *headers
        soup_message_headers_remove (headers, name);
 }
 
-static char *hop_by_hop_headers[] = {"Connection", "Keep-Alive", "Proxy-Authenticate", 
"Proxy-Authorization", "TE", "Trailer", "Transfer-Encoding", "Upgrade"};
+static SoupHeaderName hop_by_hop_headers[] = {
+        SOUP_HEADER_CONNECTION,
+        SOUP_HEADER_KEEP_ALIVE,
+        SOUP_HEADER_PROXY_AUTHENTICATE,
+        SOUP_HEADER_PROXY_AUTHORIZATION,
+        SOUP_HEADER_TE,
+        SOUP_HEADER_TRAILER,
+        SOUP_HEADER_TRANSFER_ENCODING,
+        SOUP_HEADER_UPGRADE
+};
 
 static void
 copy_end_to_end_headers (SoupMessageHeaders *source, SoupMessageHeaders *destination)
@@ -316,7 +326,7 @@ copy_end_to_end_headers (SoupMessageHeaders *source, SoupMessageHeaders *destina
 
        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_remove_common (destination, hop_by_hop_headers[i]);
        soup_message_headers_clean_connection_headers (destination);
 }
 
@@ -355,7 +365,7 @@ soup_cache_entry_set_freshness (SoupCacheEntry *entry, SoupMessage *msg, SoupCac
        entry->must_revalidate = FALSE;
        entry->freshness_lifetime = 0;
 
-       cache_control = soup_message_headers_get_list (entry->headers, "Cache-Control");
+       cache_control = soup_message_headers_get_list_common (entry->headers, SOUP_HEADER_CACHE_CONTROL);
        if (cache_control && *cache_control) {
                const char *max_age, *s_maxage;
                gint64 freshness_lifetime = 0;
@@ -398,8 +408,8 @@ soup_cache_entry_set_freshness (SoupCacheEntry *entry, SoupMessage *msg, SoupCac
        /* If the 'Expires' response header is present, use its value
         * minus the value of the 'Date' response header
         */
-       expires = soup_message_headers_get_one (entry->headers, "Expires");
-       date = soup_message_headers_get_one (entry->headers, "Date");
+       expires = soup_message_headers_get_one_common (entry->headers, SOUP_HEADER_EXPIRES);
+       date = soup_message_headers_get_one_common (entry->headers, SOUP_HEADER_DATE);
        if (expires && date) {
                GDateTime *expires_d, *date_d;
                time_t expires_t, date_t;
@@ -443,7 +453,7 @@ soup_cache_entry_set_freshness (SoupCacheEntry *entry, SoupMessage *msg, SoupCac
           than 24h (section 2.3.1.1) when using heuristics */
 
        /* Last-Modified based heuristic */
-       last_modified = soup_message_headers_get_one (entry->headers, "Last-Modified");
+       last_modified = soup_message_headers_get_one_common (entry->headers, SOUP_HEADER_LAST_MODIFIED);
        if (last_modified) {
                GDateTime *soup_date;
                time_t now, last_modified_t;
@@ -489,7 +499,7 @@ soup_cache_entry_new (SoupCache *cache, SoupMessage *msg, time_t request_time, t
        soup_cache_entry_set_freshness (entry, msg, cache);
 
        /* Section 2.3.2, Calculating Age */
-       date = soup_message_headers_get_one (entry->headers, "Date");
+       date = soup_message_headers_get_one_common (entry->headers, SOUP_HEADER_DATE);
 
        if (date) {
                GDateTime *soup_date;
@@ -500,7 +510,7 @@ soup_cache_entry_new (SoupCache *cache, SoupMessage *msg, time_t request_time, t
                date_value = g_date_time_to_unix (soup_date);
                g_date_time_unref (soup_date);
 
-               age = soup_message_headers_get_one (entry->headers, "Age");
+               age = soup_message_headers_get_one_common (entry->headers, SOUP_HEADER_AGE);
                if (age)
                        age_value = g_ascii_strtoll (age, NULL, 10);
 
@@ -1145,8 +1155,8 @@ soup_cache_has_response (SoupCache *cache, SoupMessage *msg)
 
        /* 4. The request is a conditional request issued by the client.
         */
-       if (soup_message_headers_get_one (soup_message_get_request_headers (msg), "If-Modified-Since") ||
-           soup_message_headers_get_list (soup_message_get_request_headers (msg), "If-None-Match"))
+       if (soup_message_headers_get_one_common (soup_message_get_request_headers (msg), 
SOUP_HEADER_IF_MODIFIED_SINCE) ||
+           soup_message_headers_get_list_common (soup_message_get_request_headers (msg), 
SOUP_HEADER_IF_NONE_MATCH))
                return SOUP_CACHE_RESPONSE_STALE;
 
        /* 5. The presented request and stored response are free from
@@ -1157,10 +1167,10 @@ soup_cache_has_response (SoupCache *cache, SoupMessage *msg)
 
        /* For HTTP 1.0 compatibility. RFC2616 section 14.9.4
         */
-       if (soup_message_headers_header_contains (soup_message_get_request_headers (msg), "Pragma", 
"no-cache"))
+       if (soup_message_headers_header_contains_common (soup_message_get_request_headers (msg), 
SOUP_HEADER_PRAGMA, "no-cache"))
                return SOUP_CACHE_RESPONSE_STALE;
 
-       cache_control = soup_message_headers_get_list (soup_message_get_request_headers (msg), 
"Cache-Control");
+       cache_control = soup_message_headers_get_list_common (soup_message_get_request_headers (msg), 
SOUP_HEADER_CACHE_CONTROL);
        if (cache_control && *cache_control) {
                GHashTable *hash = soup_header_parse_param_list (cache_control);
 
@@ -1391,8 +1401,8 @@ soup_cache_generate_conditional_request (SoupCache *cache, SoupMessage *original
        entry = soup_cache_entry_lookup (cache, original);
        g_return_val_if_fail (entry, NULL);
 
-       last_modified = soup_message_headers_get_one (entry->headers, "Last-Modified");
-       etag = soup_message_headers_get_one (entry->headers, "ETag");
+       last_modified = soup_message_headers_get_one_common (entry->headers, SOUP_HEADER_LAST_MODIFIED);
+       etag = soup_message_headers_get_one_common (entry->headers, SOUP_HEADER_ETAG);
 
        if (!last_modified && !etag)
                return NULL;
@@ -1415,13 +1425,13 @@ soup_cache_generate_conditional_request (SoupCache *cache, SoupMessage *original
        g_list_free (disabled_features);
 
        if (last_modified)
-               soup_message_headers_append (soup_message_get_request_headers (msg),
-                                            "If-Modified-Since",
-                                            last_modified);
+               soup_message_headers_append_common (soup_message_get_request_headers (msg),
+                                                    SOUP_HEADER_IF_MODIFIED_SINCE,
+                                                    last_modified);
        if (etag)
-               soup_message_headers_append (soup_message_get_request_headers (msg),
-                                            "If-None-Match",
-                                            etag);
+               soup_message_headers_append_common (soup_message_get_request_headers (msg),
+                                                    SOUP_HEADER_IF_NONE_MATCH,
+                                                    etag);
 
        return msg;
 }
diff --git a/libsoup/content-decoder/soup-content-decoder.c b/libsoup/content-decoder/soup-content-decoder.c
index 7f36d0cf..81dca039 100644
--- a/libsoup/content-decoder/soup-content-decoder.c
+++ b/libsoup/content-decoder/soup-content-decoder.c
@@ -13,6 +13,7 @@
 #include "soup-converter-wrapper.h"
 #include "soup-session-feature-private.h"
 #include "soup-message-private.h"
+#include "soup-message-headers-private.h"
 #include "soup-headers.h"
 #include "soup-uri-utils-private.h"
 #ifdef WITH_BROTLI
@@ -86,8 +87,8 @@ soup_content_decoder_get_decoders_for_msg (SoupContentDecoder *decoder, SoupMess
        SoupContentDecoderCreator converter_creator;
        GConverter *converter;
 
-       header = soup_message_headers_get_list (soup_message_get_response_headers (msg),
-                                               "Content-Encoding");
+       header = soup_message_headers_get_list_common (soup_message_get_response_headers (msg),
+                                                       SOUP_HEADER_CONTENT_ENCODING);
        if (!header)
                return NULL;
 
@@ -239,8 +240,8 @@ static void
 soup_content_decoder_request_queued (SoupSessionFeature *feature,
                                     SoupMessage        *msg)
 {
-       if (!soup_message_headers_get_one (soup_message_get_request_headers (msg),
-                                          "Accept-Encoding")) {
+       if (!soup_message_headers_get_one_common (soup_message_get_request_headers (msg),
+                                                  SOUP_HEADER_ACCEPT_ENCODING)) {
                 const char *header = "gzip, deflate";
 
 #ifdef WITH_BROTLI
@@ -253,9 +254,8 @@ soup_content_decoder_request_queued (SoupSessionFeature *feature,
                         header = "gzip, deflate, br";
 #endif
 
-               soup_message_headers_append (soup_message_get_request_headers (msg),
-                                            "Accept-Encoding",
-                                            header);
+               soup_message_headers_append_common (soup_message_get_request_headers (msg),
+                                                    SOUP_HEADER_ACCEPT_ENCODING, header);
        }
 }
 
diff --git a/libsoup/content-sniffer/soup-content-sniffer.c b/libsoup/content-sniffer/soup-content-sniffer.c
index 7319a7f9..50a636bc 100644
--- a/libsoup/content-sniffer/soup-content-sniffer.c
+++ b/libsoup/content-sniffer/soup-content-sniffer.c
@@ -20,6 +20,7 @@
 #include "soup-content-processor.h"
 #include "soup-content-sniffer-stream.h"
 #include "soup-message-private.h"
+#include "soup-message-headers-private.h"
 #include "soup-session-feature-private.h"
 
 /**
@@ -807,7 +808,7 @@ soup_content_sniffer_sniff (SoupContentSniffer *sniffer, SoupMessage *msg,
 
        /* MIMESNIFF: 7 Determining the sniffed MIME type of a resource. */
 
-       x_content_type_options = soup_message_headers_get_one (soup_message_get_response_headers (msg), 
"X-Content-Type-Options");
+       x_content_type_options = soup_message_headers_get_one_common (soup_message_get_response_headers 
(msg), SOUP_HEADER_X_CONTENT_TYPE_OPTIONS);
        if (!g_strcmp0 (x_content_type_options, "nosniff"))
                no_sniff = TRUE;
 
diff --git a/libsoup/cookies/soup-cookie-jar.c b/libsoup/cookies/soup-cookie-jar.c
index ad593b7d..6b6c5f4f 100644
--- a/libsoup/cookies/soup-cookie-jar.c
+++ b/libsoup/cookies/soup-cookie-jar.c
@@ -14,6 +14,7 @@
 #include "soup-cookie-jar.h"
 #include "soup-date-utils-private.h"
 #include "soup-message-private.h"
+#include "soup-message-headers-private.h"
 #include "soup-misc.h"
 #include "soup.h"
 #include "soup-session-feature-private.h"
@@ -814,11 +815,11 @@ msg_starting_cb (SoupMessage *msg, gpointer feature)
                                                                       
soup_message_get_is_top_level_navigation (msg));
        if (cookies != NULL) {
                char *cookie_header = soup_cookies_to_cookie_header (cookies);
-               soup_message_headers_replace (soup_message_get_request_headers (msg), "Cookie", 
cookie_header);
+               soup_message_headers_replace_common (soup_message_get_request_headers (msg), 
SOUP_HEADER_COOKIE, cookie_header);
                g_free (cookie_header);
                g_slist_free_full (cookies, (GDestroyNotify)soup_cookie_free);
        } else {
-               soup_message_headers_remove (soup_message_get_request_headers (msg), "Cookie");
+               soup_message_headers_remove_common (soup_message_get_request_headers (msg), 
SOUP_HEADER_COOKIE);
        }
 }
 
diff --git a/libsoup/cookies/soup-cookie.c b/libsoup/cookies/soup-cookie.c
index 2aa3fed9..021d527d 100644
--- a/libsoup/cookies/soup-cookie.c
+++ b/libsoup/cookies/soup-cookie.c
@@ -14,6 +14,7 @@
 
 #include "soup-cookie.h"
 #include "soup-date-utils-private.h"
+#include "soup-message-headers-private.h"
 #include "soup-misc.h"
 #include "soup-uri-utils-private.h"
 #include "soup.h"
@@ -931,7 +932,7 @@ soup_cookies_from_request (SoupMessage *msg)
        gpointer name, value;
        const char *header;
 
-       header = soup_message_headers_get_one (soup_message_get_request_headers (msg), "Cookie");
+       header = soup_message_headers_get_one_common (soup_message_get_request_headers (msg), 
SOUP_HEADER_COOKIE);
        if (!header)
                return NULL;
 
@@ -967,8 +968,8 @@ soup_cookies_to_response (GSList *cookies, SoupMessage *msg)
        header = g_string_new (NULL);
        while (cookies) {
                serialize_cookie (cookies->data, header, TRUE);
-               soup_message_headers_append (soup_message_get_response_headers (msg),
-                                            "Set-Cookie", header->str);
+               soup_message_headers_append_common (soup_message_get_response_headers (msg),
+                                                    SOUP_HEADER_SET_COOKIE, header->str);
                g_string_truncate (header, 0);
                cookies = cookies->next;
        }
@@ -992,14 +993,14 @@ soup_cookies_to_request (GSList *cookies, SoupMessage *msg)
 {
        GString *header;
 
-       header = g_string_new (soup_message_headers_get_one (soup_message_get_request_headers (msg),
-                                                            "Cookie"));
+       header = g_string_new (soup_message_headers_get_one_common (soup_message_get_request_headers (msg),
+                                                                    SOUP_HEADER_COOKIE));
        while (cookies) {
                serialize_cookie (cookies->data, header, FALSE);
                cookies = cookies->next;
        }
-       soup_message_headers_replace (soup_message_get_request_headers (msg),
-                                     "Cookie", header->str);
+       soup_message_headers_replace_common (soup_message_get_request_headers (msg),
+                                             SOUP_HEADER_COOKIE, header->str);
        g_string_free (header, TRUE);
 }
 
diff --git a/libsoup/http1/soup-client-message-io-http1.c b/libsoup/http1/soup-client-message-io-http1.c
index f5c24db6..ab589e43 100644
--- a/libsoup/http1/soup-client-message-io-http1.c
+++ b/libsoup/http1/soup-client-message-io-http1.c
@@ -25,6 +25,7 @@
 #include "soup-filter-input-stream.h"
 #include "soup-logger-private.h"
 #include "soup-message-private.h"
+#include "soup-message-headers-private.h"
 #include "soup-message-metrics-private.h"
 #include "soup-message-queue-item.h"
 #include "soup-misc.h"
@@ -550,8 +551,8 @@ io_read (SoupClientMessageIOHTTP1 *client_io,
                          * reading, and make sure the connection gets
                          * closed when we're done.
                          */
-                        soup_message_headers_append (soup_message_get_request_headers (msg),
-                                                     "Connection", "close");
+                        soup_message_headers_append_common (soup_message_get_request_headers (msg),
+                                                            SOUP_HEADER_CONNECTION, "close");
                         soup_message_set_metrics_timestamp (msg, SOUP_MESSAGE_METRICS_RESPONSE_END);
                         io->read_state = SOUP_MESSAGE_IO_STATE_FINISHING;
                         break;
@@ -763,10 +764,10 @@ io_run_until (SoupClientMessageIOHTTP1 *client_io,
             io->write_state == SOUP_MESSAGE_IO_STATE_DONE) {
                 GUri *uri = soup_message_get_uri (msg);
                 char *uri_str = g_uri_to_string_partial (uri, G_URI_HIDE_PASSWORD);
-                const gchar *last_modified = soup_message_headers_get_one (soup_message_get_response_headers 
(msg), "Last-Modified");
-                const gchar *etag = soup_message_headers_get_one (soup_message_get_response_headers (msg), 
"ETag");
-                const gchar *if_modified_since = soup_message_headers_get_one 
(soup_message_get_request_headers (msg), "If-Modified-Since");
-                const gchar *if_none_match = soup_message_headers_get_one (soup_message_get_request_headers 
(msg), "If-None-Match");
+                const gchar *last_modified = soup_message_headers_get_one_common 
(soup_message_get_response_headers (msg), SOUP_HEADER_LAST_MODIFIED);
+                const gchar *etag = soup_message_headers_get_one_common (soup_message_get_response_headers 
(msg), SOUP_HEADER_ETAG);
+                const gchar *if_modified_since = soup_message_headers_get_one_common 
(soup_message_get_request_headers (msg), SOUP_HEADER_IF_MODIFIED_SINCE);
+                const gchar *if_none_match = soup_message_headers_get_one_common 
(soup_message_get_request_headers (msg), SOUP_HEADER_IF_NONE_MATCH);
 
                 /* FIXME: Expand and generalise sysprof support:
                  * https://gitlab.gnome.org/GNOME/sysprof/-/issues/43 */
diff --git a/libsoup/server/soup-auth-domain-basic.c b/libsoup/server/soup-auth-domain-basic.c
index 91594f5c..3390bc63 100644
--- a/libsoup/server/soup-auth-domain-basic.c
+++ b/libsoup/server/soup-auth-domain-basic.c
@@ -12,6 +12,7 @@
 #include <string.h>
 
 #include "soup-auth-domain-basic.h"
+#include "soup-message-headers-private.h"
 #include "soup.h"
 
 /**
@@ -292,8 +293,8 @@ soup_auth_domain_basic_check_password (SoupAuthDomain    *domain,
        char *msg_username, *msg_password;
        gboolean ok;
 
-       header = soup_message_headers_get_one (soup_server_message_get_request_headers (msg),
-                                              "Authorization");
+       header = soup_message_headers_get_one_common (soup_server_message_get_request_headers (msg),
+                                                      SOUP_HEADER_AUTHORIZATION);
        if (!parse_basic (header, &msg_username, &msg_password))
                return FALSE;
 
diff --git a/libsoup/server/soup-auth-domain-digest.c b/libsoup/server/soup-auth-domain-digest.c
index f3740189..5b0bf110 100644
--- a/libsoup/server/soup-auth-domain-digest.c
+++ b/libsoup/server/soup-auth-domain-digest.c
@@ -14,6 +14,7 @@
 
 #include "soup-auth-domain-digest.h"
 #include "soup-uri-utils-private.h"
+#include "soup-message-headers-private.h"
 #include "soup.h"
 #include "auth/soup-auth-digest-private.h"
 
@@ -391,8 +392,8 @@ soup_auth_domain_digest_check_password (SoupAuthDomain    *domain,
        char hex_urp[33];
        gboolean accept;
 
-       header = soup_message_headers_get_one (soup_server_message_get_request_headers (msg),
-                                              "Authorization");
+       header = soup_message_headers_get_one_common (soup_server_message_get_request_headers (msg),
+                                                      SOUP_HEADER_AUTHORIZATION);
        if (!header || (strncmp (header, "Digest ", 7) != 0))
                return FALSE;
 
diff --git a/libsoup/server/soup-auth-domain.c b/libsoup/server/soup-auth-domain.c
index 0e1c42b9..e68884ff 100644
--- a/libsoup/server/soup-auth-domain.c
+++ b/libsoup/server/soup-auth-domain.c
@@ -12,6 +12,7 @@
 #include <string.h>
 
 #include "soup-auth-domain.h"
+#include "soup-message-headers-private.h"
 #include "soup.h"
 #include "soup-path-map.h"
 
@@ -539,10 +540,10 @@ soup_auth_domain_accepts (SoupAuthDomain    *domain,
        SoupAuthDomainPrivate *priv = soup_auth_domain_get_instance_private (domain);
        const char *header;
 
-       header = soup_message_headers_get_one (soup_server_message_get_request_headers (msg),
-                                              priv->proxy ?
-                                              "Proxy-Authorization" :
-                                              "Authorization");
+       header = soup_message_headers_get_one_common (soup_server_message_get_request_headers (msg),
+                                                      priv->proxy ?
+                                                      SOUP_HEADER_PROXY_AUTHORIZATION :
+                                                      SOUP_HEADER_AUTHORIZATION);
        if (!header)
                return NULL;
        return SOUP_AUTH_DOMAIN_GET_CLASS (domain)->accepts (domain, msg, header);
@@ -572,10 +573,10 @@ soup_auth_domain_challenge (SoupAuthDomain    *domain,
                                        SOUP_STATUS_PROXY_UNAUTHORIZED :
                                        SOUP_STATUS_UNAUTHORIZED,
                                        NULL);
-       soup_message_headers_append (soup_server_message_get_response_headers (msg),
-                                    priv->proxy ?
-                                    "Proxy-Authenticate" :
-                                    "WWW-Authenticate",
-                                    challenge);
+       soup_message_headers_append_common (soup_server_message_get_response_headers (msg),
+                                            priv->proxy ?
+                                            SOUP_HEADER_PROXY_AUTHENTICATE :
+                                            SOUP_HEADER_WWW_AUTHENTICATE,
+                                            challenge);
        g_free (challenge);
 }
diff --git a/libsoup/server/soup-server-io.c b/libsoup/server/soup-server-io.c
index cc1cfc3b..68214c2d 100644
--- a/libsoup/server/soup-server-io.c
+++ b/libsoup/server/soup-server-io.c
@@ -16,6 +16,7 @@
 #include "soup-body-output-stream.h"
 #include "soup-filter-input-stream.h"
 #include "soup-server-message-private.h"
+#include "soup-message-headers-private.h"
 #include "soup-misc.h"
 #include "soup-socket.h"
 
@@ -244,14 +245,13 @@ handle_partial_get (SoupServerMessage *msg)
                  */
 
                 multipart = soup_multipart_new ("multipart/byteranges");
-                content_type = soup_message_headers_get_one (response_headers,
-                                                             "Content-Type");
+                content_type = soup_message_headers_get_one_common (response_headers, 
SOUP_HEADER_CONTENT_TYPE);
                 for (i = 0; i < nranges; i++) {
                         part_headers = soup_message_headers_new (SOUP_MESSAGE_HEADERS_MULTIPART);
                         if (content_type) {
-                                soup_message_headers_append (part_headers,
-                                                             "Content-Type",
-                                                             content_type);
+                                soup_message_headers_append_common (part_headers,
+                                                                    SOUP_HEADER_CONTENT_TYPE,
+                                                                    content_type);
                         }
                         soup_message_headers_set_content_range (part_headers,
                                                                 ranges[i].start,
@@ -584,14 +584,14 @@ parse_headers (SoupServerMessage *msg,
         /* Handle request body encoding */
         *encoding = soup_message_headers_get_encoding (request_headers);
         if (*encoding == SOUP_ENCODING_UNRECOGNIZED) {
-                if (soup_message_headers_get_list (request_headers, "Transfer-Encoding"))
+                if (soup_message_headers_get_list_common (request_headers, SOUP_HEADER_TRANSFER_ENCODING))
                         return SOUP_STATUS_NOT_IMPLEMENTED;
                 else
                         return SOUP_STATUS_BAD_REQUEST;
         }
 
         /* Generate correct context for request */
-        req_host = soup_message_headers_get_one (request_headers, "Host");
+        req_host = soup_message_headers_get_one_common (request_headers, SOUP_HEADER_HOST);
         if (req_host && strchr (req_host, '/')) {
                 g_free (req_path);
                 return SOUP_STATUS_BAD_REQUEST;
@@ -691,7 +691,7 @@ io_read (SoupServerMessage *msg,
                          * closed when we're done.
                          */
                         soup_server_message_set_status (msg, status, NULL);
-                        soup_message_headers_append (request_headers, "Connection", "close");
+                        soup_message_headers_append_common (request_headers, SOUP_HEADER_CONNECTION, 
"close");
                         io->read_state = SOUP_MESSAGE_IO_STATE_FINISHING;
                         break;
                 }
diff --git a/libsoup/server/soup-server-message.c b/libsoup/server/soup-server-message.c
index d51f5bee..91acaa53 100644
--- a/libsoup/server/soup-server-message.c
+++ b/libsoup/server/soup-server-message.c
@@ -14,6 +14,7 @@
 #include "soup.h"
 #include "soup-connection.h"
 #include "soup-server-message-private.h"
+#include "soup-message-headers-private.h"
 #include "soup-socket.h"
 #include "soup-uri-utils-private.h"
 
@@ -384,15 +385,18 @@ soup_server_message_is_keepalive (SoupServerMessage *msg)
                  * doesn't request it. So ignore c_conn.
                  */
 
-                if (!soup_message_headers_header_contains (msg->response_headers,
-                                                           "Connection", "Keep-Alive"))
+                if (!soup_message_headers_header_contains_common (msg->response_headers,
+                                                                  SOUP_HEADER_CONNECTION,
+                                                                  "Keep-Alive"))
                         return FALSE;
         } else {
                 /* Normally persistent unless either side requested otherwise */
-                if (soup_message_headers_header_contains (msg->request_headers,
-                                                          "Connection", "close") ||
-                    soup_message_headers_header_contains (msg->response_headers,
-                                                          "Connection", "close"))
+                if (soup_message_headers_header_contains_common (msg->request_headers,
+                                                                 SOUP_HEADER_CONNECTION,
+                                                                 "close") ||
+                    soup_message_headers_header_contains_common (msg->response_headers,
+                                                                 SOUP_HEADER_CONNECTION,
+                                                                 "close"))
                         return FALSE;
 
                 return TRUE;
@@ -726,13 +730,14 @@ soup_server_message_set_response (SoupServerMessage *msg,
         if (content_type) {
                 g_warn_if_fail (strchr (content_type, '/') != NULL);
 
-                soup_message_headers_replace (msg->response_headers,
-                                              "Content-Type", content_type);
+                soup_message_headers_replace_common (msg->response_headers,
+                                                     SOUP_HEADER_CONTENT_TYPE,
+                                                     content_type);
                 soup_message_body_append (msg->response_body, resp_use,
                                           resp_body, resp_length);
         } else {
-                soup_message_headers_remove (msg->response_headers,
-                                             "Content-Type");
+                soup_message_headers_remove_common (msg->response_headers,
+                                                    SOUP_HEADER_CONTENT_TYPE);
                 soup_message_body_truncate (msg->response_body);
         }
 }
@@ -767,8 +772,8 @@ soup_server_message_set_redirect (SoupServerMessage *msg,
 
        soup_server_message_set_status (msg, status_code, NULL);
        location_str = g_uri_to_string (location);
-       soup_message_headers_replace (msg->response_headers, "Location",
-                                     location_str);
+       soup_message_headers_replace_common (msg->response_headers, SOUP_HEADER_LOCATION,
+                                             location_str);
        g_free (location_str);
        g_uri_unref (location);
 }
diff --git a/libsoup/server/soup-server.c b/libsoup/server/soup-server.c
index 25ae5924..65afc2c6 100644
--- a/libsoup/server/soup-server.c
+++ b/libsoup/server/soup-server.c
@@ -15,8 +15,8 @@
 
 #include "soup-server.h"
 #include "soup-server-message-private.h"
+#include "soup-message-headers-private.h"
 #include "soup.h"
-#include "soup-server-message-private.h"
 #include "soup-misc.h"
 #include "soup-path-map.h"
 #include "soup-socket.h"
@@ -708,7 +708,7 @@ got_headers (SoupServer        *server,
 
        date = g_date_time_new_now_utc ();
        date_string = soup_date_time_to_string (date, SOUP_DATE_HTTP);
-       soup_message_headers_replace (headers, "Date", date_string);
+       soup_message_headers_replace_common (headers, SOUP_HEADER_DATE, date_string);
        g_free (date_string);
        g_date_time_unref (date);
 
@@ -804,8 +804,8 @@ complete_websocket_upgrade (SoupServer        *server,
        stream = soup_server_message_steal_connection (msg);
        conn = soup_websocket_connection_new (stream, uri,
                                              SOUP_WEBSOCKET_CONNECTION_SERVER,
-                                             soup_message_headers_get_one 
(soup_server_message_get_request_headers (msg), "Origin"),
-                                             soup_message_headers_get_one 
(soup_server_message_get_response_headers (msg), "Sec-WebSocket-Protocol"),
+                                             soup_message_headers_get_one_common 
(soup_server_message_get_request_headers (msg), SOUP_HEADER_ORIGIN),
+                                             soup_message_headers_get_one_common 
(soup_server_message_get_response_headers (msg), SOUP_HEADER_SEC_WEBSOCKET_PROTOCOL),
                                              handler->websocket_extensions);
        handler->websocket_extensions = NULL;
        g_object_unref (stream);
@@ -932,8 +932,8 @@ start_request (SoupServer        *server,
                SoupMessageHeaders *headers;
 
                headers = soup_server_message_get_response_headers (msg);
-               soup_message_headers_append (headers, "Server",
-                                            priv->server_header);
+               soup_message_headers_append_common (headers, SOUP_HEADER_SERVER,
+                                                    priv->server_header);
        }
 
        g_signal_connect_object (msg, "got-headers",
diff --git a/libsoup/soup-message-headers.c b/libsoup/soup-message-headers.c
index 37ca0798..562d83b4 100644
--- a/libsoup/soup-message-headers.c
+++ b/libsoup/soup-message-headers.c
@@ -41,7 +41,7 @@
  **/
 
 static gboolean parse_content_foo (SoupMessageHeaders *hdrs,
-                                   const char         *header_name,
+                                   SoupHeaderName      header_name,
                                    char              **foo,
                                    GHashTable        **params);
 typedef struct {
@@ -174,7 +174,7 @@ soup_message_headers_set (SoupMessageHeaders *hdrs,
                 if (value) {
                         char *content_type = NULL, *p;
 
-                        parse_content_foo (hdrs, "Content-Type", &content_type, NULL);
+                        parse_content_foo (hdrs, SOUP_HEADER_CONTENT_TYPE, &content_type, NULL);
                         g_assert (content_type != NULL);
 
                         p = strpbrk (content_type, " /");
@@ -265,7 +265,7 @@ soup_message_headers_clean_connection_headers (SoupMessageHeaders *hdrs)
        const char *connection;
        GSList *tokens, *t;
 
-       connection = soup_message_headers_get_list (hdrs, "Connection");
+       connection = soup_message_headers_get_list_common (hdrs, SOUP_HEADER_CONNECTION);
        if (!connection)
                return;
 
@@ -920,7 +920,7 @@ soup_message_headers_get_encoding (SoupMessageHeaders *hdrs)
        /* If Transfer-Encoding was set, hdrs->encoding would already
         * be set. So we don't need to check that possibility.
         */
-       header = soup_message_headers_get_one (hdrs, "Content-Length");
+       header = soup_message_headers_get_one_common (hdrs, SOUP_HEADER_CONTENT_LENGTH);
        if (header) {
                 soup_message_headers_set (hdrs, SOUP_HEADER_CONTENT_LENGTH, header);
                if (hdrs->encoding != -1)
@@ -958,17 +958,17 @@ soup_message_headers_set_encoding (SoupMessageHeaders *hdrs,
        switch (encoding) {
        case SOUP_ENCODING_NONE:
        case SOUP_ENCODING_EOF:
-               soup_message_headers_remove (hdrs, "Transfer-Encoding");
-               soup_message_headers_remove (hdrs, "Content-Length");
+               soup_message_headers_remove_common (hdrs, SOUP_HEADER_TRANSFER_ENCODING);
+               soup_message_headers_remove_common (hdrs, SOUP_HEADER_CONTENT_LENGTH);
                break;
 
        case SOUP_ENCODING_CONTENT_LENGTH:
-               soup_message_headers_remove (hdrs, "Transfer-Encoding");
+               soup_message_headers_remove_common (hdrs, SOUP_HEADER_TRANSFER_ENCODING);
                break;
 
        case SOUP_ENCODING_CHUNKED:
-               soup_message_headers_remove (hdrs, "Content-Length");
-               soup_message_headers_replace (hdrs, "Transfer-Encoding", "chunked");
+               soup_message_headers_remove_common (hdrs, SOUP_HEADER_CONTENT_LENGTH);
+               soup_message_headers_replace_common (hdrs, SOUP_HEADER_TRANSFER_ENCODING, "chunked");
                break;
 
        default:
@@ -1025,8 +1025,8 @@ soup_message_headers_set_content_length (SoupMessageHeaders *hdrs,
 
        g_snprintf (length, sizeof (length), "%" G_GUINT64_FORMAT,
                    content_length);
-       soup_message_headers_remove (hdrs, "Transfer-Encoding");
-       soup_message_headers_replace (hdrs, "Content-Length", length);
+       soup_message_headers_remove_common (hdrs, SOUP_HEADER_TRANSFER_ENCODING);
+       soup_message_headers_replace_common (hdrs, SOUP_HEADER_CONTENT_LENGTH, length);
 }
 
 /**
@@ -1076,9 +1076,9 @@ soup_message_headers_set_expectations (SoupMessageHeaders *hdrs,
        g_return_if_fail ((expectations & ~SOUP_EXPECTATION_CONTINUE) == 0);
 
        if (expectations & SOUP_EXPECTATION_CONTINUE)
-               soup_message_headers_replace (hdrs, "Expect", "100-continue");
+               soup_message_headers_replace_common (hdrs, SOUP_HEADER_EXPECT, "100-continue");
        else
-               soup_message_headers_remove (hdrs, "Expect");
+               soup_message_headers_remove_common (hdrs, SOUP_HEADER_EXPECT);
 }
 
 /**
@@ -1125,7 +1125,7 @@ soup_message_headers_get_ranges_internal (SoupMessageHeaders  *hdrs,
                                          SoupRange          **ranges,
                                          int                 *length)
 {
-       const char *range = soup_message_headers_get_one (hdrs, "Range");
+       const char *range = soup_message_headers_get_one_common (hdrs, SOUP_HEADER_RANGE);
        GSList *range_list, *r;
        GArray *array;
        char *spec, *end;
@@ -1313,7 +1313,7 @@ soup_message_headers_set_ranges (SoupMessageHeaders  *hdrs,
                }
        }
 
-       soup_message_headers_replace (hdrs, "Range", header->str);
+       soup_message_headers_replace_common (hdrs, SOUP_HEADER_RANGE, header->str);
        g_string_free (header, TRUE);
 }
 
@@ -1364,7 +1364,7 @@ soup_message_headers_get_content_range (SoupMessageHeaders  *hdrs,
                                        goffset             *end,
                                        goffset             *total_length)
 {
-       const char *header = soup_message_headers_get_one (hdrs, "Content-Range");
+       const char *header = soup_message_headers_get_one_common (hdrs, SOUP_HEADER_CONTENT_RANGE);
        goffset length;
        char *p;
 
@@ -1429,18 +1429,20 @@ soup_message_headers_set_content_range (SoupMessageHeaders  *hdrs,
                header = g_strdup_printf ("bytes %" G_GINT64_FORMAT "-%"
                                          G_GINT64_FORMAT "/*", start, end);
        }
-       soup_message_headers_replace (hdrs, "Content-Range", header);
+       soup_message_headers_replace_common (hdrs, SOUP_HEADER_CONTENT_RANGE, header);
        g_free (header);
 }
 
 static gboolean
-parse_content_foo (SoupMessageHeaders *hdrs, const char *header_name,
-                  char **foo, GHashTable **params)
+parse_content_foo (SoupMessageHeaders *hdrs,
+                   SoupHeaderName      header_name,
+                  char              **foo,
+                   GHashTable        **params)
 {
        const char *header;
        char *semi;
 
-       header = soup_message_headers_get_one (hdrs, header_name);
+       header = soup_message_headers_get_one_common (hdrs, header_name);
        if (!header)
                return FALSE;
 
@@ -1473,8 +1475,10 @@ parse_content_foo (SoupMessageHeaders *hdrs, const char *header_name,
 }
 
 static void
-set_content_foo (SoupMessageHeaders *hdrs, const char *header_name,
-                const char *foo, GHashTable *params)
+set_content_foo (SoupMessageHeaders *hdrs,
+                 SoupHeaderName      header_name,
+                const char         *foo,
+                 GHashTable         *params)
 {
        GString *str;
        GHashTableIter iter;
@@ -1489,7 +1493,7 @@ set_content_foo (SoupMessageHeaders *hdrs, const char *header_name,
                }
        }
 
-       soup_message_headers_replace (hdrs, header_name, str->str);
+       soup_message_headers_replace_common (hdrs, header_name, str->str);
        g_string_free (str, TRUE);
 }
 
@@ -1518,7 +1522,7 @@ soup_message_headers_get_content_type (SoupMessageHeaders  *hdrs,
                return NULL;
 
        if (params)
-               parse_content_foo (hdrs, "Content-Type", NULL, params);
+               parse_content_foo (hdrs, SOUP_HEADER_CONTENT_TYPE, NULL, params);
        return hdrs->content_type;
 }
 
@@ -1538,7 +1542,7 @@ soup_message_headers_set_content_type (SoupMessageHeaders  *hdrs,
                                       const char          *content_type,
                                       GHashTable          *params)
 {
-       set_content_foo (hdrs, "Content-Type", content_type, params);
+       set_content_foo (hdrs, SOUP_HEADER_CONTENT_TYPE, content_type, params);
 }
 
 /**
@@ -1578,7 +1582,7 @@ soup_message_headers_get_content_disposition (SoupMessageHeaders  *hdrs,
 {
        gpointer orig_key, orig_value;
 
-       if (!parse_content_foo (hdrs, "Content-Disposition",
+       if (!parse_content_foo (hdrs, SOUP_HEADER_CONTENT_DISPOSITION,
                                disposition, params))
                return FALSE;
 
@@ -1614,6 +1618,6 @@ soup_message_headers_set_content_disposition (SoupMessageHeaders  *hdrs,
                                              const char          *disposition,
                                              GHashTable          *params)
 {
-       set_content_foo (hdrs, "Content-Disposition", disposition, params);
+       set_content_foo (hdrs, SOUP_HEADER_CONTENT_DISPOSITION, disposition, params);
 }
 
diff --git a/libsoup/soup-message.c b/libsoup/soup-message.c
index d95d1110..33e93bd6 100644
--- a/libsoup/soup-message.c
+++ b/libsoup/soup-message.c
@@ -15,6 +15,7 @@
 #include "soup.h"
 #include "soup-connection.h"
 #include "soup-message-private.h"
+#include "soup-message-headers-private.h"
 #include "soup-message-metrics-private.h"
 #include "soup-uri-utils-private.h"
 #include "content-sniffer/soup-content-sniffer-stream.h"
@@ -1061,7 +1062,7 @@ soup_message_set_request_body (SoupMessage  *msg,
                         g_warn_if_fail (strchr (content_type, '/') != NULL);
 
                         if (soup_message_headers_get_content_type (priv->request_headers, NULL) != 
content_type)
-                                soup_message_headers_replace (priv->request_headers, "Content-Type", 
content_type);
+                                soup_message_headers_replace_common (priv->request_headers, 
SOUP_HEADER_CONTENT_TYPE, content_type);
                 }
 
                 if (content_length == -1)
@@ -1071,8 +1072,8 @@ soup_message_set_request_body (SoupMessage  *msg,
 
                 priv->request_body_stream = g_object_ref (stream);
         } else {
-                soup_message_headers_remove (priv->request_headers, "Content-Type");
-                soup_message_headers_remove (priv->request_headers, "Content-Length");
+                soup_message_headers_remove_common (priv->request_headers, SOUP_HEADER_CONTENT_TYPE);
+                soup_message_headers_remove_common (priv->request_headers, SOUP_HEADER_CONTENT_LENGTH);
         }
 }
 
@@ -1816,15 +1817,18 @@ soup_message_is_keepalive (SoupMessage *msg)
                 * doesn't request it. So ignore c_conn.
                 */
 
-               if (!soup_message_headers_header_contains (priv->response_headers,
-                                                          "Connection", "Keep-Alive"))
+               if (!soup_message_headers_header_contains_common (priv->response_headers,
+                                                                  SOUP_HEADER_CONNECTION,
+                                                                  "Keep-Alive"))
                        return FALSE;
        } else {
                /* Normally persistent unless either side requested otherwise */
-               if (soup_message_headers_header_contains (priv->request_headers,
-                                                         "Connection", "close") ||
-                   soup_message_headers_header_contains (priv->response_headers,
-                                                         "Connection", "close"))
+               if (soup_message_headers_header_contains_common (priv->request_headers,
+                                                                 SOUP_HEADER_CONNECTION,
+                                                                 "close") ||
+                   soup_message_headers_header_contains_common (priv->response_headers,
+                                                                 SOUP_HEADER_CONNECTION,
+                                                                 "close"))
                        return FALSE;
 
                return TRUE;
@@ -2869,12 +2873,12 @@ soup_message_set_request_host_from_uri (SoupMessage *msg,
 
         host = soup_uri_get_host_for_headers (uri);
         if (soup_uri_uses_default_port (uri))
-                soup_message_headers_replace (priv->request_headers, "Host", host);
+                soup_message_headers_replace_common (priv->request_headers, SOUP_HEADER_HOST, host);
         else {
                 char *value;
 
                 value = g_strdup_printf ("%s:%d", host, g_uri_get_port (uri));
-                soup_message_headers_replace (priv->request_headers, "Host", value);
+                soup_message_headers_replace_common (priv->request_headers, SOUP_HEADER_HOST, value);
                 g_free (value);
         }
         g_free (host);
@@ -2888,7 +2892,7 @@ soup_message_update_request_host_if_needed (SoupMessage *msg)
         if (priv->http_version == SOUP_HTTP_2_0)
                 return;
 
-        if (soup_message_headers_get_one (priv->request_headers, "Host"))
+        if (soup_message_headers_get_one_common (priv->request_headers, SOUP_HEADER_HOST))
                 return;
 
         soup_message_set_request_host_from_uri (msg, priv->uri);
@@ -2907,10 +2911,10 @@ soup_message_force_keep_alive_if_needed (SoupMessage *msg)
          * a short period of time, as we wouldn't need to establish
          * new connections. Keep alive is implicit for HTTP 1.1.
          */
-        if (!soup_message_headers_header_contains (priv->request_headers, "Connection", "Keep-Alive") &&
-            !soup_message_headers_header_contains (priv->request_headers, "Connection", "close") &&
-            !soup_message_headers_header_contains (priv->request_headers, "Connection", "Upgrade")) {
-                soup_message_headers_append (priv->request_headers, "Connection", "Keep-Alive");
+        if (!soup_message_headers_header_contains_common (priv->request_headers, SOUP_HEADER_CONNECTION, 
"Keep-Alive") &&
+            !soup_message_headers_header_contains_common (priv->request_headers, SOUP_HEADER_CONNECTION, 
"close") &&
+            !soup_message_headers_header_contains_common (priv->request_headers, SOUP_HEADER_CONNECTION, 
"Upgrade")) {
+                soup_message_headers_append_common (priv->request_headers, SOUP_HEADER_CONNECTION, 
"Keep-Alive");
         }
 }
 
diff --git a/libsoup/soup-multipart.c b/libsoup/soup-multipart.c
index d2ea1b5b..0bc13fa0 100644
--- a/libsoup/soup-multipart.c
+++ b/libsoup/soup-multipart.c
@@ -13,6 +13,7 @@
 
 #include "soup-multipart.h"
 #include "soup-headers.h"
+#include "soup-message-headers-private.h"
 #include "soup.h"
 
 /**
@@ -363,13 +364,13 @@ soup_multipart_append_form_file (SoupMultipart *multipart,
                g_string_append (disposition, "; ");
                soup_header_g_string_append_param_quoted (disposition, "filename", filename);
        }
-       soup_message_headers_append (headers, "Content-Disposition",
-                                    disposition->str);
+       soup_message_headers_append_common (headers, SOUP_HEADER_CONTENT_DISPOSITION,
+                                            disposition->str);
        g_string_free (disposition, TRUE);
 
        if (content_type) {
-               soup_message_headers_append (headers, "Content-Type",
-                                            content_type);
+               soup_message_headers_append_common (headers, SOUP_HEADER_CONTENT_TYPE,
+                                                    content_type);
        }
 
        g_ptr_array_add (multipart->headers, headers);
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index 08aea5de..68d87fb0 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -18,6 +18,7 @@
 #include "cache/soup-cache-private.h"
 #include "soup-connection.h"
 #include "soup-message-private.h"
+#include "soup-message-headers-private.h"
 #include "soup-misc.h"
 #include "soup-message-queue-item.h"
 #include "soup-session-private.h"
@@ -1158,8 +1159,8 @@ redirection_uri (SoupSession *session,
        const char *new_loc;
        GUri *new_uri;
 
-       new_loc = soup_message_headers_get_one (soup_message_get_response_headers (msg),
-                                               "Location");
+       new_loc = soup_message_headers_get_one_common (soup_message_get_response_headers (msg),
+                                                       SOUP_HEADER_LOCATION);
        if (!new_loc || !*new_loc) {
                g_set_error_literal (error,
                                     SOUP_SESSION_ERROR,
@@ -1405,10 +1406,10 @@ soup_session_send_queue_item (SoupSession *session,
 
        request_headers = soup_message_get_request_headers (item->msg);
        if (priv->user_agent)
-               soup_message_headers_replace (request_headers, "User-Agent", priv->user_agent);
+               soup_message_headers_replace_common (request_headers, SOUP_HEADER_USER_AGENT, 
priv->user_agent);
 
-       if (priv->accept_language && !soup_message_headers_get_list (request_headers, "Accept-Language"))
-               soup_message_headers_append (request_headers, "Accept-Language", priv->accept_language);
+       if (priv->accept_language && !soup_message_headers_get_list_common (request_headers, 
SOUP_HEADER_ACCEPT_LANGUAGE))
+               soup_message_headers_append_common (request_headers, SOUP_HEADER_ACCEPT_LANGUAGE, 
priv->accept_language);
 
         soup_message_set_http_version (item->msg, soup_connection_get_negotiated_protocol 
(soup_message_get_connection (item->msg)));
 
@@ -3801,8 +3802,8 @@ websocket_connect_async_stop (SoupMessage *msg, gpointer user_data)
                client = soup_websocket_connection_new (stream,
                                                        soup_message_get_uri (item->msg),
                                                        SOUP_WEBSOCKET_CONNECTION_CLIENT,
-                                                       soup_message_headers_get_one 
(soup_message_get_request_headers (msg), "Origin"),
-                                                       soup_message_headers_get_one 
(soup_message_get_response_headers (msg), "Sec-WebSocket-Protocol"),
+                                                       soup_message_headers_get_one_common 
(soup_message_get_request_headers (msg), SOUP_HEADER_ORIGIN),
+                                                       soup_message_headers_get_one_common 
(soup_message_get_response_headers (msg), SOUP_HEADER_SEC_WEBSOCKET_PROTOCOL),
                                                        accepted_extensions);
                g_object_unref (stream);
                g_task_return_pointer (task, client, g_object_unref);
diff --git a/libsoup/websocket/soup-websocket.c b/libsoup/websocket/soup-websocket.c
index 6fba1908..bdcbd7c7 100644
--- a/libsoup/websocket/soup-websocket.c
+++ b/libsoup/websocket/soup-websocket.c
@@ -27,6 +27,7 @@
 #include "soup-websocket.h"
 #include "soup-headers.h"
 #include "soup-message-private.h"
+#include "soup-message-headers-private.h"
 #include "soup-server-message.h"
 #include "soup-websocket-extension.h"
 
@@ -210,8 +211,8 @@ choose_subprotocol (SoupServerMessage *msg,
                return TRUE;
 
        client_protocols_str =
-               soup_message_headers_get_one (soup_server_message_get_request_headers (msg),
-                                             "Sec-Websocket-Protocol");
+               soup_message_headers_get_one_common (soup_server_message_get_request_headers (msg),
+                                                     SOUP_HEADER_SEC_WEBSOCKET_PROTOCOL);
        if (!client_protocols_str)
                return TRUE;
 
@@ -265,28 +266,28 @@ soup_websocket_client_prepare_handshake (SoupMessage *msg,
 
        g_return_if_fail (SOUP_IS_MESSAGE (msg));
 
-       soup_message_headers_replace (soup_message_get_request_headers (msg), "Upgrade", "websocket");
-       soup_message_headers_append (soup_message_get_request_headers (msg), "Connection", "Upgrade");
+       soup_message_headers_replace_common (soup_message_get_request_headers (msg), SOUP_HEADER_UPGRADE, 
"websocket");
+       soup_message_headers_append_common (soup_message_get_request_headers (msg), SOUP_HEADER_CONNECTION, 
"Upgrade");
 
        raw[0] = g_random_int ();
        raw[1] = g_random_int ();
        raw[2] = g_random_int ();
        raw[3] = g_random_int ();
        key = g_base64_encode ((const guchar *)raw, sizeof (raw));
-       soup_message_headers_replace (soup_message_get_request_headers (msg), "Sec-WebSocket-Key", key);
+       soup_message_headers_replace_common (soup_message_get_request_headers (msg), 
SOUP_HEADER_SEC_WEBSOCKET_KEY, key);
        g_free (key);
 
-       soup_message_headers_replace (soup_message_get_request_headers (msg), "Sec-WebSocket-Version", "13");
+       soup_message_headers_replace_common (soup_message_get_request_headers (msg), 
SOUP_HEADER_SEC_WEBSOCKET_VERSION, "13");
 
        if (origin)
-               soup_message_headers_replace (soup_message_get_request_headers (msg), "Origin", origin);
+               soup_message_headers_replace_common (soup_message_get_request_headers (msg), 
SOUP_HEADER_ORIGIN, origin);
 
        if (protocols) {
                char *protocols_str;
 
                protocols_str = g_strjoinv (", ", protocols);
-               soup_message_headers_replace (soup_message_get_request_headers (msg),
-                                             "Sec-WebSocket-Protocol", protocols_str);
+               soup_message_headers_replace_common (soup_message_get_request_headers (msg),
+                                                     SOUP_HEADER_SEC_WEBSOCKET_PROTOCOL, protocols_str);
                g_free (protocols_str);
        }
 
@@ -321,12 +322,12 @@ soup_websocket_client_prepare_handshake (SoupMessage *msg,
                }
 
                if (extensions->len > 0) {
-                       soup_message_headers_replace (soup_message_get_request_headers (msg),
-                                                     "Sec-WebSocket-Extensions",
-                                                     extensions->str);
+                       soup_message_headers_replace_common (soup_message_get_request_headers (msg),
+                                                             SOUP_HEADER_SEC_WEBSOCKET_EXTENSIONS,
+                                                             extensions->str);
                } else {
-                       soup_message_headers_remove (soup_message_get_request_headers (msg),
-                                                    "Sec-WebSocket-Extensions");
+                       soup_message_headers_remove_common (soup_message_get_request_headers (msg),
+                                                            SOUP_HEADER_SEC_WEBSOCKET_EXTENSIONS);
                }
                g_string_free (extensions, TRUE);
        }
@@ -346,7 +347,7 @@ extract_extension_names_from_request (SoupMessage *msg)
         GSList *extension_list, *l;
         GHashTable *return_value = NULL;
 
-        extensions = soup_message_headers_get_list (soup_message_get_request_headers (msg), 
"Sec-WebSocket-Extensions");
+        extensions = soup_message_headers_get_list_common (soup_message_get_request_headers (msg), 
SOUP_HEADER_SEC_WEBSOCKET_EXTENSIONS);
         if (!extensions || !*extensions)
                 return NULL;
 
@@ -578,8 +579,8 @@ soup_websocket_server_check_handshake (SoupServerMessage *msg,
        }
 
        request_headers = soup_server_message_get_request_headers (msg);
-       if (!soup_message_headers_header_equals (request_headers, "Upgrade", "websocket") ||
-           !soup_message_headers_header_contains (request_headers, "Connection", "upgrade")) {
+       if (!soup_message_headers_header_equals_common (request_headers, SOUP_HEADER_UPGRADE, "websocket") ||
+           !soup_message_headers_header_contains_common (request_headers, SOUP_HEADER_CONNECTION, 
"upgrade")) {
                g_set_error_literal (error,
                                     SOUP_WEBSOCKET_ERROR,
                                     SOUP_WEBSOCKET_ERROR_NOT_WEBSOCKET,
@@ -587,7 +588,7 @@ soup_websocket_server_check_handshake (SoupServerMessage *msg,
                return FALSE;
        }
 
-       if (!soup_message_headers_header_equals (request_headers, "Sec-WebSocket-Version", "13")) {
+       if (!soup_message_headers_header_equals_common (request_headers, SOUP_HEADER_SEC_WEBSOCKET_VERSION, 
"13")) {
                g_set_error_literal (error,
                                     SOUP_WEBSOCKET_ERROR,
                                     SOUP_WEBSOCKET_ERROR_BAD_HANDSHAKE,
@@ -595,7 +596,7 @@ soup_websocket_server_check_handshake (SoupServerMessage *msg,
                return FALSE;
        }
 
-       key = soup_message_headers_get_one (request_headers, "Sec-WebSocket-Key");
+       key = soup_message_headers_get_one_common (request_headers, SOUP_HEADER_SEC_WEBSOCKET_KEY);
        if (key == NULL || !validate_key (key)) {
                g_set_error_literal (error,
                                     SOUP_WEBSOCKET_ERROR,
@@ -605,7 +606,7 @@ soup_websocket_server_check_handshake (SoupServerMessage *msg,
        }
 
        if (expected_origin) {
-               origin = soup_message_headers_get_one (request_headers, "Origin");
+               origin = soup_message_headers_get_one_common (request_headers, SOUP_HEADER_ORIGIN);
                if (!origin || g_ascii_strcasecmp (origin, expected_origin) != 0) {
                        g_set_error (error,
                                     SOUP_WEBSOCKET_ERROR,
@@ -623,7 +624,7 @@ soup_websocket_server_check_handshake (SoupServerMessage *msg,
                return FALSE;
        }
 
-       extensions = soup_message_headers_get_list (request_headers, "Sec-WebSocket-Extensions");
+       extensions = soup_message_headers_get_list_common (request_headers, 
SOUP_HEADER_SEC_WEBSOCKET_EXTENSIONS);
        if (extensions && *extensions) {
                if (!process_extensions (extensions, NULL, supported_extensions, NULL, error))
                        return FALSE;
@@ -639,8 +640,8 @@ static void
 respond_handshake_forbidden (SoupServerMessage *msg)
 {
        soup_server_message_set_status (msg, SOUP_STATUS_FORBIDDEN, NULL);
-       soup_message_headers_append (soup_server_message_get_response_headers (msg),
-                                    "Connection", "close");
+       soup_message_headers_append_common (soup_server_message_get_response_headers (msg),
+                                            SOUP_HEADER_CONNECTION, "close");
        soup_server_message_set_response (msg, "text/html", SOUP_MEMORY_COPY,
                                          RESPONSE_FORBIDDEN, strlen (RESPONSE_FORBIDDEN));
 }
@@ -656,8 +657,8 @@ respond_handshake_bad (SoupServerMessage *msg,
 
        text = g_strdup_printf (RESPONSE_BAD, why);
        soup_server_message_set_status (msg, SOUP_STATUS_BAD_REQUEST, NULL);
-       soup_message_headers_append (soup_server_message_get_response_headers (msg),
-                                    "Connection", "close");
+       soup_message_headers_append_common (soup_server_message_get_response_headers (msg),
+                                            SOUP_HEADER_CONNECTION, "close");
        soup_server_message_set_response (msg, "text/html", SOUP_MEMORY_TAKE,
                                          text, strlen (text));
 }
@@ -723,20 +724,20 @@ soup_websocket_server_process_handshake (SoupServerMessage *msg,
 
        soup_server_message_set_status (msg, SOUP_STATUS_SWITCHING_PROTOCOLS, NULL);
        response_headers = soup_server_message_get_response_headers (msg);
-       soup_message_headers_replace (response_headers, "Upgrade", "websocket");
-       soup_message_headers_append (response_headers, "Connection", "Upgrade");
+       soup_message_headers_replace_common (response_headers, SOUP_HEADER_UPGRADE, "websocket");
+       soup_message_headers_append_common (response_headers, SOUP_HEADER_CONNECTION, "Upgrade");
 
        request_headers = soup_server_message_get_request_headers (msg);
-       key = soup_message_headers_get_one (request_headers, "Sec-WebSocket-Key");
+       key = soup_message_headers_get_one_common (request_headers, SOUP_HEADER_SEC_WEBSOCKET_KEY);
        accept_key = compute_accept_key (key);
-       soup_message_headers_append (response_headers, "Sec-WebSocket-Accept", accept_key);
+       soup_message_headers_append_common (response_headers, SOUP_HEADER_SEC_WEBSOCKET_ACCEPT, accept_key);
        g_free (accept_key);
 
        choose_subprotocol (msg, (const char **) protocols, &chosen_protocol);
        if (chosen_protocol)
-               soup_message_headers_append (response_headers, "Sec-WebSocket-Protocol", chosen_protocol);
+               soup_message_headers_append_common (response_headers, SOUP_HEADER_SEC_WEBSOCKET_PROTOCOL, 
chosen_protocol);
 
-       extensions = soup_message_headers_get_list (request_headers, "Sec-WebSocket-Extensions");
+       extensions = soup_message_headers_get_list_common (request_headers, 
SOUP_HEADER_SEC_WEBSOCKET_EXTENSIONS);
        if (extensions && *extensions) {
                GList *websocket_extensions = NULL;
                GList *l;
@@ -763,12 +764,12 @@ soup_websocket_server_process_handshake (SoupServerMessage *msg,
                        }
 
                        if (response_extensions->len > 0) {
-                               soup_message_headers_replace (response_headers,
-                                                             "Sec-WebSocket-Extensions",
-                                                             response_extensions->str);
+                               soup_message_headers_replace_common (response_headers,
+                                                                     SOUP_HEADER_SEC_WEBSOCKET_EXTENSIONS,
+                                                                     response_extensions->str);
                        } else {
-                               soup_message_headers_remove (response_headers,
-                                                            "Sec-WebSocket-Extensions");
+                               soup_message_headers_remove_common (response_headers,
+                                                                    SOUP_HEADER_SEC_WEBSOCKET_EXTENSIONS);
                        }
                        g_string_free (response_extensions, TRUE);
 
@@ -837,8 +838,8 @@ soup_websocket_client_verify_handshake (SoupMessage *msg,
                return FALSE;
        }
 
-       if (!soup_message_headers_header_equals (soup_message_get_response_headers (msg), "Upgrade", 
"websocket") ||
-           !soup_message_headers_header_contains (soup_message_get_response_headers (msg), "Connection", 
"upgrade")) {
+       if (!soup_message_headers_header_equals_common (soup_message_get_response_headers (msg), 
SOUP_HEADER_UPGRADE, "websocket") ||
+           !soup_message_headers_header_contains_common (soup_message_get_response_headers (msg), 
SOUP_HEADER_CONNECTION, "upgrade")) {
                g_set_error_literal (error,
                                     SOUP_WEBSOCKET_ERROR,
                                     SOUP_WEBSOCKET_ERROR_NOT_WEBSOCKET,
@@ -846,9 +847,9 @@ soup_websocket_client_verify_handshake (SoupMessage *msg,
                return FALSE;
        }
 
-       protocol = soup_message_headers_get_one (soup_message_get_response_headers (msg), 
"Sec-WebSocket-Protocol");
+       protocol = soup_message_headers_get_one_common (soup_message_get_response_headers (msg), 
SOUP_HEADER_SEC_WEBSOCKET_PROTOCOL);
        if (protocol) {
-               request_protocols = soup_message_headers_get_one (soup_message_get_request_headers (msg), 
"Sec-WebSocket-Protocol");
+               request_protocols = soup_message_headers_get_one_common (soup_message_get_request_headers 
(msg), SOUP_HEADER_SEC_WEBSOCKET_PROTOCOL);
                if (!request_protocols ||
                    !soup_header_contains (request_protocols, protocol)) {
                        g_set_error_literal (error,
@@ -859,14 +860,14 @@ soup_websocket_client_verify_handshake (SoupMessage *msg,
                }
        }
 
-       extensions = soup_message_headers_get_list (soup_message_get_response_headers (msg), 
"Sec-WebSocket-Extensions");
+       extensions = soup_message_headers_get_list_common (soup_message_get_response_headers (msg), 
SOUP_HEADER_SEC_WEBSOCKET_EXTENSIONS);
        if (extensions && *extensions) {
                if (!process_extensions (extensions, msg, supported_extensions, accepted_extensions, error))
                        return FALSE;
        }
 
-       accept_key = soup_message_headers_get_one (soup_message_get_response_headers (msg), 
"Sec-WebSocket-Accept");
-       expected_accept_key = compute_accept_key (soup_message_headers_get_one 
(soup_message_get_request_headers (msg), "Sec-WebSocket-Key"));
+       accept_key = soup_message_headers_get_one_common (soup_message_get_response_headers (msg), 
SOUP_HEADER_SEC_WEBSOCKET_ACCEPT);
+       expected_accept_key = compute_accept_key (soup_message_headers_get_one_common 
(soup_message_get_request_headers (msg), SOUP_HEADER_SEC_WEBSOCKET_KEY));
        key_ok = (accept_key && expected_accept_key &&
                  !g_ascii_strcasecmp (accept_key, expected_accept_key));
        g_free (expected_accept_key);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]