Forum Discussion

João_Assad_4295's avatar
João_Assad_4295
Icon for Nimbostratus rankNimbostratus
Nov 14, 2005

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.

15 Replies

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

     

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    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
  • 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"

     

     

    }

     

    }

     

    }