Forum Discussion
João_Assad_4295
Nimbostratus
Nov 14, 2005redirect POSTs bigger than 1MB
Hello,
I'd like to redirect POSTs bigger than 1MB to an error page, so I tried this:
when HTTP_REQUEST {
set method [HTTP::method]
set clen [HTTP::header Content-Length]
if { $method =="POST" and $clen > 1048576 } {
log local0. "over 1MB post: $uri - ($clen) [IP::client_addr]"
HTTP::respond 301 "Location" "http://[HTTP::host/errorpage.htm"
}
}The problem with that is that it will only redirect after the whole POST is sent to the server, I'd like the iRule to interrupt the client and redirect it to the error page immediately.
So I tried adding HTTP::close or TCP::close after the HTTP::respond, but then I got "Document contains no data" errors on the client.
So, Is there a way to make this work ?
Thanks.
15 Replies
- James_Thomson
Employee
You might need to collect the data with an http::collect. I think this will stop the BIG-IP from sending the bits and pieces to the server.
from manual.
HTTP::collect [] Collects the amount of data that you specify with the [length] argument.
When
the system collects the specified amount of data, it calls the Tcl event
HTTP_REQUEST_DATA or HTTP_RESPONSE_DATA. Use great caution
when omitting the value of the content length. Even though this is allowed in
certain cases; doing so or using a value larger than the size of the actual length
can stall the connection. - drteeth_127330Historic F5 AccountAre you sure the whole POST is going to the server? HTTP::respond is supposed to sink the POST data without sending it on. What version of BIG-IP are you running?
- João_Assad_4295
Nimbostratus
I tried:HTTP::collect $clen
andHTTP::collect 1
andHTTP::collect
before the HTTP::respond but it didn't seem to make any difference to me, I still get "document contains no data" on the client.
drteeth:
Im not sure if it's going to my servers or not, but the BigIP is waiting for the client POST and thats not good for me either.
BigIP 9.1 - unRuleY_95363Historic F5 AccountYou could try adding a "reject" after the HTTP::respond. This should reset the connection after responding which should stop the client from sending more of the post data (where not quite sure what you are trying to accomplish). The BIGIP should discard the data after you respond. Is the problem that the BIGIP doesn't respond until after the entire post arrives at the BIGIP and the client browser times out before then?
- João_Assad_4295
Nimbostratus
adding a "reject" after the HTTP::respond gives the same "Document contains no data"
what Im trying to accomplish here is craft a rule that limits the image size that users can upload using a form. the rule must prevent the user from sending the data entirely, thats why I want it to interrupt the POST, I dont want to waste any bandwidth. - unRuleY_95363Historic F5 AccountI just looked closer at your HTTP::respond command and it looks like you might be having an error:
HTTP::respond 301 "Location" "http://[HTTP::host/errorpage.htm"
Notice the missing close square bracket that should be after HTTP::host. Check your log file (/var/log/ltm) and see if you were in fact getting a rule error. That would cause an abort which would result in the Document contains no data. - João_Assad_4295
Nimbostratus
ah my bad, It is correct on the BigIP.. I just messed up the post here. - João_Assad_4295
Nimbostratus
Still can't make this work.
adding a HTTP::collect before the HTTP::respond doesnt make any difference, the client will keep sending the POST and get redirected only after it's done.
adding the HTTP::collect after the HTTP::respond gives the error Operation not supported (line 1) invoked from within "HTTP::collect"
adding a reject after the HTTP::respond will give the Document contains no data error on the client and no errors on the logs
at this point Im really out of ideas... maybe this can't be done ? - drteeth_127330Historic F5 AccountBIG-IP has no support for early responses at this time. It's also worth mentioning that even if BIG-IP did send the early response, there's no guarantee that the client will pay any attention.
That being said, rapmaster_c suggested that you try doing this at the layer below HTTP. That is, try crafting the response with TCP::respond. You'll need to create a complete response with the HTTP status line and headers. Then you can force the connection closed with HTTP::close. I think the HTTP::close might discard the data received so far. To be honest, this is a long shot, but it might work. - Jari_Hyttinen_1
Nimbostratus
Hi,
I'm fighting with the same problem.
I would like to send an early response to the client,
that the user is trying to send too large file with POST request.
Has anybody solved this problem yet?
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
