Forum Discussion
dubdub
Oct 26, 2011Nimbostratus
HTTP::payload replace length
Hi all,
I used Colin's excellent example of replacing outbound payload content at http://devcentral.f5.com/Tutorials/...Rules.aspx - but was curious, that last line where it says:
HTTP::payload replace 0 [string length $newPayload] $newPayload
Should it be:
HTTP::payload replace 0 $originalPayloadLength $newPayload
where $originalPayloadLength is calculated right before the "set newPayload" line in HTTP_RESPONSE_DATA? Won't the content length in the header be off otherwise?
Thanks,
Jen
- Michael_YatesNimbostratusIf you edit the payload and do not correct the length then you can get mismatch errors which would tell the client that the data has been tampered with. Some systems like the ASM will flag or even block this.
- dubdubNimbostratusHi Michael,
- Thomas_SchaeferNimbostratusIt is the old length. From the Wiki for HTTP:payload replace: To clarify, the length argument should be the length of original content to replace. In order to replace the entire payload, the offset should be 0 and the length should be the original size in bytes of the payload. The original content length can typically be retrieved using [HTTP::header value Content-Length].
- Thomas_SchaeferNimbostratusOne more thought...This is actually clearer in the example of scrubbing a credit card number somewhere in the middle of the string where the first number is not 0. If you find a credit card at position 1300, then it seems pretty clear that you replace starting at position 1300 for 16 (length of the credit card--except AMEX). Perhaps the confusion comes in the fact that in this case the length you want to replace is 16 which also happens to be the length of the new string as well. If I have the statement
it is not obvious which is which, but in fact, it is the size of the content you are replacing.HTTP::payload replace 1300 16 $scrubbedCard
- Michael_YatesNimbostratusGood catch Thomas. I didn't catch that comment on the Wiki.
- Colin_Walker_12Historic F5 AccountNow that I'm sitting in a room with dubdub, and have been pointed at this post (Thanks!!) I want to weigh in here. It is definitely a typo in my example, which I'll go fix once I'm back at my desk. It should be the old length. Sorry for any confusion folks, and thanks for the heads up! Any and all feedback is most welcome.
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