changeset 584:9b64f201b3a7

urllog: Use lowercase HTTP metadata keys and sanitize them.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 24 Jan 2021 21:47:27 +0200
parents d5fc3ecee4c7
children a5dc31f5b44e
files urllog.tcl
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/urllog.tcl	Sun Jan 10 14:57:30 2021 +0200
+++ b/urllog.tcl	Sun Jan 24 21:47:27 2021 +0200
@@ -229,6 +229,12 @@
   array set umeta [::http::meta $utoken]
   ::http::cleanup $utoken
 
+  # Sanitize the metadata KEYS
+  foreach {ukey uvalue} [array get umeta] {
+    set ukey [string tolower $ukey]
+    set umeta($ukey) $uvalue
+  }
+
   return 1
 }
 
@@ -349,7 +355,7 @@
 
   ### Handle redirects
   if {$ucode >= 301 && $ucode <= 303} {
-    set nurlStr $umeta(Location)
+    set nurlStr $umeta(location)
     if {![regexp "\[a-z\]+://" $nurlStr]} {
       if {[string range $nurlStr 0 0] != "/"} {
         append nurlStr "/"
@@ -370,7 +376,7 @@
 
   ### Handle 2nd level redirects
   if {$ucode >= 301 && $ucode <= 303} {
-    set nurlStr $umeta(Location)
+    set nurlStr $umeta(location)
     if {![regexp "\[a-z\]+://" $nurlStr]} {
       if {[string range $nurlStr 0 0] != "/"} {
         append nurlStr "/"
@@ -396,7 +402,7 @@
     set uencoding ""
 
     # Get information about specified character encodings
-    if {[info exists umeta(Content-Type)] && [regexp -nocase {charset\s*=\s*([a-z0-9._-]+)} $umeta(Content-Type) umatches uenc_http]} {
+    if {[info exists umeta(Content-Type)] && [regexp -nocase {charset\s*=\s*([a-z0-9._-]+)} $umeta(content-type) umatches uenc_http]} {
       # Found character set encoding information in HTTP headers
     }