Caching based on Surrogate-Control header

I want to configure a virtual server to use Web Acceleration caching based on the Surrogate-Control response header instead of the Cache-Control response header.

Both headers must be preserved, so I can’t just overwrite the Cache-Control header with the Surrogate-Control header upon HTTP_RESPONSE.

Is there some built in support for this, or is there some nice solution to this?

Hello @LarsKristensson

Not sure if this is possible.
But you could save original Cache-Control response header in HTTP_RESPONSE in a variable, replace it with Surrogate-Control header so it can be used by Web Acceleration caching and then in HTTP_RESPONSE_RELEASE event restore the original value of Cache-Control from variable.

You could check something like this

when HTTP_RESPONSE {
	# Check if Surrogate-Control header exists in the response
    if { [HTTP::header exists "Surrogate-Control"] } {
		set surrogate_control [HTTP::header value "Surrogate-Control"]
		# Check if Cache-Control header exists in the response
		if { [HTTP::header exists "Cache-Control"] } {
			# Save the original Cache-Control header value in a variable
			set original_cache_control [HTTP::header value "Cache-Control"]
		}
		# Replace Cache-Control with Surrogate-Control for Web Acceleration
		HTTP::header replace "Cache-Control" $surrogate_control
	}
}

when HTTP_RESPONSE_RELEASE {
    # Check if we saved a Cache-Control value
    if { [info exists original_cache_control] } {
        # Restore the original Cache-Control header
        HTTP::header replace "Cache-Control" $original_cache_control
    }
}

Yes, after posting my question I figured out that I could replace the Cache-Control header in HTTP_RESPONSE. However, storing it in a variable is not enough since the response may be served from the cache at a later point.

I ended up with this:

when HTTP_RESPONSE {
    HTTP::header insert Saved-Cache-Control [HTTP::header Cache-Control]
    HTTP::header replace Cache-Control [HTTP::header Surrogate-Control]
}

when HTTP_RESPONSE_RELEASE {
    if { [HTTP::header exists Saved-Cache-Control] } {
        HTTP::header replace Cache-Control [HTTP::header Saved-Cache-Control]
        HTTP::header remove Saved-Cache-Control
    }
}