Fixup Cache Control Headers
Problem this snippet solves:
Coalesce all instances of a header in the response into a single comma-delimited header. This is primarily used to work around a bug in RAMCache, ID360047, where it only examines the last Cache-Control response header.
Code :
when RULE_INIT { # A list of headers; for each header, take all instances of that header and # combine them into a single (comma-delimited) header. # # e.g. # Cache-Control: private # Cache-Control: max-age=0 # is translated into: # Cache-Control: private, max-age=0 # # Headers listed here MUST be defined as a list in the HTTP RFC. # See the definition of Cache-Control and WWW-Authenticate for examples # (http://tools.ietf.org/html/rfc2616#section-14.9) #set static::headers { "Cache-Control" "WWW-Authenticate" } set static::headers { "Cache-Control" } # Enable/disable diagnostic logging. Set to 1 to enable, 0 to disable set static::debug 0 } when HTTP_RESPONSE { foreach header $static::headers { if {[HTTP::header exists $header]} { # Grab the values as a list, remove the existing headers, and # replace with the values, joined as a comma-delimited string set from_values [HTTP::header values $header] set to_values {} foreach value $from_values { set value [string trim $value] if { $value ne ""} { lappend to_values $value } } set to_values [join $to_values ", "] if { $static::debug } { log local0. "Coalescing $header from '$from_values' to '$to_values'" } HTTP::header remove $header HTTP::header insert "lws" $header $to_values } } }
Published Mar 17, 2015
Version 1.0CodeCentral_194
Cirrus
Joined May 05, 2019
CodeCentral_194
Cirrus
Joined May 05, 2019
No CommentsBe the first to comment