Forum Discussion
irule to insert action parameter inside Content-Type header for xml request
Hi Mohanad,
the iRule below uses a
HTTP::collect
approach, to intercept and buffer the POST request destined to your web service. If the entire POST-Body (or a maximum of X bytes amount) has been buffered, the iRule will use a combination of the [getfield]
, [substr]
and [URI::basename]
commands to extract the last portion of the URL defined in the Action
XML element. If a action value could be extracted, the iRule will replace the Content-Type HTTP-Header with a new value including the extracted action value. Once the HTTP-Header has been changed, the request is released from the buffer and send to your web service...
when RULE_INIT {
Defining the maximum HTTP::collect size
set static::maximum_http_collect_size 1048576 ; Its 1 Mbyte per POST request. This should be lowered if possible
}
when HTTP_REQUEST {
if { ( [HTTP::method] eq "POST" )
and ( [HTTP::path] ends_with "/Service.svc" ) } then {
if { not [string is integer [HTTP::header value "Content-Length"]] } then {
Skipping the malformated Content-Length header...
} elseif { [HTTP::header value "Content-Length"] >= $static::maximum_post_collect_size } then {
Collecting the HTTP payload until maximum size has been reached
HTTP::collect $static::maximum_http_collect_size
} elseif { [HTTP::header value "Content-Length"] > 0 } then {
Collecting the full HTTP payload.
HTTP::collect [HTTP::header value "Content-Length"]
}
}
}
when HTTP_REQUEST_DATA {
set action_value [URI::basename [substr [getfield [HTTP::payload] "" 2] 0 "<"]]
log local0.debug "Found the action = $action_value"
if { $action_value ne "" } then {
HTTP::header remove "Content-Type"
HTTP::header insert "Content-Type" "application/soap xml; charset=utf-8; action=http://tempuri.org/IACHService/$action_value"
log local0.debug "New Header Value: [HTTP::header value "Content-Type"]"
}
}
Note: I'm sorry if I've wasted some of your valuable time with my previous
approach. Well, the STREAM_MATCH
approach is still superior in my opinion, since it does not need to buffer the entire payload into LTMs memory. But unfortunately it changes the ongoing request slightly, which may have certain side effects within your application which we don't know yet. The STREAM_MATCH
approach is not bad at all. If you tweak the maximum collect size to a minimum (e.g. just a few kbyte), the impact to buffer portions of the request could be minimized to an acceptable degree.HTTP::collect
Cheers, Kai
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com