Hello, I follow the following reasoning, trying to avoid regex for example. Of course the code is very simple and needs validation source page, size of request, if there is content, etc. But I think this code is a start for you.
Regards.
when HTTP_REQUEST {
if { ([HTTP::method] eq "POST") } {
HTTP::collect [HTTP::header Content-Length]
}
}
when HTTP_REQUEST_DATA {
set decoded [decode_uri [HTTP::payload]]
log local0. "=== Decoded $decoded"
set ini [string first "\"idTerminal\"" $decoded]
if { $ini != -1 } {
set end [string first "," $decoded $ini]
set value [string range $decoded $ini [expr {$end-1}]]
set idTerminal [lindex [split $value ":"] 1]
switch -exact $idTerminal {
678 -
679 {
pool terminal_67x_pool
}
default {
pool default_pool
}
}
}
}
set id [findstr [URI::decode [HTTP::payload]] "\"idTerminal\":\"" 14 "\""]
This will find the first instance of “idTerminal”:" in the payload, skip 14 characters (the length of that string), and then collect everything up to but not including the very next double quote, which in this case should be the ID value.
One thing I’d want to point out here, is that for this method to be used to path management, you have to make sure that either a) a POST payload ID is in EVERY request, b) you have something in place for when it isn’t, or c) you configure so,e form of persistence.
when HTTP_REQUEST { if { ([HTTP::method] eq “POST”) } { HTTP::collect [HTTP::header Content-Length] } }
when HTTP_REQUEST_DATA { set decoded [decode_uri [HTTP::payload]] log local0. “=== Decoded $decoded”
set ini [string first "\"idBiller\"" $decoded]
if { $ini != -1 } {
set end [string first "," $decoded $ini]
set value [string range $decoded $ini [expr {$end-1}]]
set idBiller [lindex [split $value ":"] 1]
log local0. "=== ID Biller: $idBiller ==="
switch -exact $idBiller {
94950004 {
pool Pool_recarga_XXX
log local0. "=== Sali por TASA ==="
}
default {
pool Pool_recarga_YYY
log local0. "=== Sali por Default ==="
}
}
}