Parcourir la source

fix(server): handle http headers case-insensitively

HTTP headers are case-insensitive per RFC 7230, so the header
catalogue now uses case-insensitive hash and equality functions
for proper lookups.
Billy Barrow il y a 1 semaine
Parent
commit
8099e8015a
1 fichiers modifiés avec 12 ajouts et 2 suppressions
  1. 12 2
      src/Server/Server.vala

+ 12 - 2
src/Server/Server.vala

@@ -33,8 +33,8 @@ namespace Astralis {
 
             // On the second call we populate the `HttpRequest` object and begin the handler
             if (context.handler_context == null) {
-                // Extract all headers from the connection
-                var headers = new Catalogue<string, string>();
+                // Extract all headers from the connection (case-insensitive keys)
+                var headers = new Catalogue<string, string>(case_insensitive_hash, case_insensitive_equal);
                 var headers_collector = new KeyValueCollector(headers);
                 MHD.get_connection_values(connection, MHD.ValueKind.HEADER_KIND, KeyValueCollector.key_value_iterator, (void*)headers_collector);
     
@@ -248,5 +248,15 @@ namespace Astralis {
             // Get the InetAddress and convert to string
             return inet_addr.address.to_string();
         }
+
+        // Case-insensitive hash function for strings (for HTTP header lookups)
+        private static uint case_insensitive_hash(string key) {
+            return key.down().hash();
+        }
+
+        // Case-insensitive equality function for strings (for HTTP header lookups)
+        private static bool case_insensitive_equal(string a, string b) {
+            return a.down() == b.down();
+        }
     }
 }