redirect 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.

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.

Are 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?

I tried:

HTTP::collect $clen

and

HTTP::collect 1

and

HTTP::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

You 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?

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.

I 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.

ah my bad, It is correct on the BigIP.. I just messed up the post here.

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 ?

BIG-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.

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?

This rule works with IE6 but not with Mozilla based browsers. Why is that ?

The client shows a alert “The document contains no data”

The rule is:

when HTTP_REQUEST {

if { [HTTP::uri] starts_with “/upload” } {

set method [HTTP::method]

set clen [HTTP::header Content-Length]

if { $method ==“POST” and $clen > 40960 } {

log local0. “Over 40 kb post: ($clen) from [IP::client_addr]”

reject

HTTP::respond 307 “Location” “http://www.mydomain.com/xxx.html”

}

}

}

I have tried to add HTTP::close before HTTP::respond, but it doesn’t effect anyway.

I also tried to change HTTP::respond line to

HTTP::respond 303 content “http://www.mydomain.com/xxx.html”

and it doesn’t effect either.

It’s interesting that it won’t work in Mozilla based browsers. It sounds like it has something to do with the way that the different browsers are handling the 307 response the BIG-IP is sending them. Mozilla isn’t dropping immediately, which may have something to do with RFC adherence, but I’d have to dig more deeply into it to be sure.

I might recommend adding some logging statements to be sure that the rule is behaving the same in both scenarios, so you can be sure it’s only the browser’s interpretation of the response that changes. In which case, you’d have to identify what it takes to get Mozilla to drop the connection.

-Colin

Please try adding the ‘reject’ after the HTTP::redirect.

s/HTTP::redirect/HTTP::respond

Hi,

Finally I got this iRule working. The issue was to use discard not reject.

I don’t excatly know the difference between these two commands,

but now it works almost great.

Now I have noticed that if client tries to send much more bigger file

(actually over 140 kilobytes) HTTP::respond does not work correctly.

I have added logging statements to the iRule and it seems to me that every step goes OK.

I have check the request log from the web server behind Big-IP

that the POST request has been discard by Big-IP. That is great,

but I want to send a real response to the client.

What could cause this behaviour?

Here is my current iRule:

when HTTP_REQUEST {

if { [HTTP::uri] starts_with “/upload” } {

set method [HTTP::method]

set clen [HTTP::header Content-Length]

if { $method ==“POST” and $clen > 133120 } {

log local0. “Over 130 kb post: ($clen) from [IP::client_addr]”

discard

HTTP::close

HTTP::respond 307 “Location” “http://www.mydomain.com/xxx.html”

}

}

}