Forum Discussion
Using variables to create HTTP::respond string?
Hi there,
I've been working with f5 for only a short while and have run into an issue which I hope someone might be able to shed some light on ..
I'm trying to write a procedure which builds an HTTP response string and then uses HTTP::repond to deliver it but unless I write
Essentially I want to build a header string based on logic in the iRule something like:
set myStatusCode 405
set myContent "Only POSTs allowed here .."
set myHeader "time \"[clock seconds]\"
httpString = "$myStatusCode content $myContent $myHeader"
HTTP::respond $httpString
This isn't working in the slightest 🙂 - "expected integer but got "405 content "Only POSTs allowed here .."
Is there a way to do this or am I trying to use HTTP::respond for something it wasn't designed to do? If I write the command in with no variables as below it works fine..
HTTP::respond 405 "Only POSTs allowed here .." time 033576859
Many thanks!
bc
- Vijay_E
Cirrus
Try:
HTTP::respond $myStatusCode $myContent $myHeader
If the above works, try dropping the "content" from this variable:
httpString = "$myStatusCode content $myContent $myHeader"
Hi bc,
the [HTTP::respond] command requires you to pass each additional header as two parameters. So you may either pass your additional headers as two variables...
set statusCode 405 set httpcontent "Only POSTs allowed" set extraheader_name "Connection" set extraheader_value "Close" HTTP::respond $statusCode content $httpContent $extraheader_name $extraheader_value
... or you could utilize TCLs [eval] command to create and finally execute a custom TCL script during runtime.
set http_respond_param "405 content \"Only POSTs allowed\" Connection Close" eval "HTTP::respond $http_respond_param"
Note: The use of [eval] to create a (non-global) TCL script should be strongly avoided. The reason is, that [eval] needs to parse and byte-code compile the provided script. This will add additional overhead to the system. In addition you have to make sure that the usage of [eval] does not introduce TCL Code-Injection attack vectors, by wrapping every user provided infomation into curly {} braces so that those information are getting hidden either from the first or second command substitution. For further information read those wiki pages.
Information on [eval]
Information on TCL Code Injection Attacks
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