Location header rewrite, but only on HTTP 201 events
Hello, we have an LTM doing SSL offloading and balancing for a pool of JBoss servers. Because the LTM talks HTTP to the JBoss pool, some Location headers were returning as http instead of https.
Example POST with http Location header:
curl -v -X POST -u username:password https://stage.test.com/SCFileserver/text/ --data-ascii 'Text Example 1'
>
> Text Example 1HTTP/1.1 201 Created
< Server: Apache-Coyote/1.1
< X-UA-Compatible: IE=EmulateIE8
< Location: http://stage.test.com/SCFileserver/text/text655bf2cb-7c91-438b-81e0-3fe0469208a1
< Content-Length: 0
< Date: Wed, 28 Nov 2012 22:58:29 GMT
< Set-Cookie: BIGipServerStage1_Pool=2365657260.33315.0000; path=/
Normally not a problem for a web browser-- the LTM has an iRule to redirect http requests to https-- but our Java app does not handle the 302 redirect to https from the LTM correctly so we want to rewrite the Location header to be https.
It was easy to find an iRule on DevCentral that would ReWrite https into a redirect message, I used this one:
https://devcentral.f5.com/wiki/iRul...iting.ashx
I removed [HTTP::is_redirect] && from line 27 since we want to rewrite the Location before the redirect has a chance to happen.
This seems to work for us as shown in this example after the iRule is applied to the virtual server:
curl -v -X POST -u username:password https://stage.test.com/SCFileserver/text/ --data-ascii 'Text Example 2'
>
> Text Example 2HTTP/1.1 201 Created
< Server: Apache-Coyote/1.1
< X-UA-Compatible: IE=EmulateIE8
< Location: https://stage.test.com/SCFileserver/text/text77cda4f2-4e2f-46e7-9b57-48ec519d8df0
< Content-Length: 0
< Date: Wed, 28 Nov 2012 23:06:37 GMT
< Set-Cookie: BIGipServerStage1_Pool=2365657260.33315.0000; path=/
My questions-- is this the best method of changing the Location header in the response, and is there a way to apply the rewrite just to HTTP 201 Created responses?
Something like this?
if { [HTTP::status] == 201 && [string tolower [HTTP::header Location]] starts_with "http://$host"} {
HTTP::header replace Location [string map -nocase "http://$host https://$host" [HTTP::header Location]]
Thank you,
Scott