cancel
Showing results for 
Search instead for 
Did you mean: 

Modify HTTP::collect header

Ube_34341
Nimbostratus
Nimbostratus

Hi everybody,

 

I'm trying to duplicate an HTTP post to different destinations modifying headers before sending it. This is what I've been doing:

 

when HTTP_REQUEST {

 

HTTP::collect [HTTP::header Content-Length]

 

HTTP::header replace Host "newhost"

 

}

 

when HTTP_REQUEST_DATA {

 

set request_cmd "HTTP::request"

 

log local0. "[IP::client_addr]:[TCP::client_port]: Collected [HTTP::payload length] bytes, "

 

HSL::send $hsl "[eval $request_cmd][HTTP::payload]"

 

}

 

The HSL is correctly working, but headers are kept unchanged. WHat am I doing wrong???

 

Thanks for help in advance!

 

5 REPLIES 5

What_Lies_Bene1
Cirrostratus
Cirrostratus
How are you checking the headers?

 

 

It's possible there are multiple Host headers for some reason. You could try using HTTP::header remove Host first to remove all instances. Replace will still create a new header.

nitass
F5 Employee
F5 Employee
doesn't it already work? what http header do you refer? it is http host header, isn't it?

 

 

[root@ve10:Active] config b virtual bar list virtual bar { snat automap pool foo destination 172.28.19.79:80 ip protocol 6 rules myrule profiles { http {} tcp {} } } [root@ve10:Active] config b pool foo list pool foo { members 200.200.200.101:80 {} } [root@ve10:Active] config b pool http_pool list pool http_pool { members 172.28.19.251:80 {} } [root@ve10:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { HTTP::collect [HTTP::header Content-Length] HTTP::header replace Host "newhost" } when HTTP_REQUEST_DATA { set hsl [HSL::open -proto TCP -pool http_pool] set request_cmd "HTTP::request" log local0. "[IP::client_addr]:[TCP::client_port]: Collected [HTTP::payload length] bytes" HSL::send $hsl "[eval $request_cmd][HTTP::payload]" } } [root@ve10:Active] config ssldump -Aed -nni 0.0 port 80 New TCP connection 1: 172.28.20.11(40283) <-> 172.28.19.79(80) 1354200884.1507 (0.0031) C>S --------------------------------------------------------------- POST /something HTTP/1.1 User-Agent: curl/7.19.7 (i686-redhat-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8x zlib/1.2.3 libidn/0.6.5 Accept: */* Host: test.com Content-Length: 14 Content-Type: application/x-www-form-urlencoded postdata123456--------------------------------------------------------------- New TCP connection 2: 200.200.200.10(40283) <-> 200.200.200.101(80) 1354200884.1526 (0.0016) C>S --------------------------------------------------------------- POST /something HTTP/1.1 User-Agent: curl/7.19.7 (i686-redhat-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8x zlib/1.2.3 libidn/0.6.5 Accept: */* Host: newhost Content-Length: 14 Content-Type: application/x-www-form-urlencoded postdata123456--------------------------------------------------------------- New TCP connection 3: 172.28.19.80(58616) <-> 172.28.19.251(80) 1354200884.1536 (0.0010) C>S --------------------------------------------------------------- POST /something HTTP/1.1 User-Agent: curl/7.19.7 (i686-redhat-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8x zlib/1.2.3 libidn/0.6.5 Accept: */* Host: newhost Content-Length: 14 Content-Type: application/x-www-form-urlencoded postdata123456---------------------------------------------------------------

Ube_34341
Nimbostratus
Nimbostratus
You are right; it is working. By the way I found why my application that lies upon this irule is not: as you can see in your tcpdump, the host is newhost forboth the destinations, but it should be different.

 

 

Here is the comple irule, with the different 2 Host Headers and 2 different Pools

 

 

when CLIENT_ACCEPTED {

 

set hsl [HSL::open -proto TCP -pool PoolB]

 

log local0. "[IP::client_addr]:[TCP::client_port]: New hsl: $hsl"

 

}

 

 

when HTTP_REQUEST {

 

HTTP::header replace host "HOSTA"

 

pool PoolA

 

 

set LogString "Client [IP::client_addr]:[TCP::client_port] -> [HTTP::host][HTTP::uri]"

 

log local0. "============================================= "

 

log local0. "$LogString (request)"

 

foreach aHeader [HTTP::header names] {

 

log local0. "$aHeader: [HTTP::header value $aHeader]"

 

}

 

log local0. "============================================="

 

 

HTTP::collect [HTTP::header Content-Length]

 

}

 

 

when HTTP_REQUEST_DATA {

 

set request_cmd "HTTP::request"

 

HTTP::header replace Host "HOSTB"

 

log local0. "[IP::client_addr]:[TCP::client_port]: Collected [HTTP::payload length] bytes, "

 

HSL::send $hsl "[eval $request_cmd][HTTP::payload]"

 

}

 

What_Lies_Bene1
Cirrostratus
Cirrostratus
OK, need help rewriting the rule?

nitass
F5 Employee
F5 Employee
e.g.

 

 

[root@ve10:Active] config b virtual bar list virtual bar { snat automap destination 172.28.19.79:80 ip protocol 6 rules myrule profiles { http {} tcp {} } } [root@ve10:Active] config b rule myrule list rule myrule { when CLIENT_ACCEPTED { set hsl [HSL::open -proto TCP -pool PoolB] } when HTTP_REQUEST { set request_header [HTTP::request] set host_header [HTTP::host] HTTP::header replace host "HOSTA" pool PoolA HTTP::collect [HTTP::header Content-Length] } when HTTP_REQUEST_DATA { HSL::send $hsl "[string map [list "Host: $host_header" "Host: HOSTB"] $request_header][HTTP::payload]" } } [root@ve10:Active] config b pool PoolA list pool PoolA { members 200.200.200.101:80 {} } [root@ve10:Active] config b pool PoolB list pool PoolB { members 172.28.19.251:80 {} } [root@ve10:Active] config ssldump -Aed -nni 0.0 port 80 New TCP connection 1: 172.28.20.11(44068) <-> 172.28.19.79(80) 1354257648.3008 (0.0030) C>S --------------------------------------------------------------- POST /something HTTP/1.1 User-Agent: curl/7.19.7 (i686-redhat-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8x zlib/1.2.3 libidn/0.6.5 Accept: */* Host: test.com Content-Length: 14 Content-Type: application/x-www-form-urlencoded postdata123456--------------------------------------------------------------- New TCP connection 2: 172.28.19.80(58639) <-> 172.28.19.251(80) 1354257648.3016 (0.0007) C>S --------------------------------------------------------------- POST /something HTTP/1.1 User-Agent: curl/7.19.7 (i686-redhat-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8x zlib/1.2.3 libidn/0.6.5 Accept: */* Host: HOSTB Content-Length: 14 Content-Type: application/x-www-form-urlencoded postdata123456--------------------------------------------------------------- New TCP connection 3: 200.200.200.10(44068) <-> 200.200.200.101(80) 1354257648.3017 (0.0007) C>S --------------------------------------------------------------- POST /something HTTP/1.1 User-Agent: curl/7.19.7 (i686-redhat-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8x zlib/1.2.3 libidn/0.6.5 Accept: */* Host: HOSTA Content-Length: 14 Content-Type: application/x-www-form-urlencoded postdata123456---------------------------------------------------------------