From 772d91a9f8bcefbe8ac75efa05f70b10434911c6 Mon Sep 17 00:00:00 2001 From: df Date: Tue, 16 Feb 2021 00:28:24 +0000 Subject: [PATCH] Use dicts for `httpheader` --- webif/lib/setup | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/webif/lib/setup b/webif/lib/setup index 82f17a0..4ae354b 100644 --- a/webif/lib/setup +++ b/webif/lib/setup @@ -33,16 +33,24 @@ if {![exists -proc require]} { exit } - proc httpheader {{type "text/html"} {cache 0} {extra ""}} {{done 0}} { + proc httpheader {{type "text/html"} {cache 0} {extra {}}} {{done 0}} { if {$done} return if {!$cache} { - puts -nonewline "Content-Type: $type; charset=\"UTF-8\"; no-cache\r\n" - puts -nonewline "Expires: -1\r\n" - puts -nonewline "Connection: close\r\n" - puts -nonewline "Pragma: no-cache\r\n" - puts -nonewline "Cache-Control: no-cache\r\n" + set hdr [dict create \ + "Content-Type" "$type; charset=\"UTF-8\"; no-cache" \ + "Expires" "-1" \ + "Connection" "close" \ + "Pragma" "no-cache" \ + "Cache-Control" "no-cache"] } else { - puts -nonewline "Content-Type: $type; charset=\"UTF-8\"\r\n" + set hdr [dict create "Content-Type" "$type; charset=\"UTF-8\""] + } + if {![catch {dict size $extra}]} { + set hdr [dict merge $hdr $extra] + set extra "" + } + dict for {k v} $hdr { + puts -nonewline "$k: $v\r\n" } if {$extra ne ""} { puts -nonewline "$extra" } puts -nonewline "\r\n"