by RedTrousers » Tue Jan 23, 2007 12:26 am
I've PM'd this to some others in the past, but since we're no longer using this (recent Finjan versions have preview enabled in request mode ICAP, thus solving the issue) I'll post it here for future reference.
Note that I've stripped all other code to protect the innocent. You may need to mingle this with your own local CPL if you have any.
I've also added some more comments to help clarify things
Here we go:
-----------------------------------------
; This is in the local CPL file by joost AT decock DOT org
; Conditions and actions are on top, the actual layers are at the bottom
;
; We have a Bluecoat (port 8082) that normally does ICAP to Finjan
; For big request (uploads over HTTP) we forward to Finjan over HTTP
; The Finjan's next proxy is once again the Bluecoat (port 8080)
; CONDITION: We run our proxy on port 8082
define condition CPL_Condition_ProxyPort_8082
proxy.port=8082
end
; CONDITION: Request larger then 3Mb (typically a file upload)
define condition CPL_Condition_Specific_RequestLargerThan3Mb
; Content-Length of 6 or more digits is way to big
request.header.Content-Length.length=6..
; Content-Length of 5 digits is to big if the first digit is 3-9
request.header.Content-Length.length=5 request.header.Content-Length="^[3-9]"
end
; CONDITION: Request larger then 3Mb proxied on port 8082
; This is just a combination of the two above
define condition CPL_Condition_GroupAND_LargeRequestProxyPort8082
condition=CPL_Condition_Specific_RequestLargerThan3Mb condition=CPL_Condition_ProxyPort_8082
end
; ACTION: Forward over HTTP, instead of using ICAP
define action CPL_Action_Specific_ForwardToFinjanBypassICAPStep1
; We add logging to have an idea of how frequent this happens
log_message("Big request detected. Not using ICAP, forwarding over HTTP. Rewriting headers.")
; In the forwarding layer, we have very limited context.
; Since the URL is one of the few things we have access to at that time, we are adding some stuff to trigger the forwarding
; We are adding '?BigPostWorkaround=on' at the end
rewrite(url, "(.*)", "$(1)?BigPostWorkaround=on")
; Also adding a X-BigPostAdded header
set(request.x_header.X-BigPostAdded, "yes")
; Strip the X-Bluecoat-Via header, or the Bluecoat will bark when the request returns
delete(request.x_header.X-Bluecoat-Via)
end
; Undo changes added by CPL_Action_Specific_ForwardToFinjanBypassICAPStep2
; When the request comes back after the forwarding, we re-normalize the request, undoing what we did before
define action CPL_Action_Specific_ForwardToFinjanBypassICAPStep2
; Some more informational logging
log_message("Forwarded big request received back from Finjan. Restoring headers.")
; Stripping our custom header
delete(request.x_header.X-BigPostAdded)
; Stripping the part we added to the URL
rewrite(url, "(.*)\?BigPostWorkaround=on", "$(1)")
end
<Proxy "CPL LAYER -- Bypass ICAP Request Mode">
; When the request first hits, this rule matches
; It triggers the action that adds headers and URL string
ALLOW condition=CPL_Condition_GroupAND_LargeRequestProxyPort8082 action.CPL_Action_Specific_ForwardToFinjanBypassICAPStep1(yes) client.protocol=http
; When it comes back from forwarding, this matches
; It triggers the action that undoes the modifications above
request.x_header.X-BigPostAdded.count=1 action.CPL_Action_Specific_ForwardToFinjanBypassICAPStep2(yes)
<Forward "CPL LAYER -- Forwarding">
; By the time this layer is treated, the URL has been modified
; We force the request through forwarding over HTTP instead of going over ICAP (the default in our case)
server_url.query.regex="BigPostWorkaround" proxy.port=8082 forward(finjan) forward.fail_open(no)
<Cache "CPL LAYER -- Bypass ICAP Response Mode">
; Finally, don't do response mode ICAP
server_url.query.regex="BigPostWorkaround" response.icap_service(no)
-----------------------------------------
That's it. Worked great for us, hopfully it can benefit others too.
ciao,
Joost