29-Nov-2012 05:28
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!
29-Nov-2012 05:37
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.
29-Nov-2012 06:01
[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---------------------------------------------------------------
29-Nov-2012 07:39
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]"
}
29-Nov-2012 07:50
29-Nov-2012 21:48
[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---------------------------------------------------------------