Forum Discussion
Tim_W_72292
Nimbostratus
Nov 19, 2007Adding to header and PDU content
Hi,
I am trying to add some content to a HTTP header and pdu content. I just need to add the bit in bold as shown in the example below:
POST /mms-rs/mm7 HTTP/1.1
Host: mms.omms.com
Content-Type: multipart/related; boundary="NextPart_000_0028_01C19839.84698430"; type=text/xml; start=""
Content-Length: nnnn
SOAPAction: ""
--NextPart_000_0028_01C19839.84698430
Content-Type:text/xml; charset="utf-8"
Content-ID:
Is this possible to do and if so any pointers would be great.
Thanks in advance
Tim
7 Replies
- hoolio
Cirrostratus
Hi Tim,
Inserting the header should just be a matter of using 'HTTP::header insert start {}' (Click here).
Are you wanting to insert the Content-ID in a header or the HTTP data? If it's the header, you can use the HTTP::header insert command again. If the latter, you would need to collect the payload and then use HTTP::payload replace. Deb posted a codeshare example for inserting content in the response. You could adapt this for the request.
InsertContentIntoServerResponse (Click here).
Aaron - Tim_W_72292
Nimbostratus
Hey Aaron,
The Contentid is in the HTTP data, and the start="" is in the HTTP header but needs to be at the end of the line as shown in the example, I am checking out the links now.
Thanks for the advice.
Tim - Tim_W_72292
Nimbostratus
Aaron,
maybe like this?
when HTTP_REQUEST {
Insert Missing HTTP tag.
HTTP::payload replace 0 0 "; start="""
}
when HTTP_REQUEST_DATA {
Add missing pdu content.
HTTP::payload replace 0 0 "Content-ID: "
}
I am a little unsure how to make the HTTP::replace apend to the end of the line instead of adding the content at the begining of the Header. From the wiki pages:
HTTP::payload replace
* Replaces the amount of content that you specified with the argument, starting at with , adjusting the Content-Length header appropriately.
The offset is this in characters? How do I take into account line breaks?
Tim - Tim_W_72292
Nimbostratus
Ok I think this is going to do what I want, but the "" that are needed to be written how do I specify them?
when HTTP_REQUEST {
Insert Missing HTTP tag.
set old-data [HTTP::header value "Content-Type"]
HTTP::header remove "Content-Type"
HTTP::header insert "Content-Type""$old-data""; start="""
}
when HTTP_REQUEST_DATA {
Add missing pdu content.
HTTP::payload replace 0 0 "Content-ID: "
}
Tim - hoolio
Cirrostratus
To insert the header, you can use the HTTP_REQUEST event:when HTTP_REQUEST { Insert HTTP header HTTP::header insert start {} }
To insert the string in the payload, I thought you needed to collect the HTTP data first. I'm actually a bit surprised to see in the codeshare example HTTP::payload replace being used in the HTTP_RESPONSE event (as opposed to HTTP_RESPONSE_DATA).
If you do need to collect the data in order to modify the payload, I think it would actually be more efficient to use a stream profile to 'replace' a known string in the payload with that string plus what you want to insert.
Here's what I'm thinking for the rule:when HTTP_REQUEST { Check if the request is a POST to a specific path with a content type containing "xml" if {[HTTP::path] starts_with "/mms-rs" and [HTTP::method] eq "POST" and [HTTP::header value "Content-Type" contains "xml"}{ Insert HTTP header HTTP::header insert start {} Enable the stream profile and set the find/replace strings STREAM::enable STREAM::expression {@Content-Type:text/xml; charset="utf-8"@Content-Type:text/xml; charset="utf-8"...Content-ID: @} } }
The rule requires a blank stream profile added to the virtual server.
The stream expression format is described on the wiki page (Click here).
The only catch, is that I haven't figured out how to insert a carriage return and line feed where the three periods are in the STREAM::expression. I'm not sure if you could insert a \r\n, the value in hex 0D0A, or something else altogether. I can't test this right now to see either.
Aaron - Tim_W_72292
Nimbostratus
Aaron,
I am going to give this a try and see what happens
rule mm7 {
when HTTP_REQUEST {
if {[HTTP::path] starts with "/mmsc/mm7" and [HTTP::method] eq POST}{
Insert Missing HTTP tag.
set old-data [HTTP::header value "Content-Type"]
set missing [; start=""]
HTTP::header remove "Content-Type"
HTTP::header insert "Content-Type""$old-data""$missing"
Add missing pdu content
STREAM::enable
STREAM::expression {@Content-Type:text/xml; charset="utf-8"@Content-Type:text/xml; charset="utf-8"\r\nContent-ID: @}
}
}
}
Tim - Tim_W_72292
Nimbostratus
This is what I have now, the objectives have changed slightly, but I have an issue:
when HTTP_REQUEST {
if {([HTTP::path] starts_with "/mmsc/mm7") and ([HTTP::method] eq
"POST")}{
read out boundry
set tblength [string first "Content-Type" [HTTP::payload]]
set blength [expr {$tblength - 4}]
set bdary [substr [HTTP::payload] 2 $blength]
Insert Missing HTTP tag.
set olddata [HTTP::header value "Content-Type"]
set missing "start=\"\";"
HTTP::header replace "Content-Type" "$olddata
boundary=\"$bdary\"; $missing"
Add missing pdu content
insert Content-ID
set tmp [string first "Content-Type" [HTTP::payload] ]
set bypass [expr {$tmp + 37}]
HTTP::payload replace $bypass 0 "\r\nContent-ID:
"
insert CID:
set bypass2 [string first "comverse.cid" [HTTP::payload] ]
HTTP::payload replace $bypass2 0 "cid:"
fix boundry in payload
set tbypass3 [string first ".boundary=" [HTTP::payload] ]
log local0. "$tbypass3"
set bypass3 [expr {$tbypass3 - 2}]
if {$bypass3 > 0}{
HTTP::payload replace $bypass3 3 " "
}
}
}
The fix boundry in payload section never finds the actual string .boundry, is there some limitations on how much HTTP::payload can read? if not what do you think is wrong with this?
Tim
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects