Forum Discussion

lstewart_53611's avatar
lstewart_53611
Icon for Nimbostratus rankNimbostratus
Apr 15, 2010

Redirect POST data while load balancing GET iRule

I am attempting to write an iRule which will allow data from a page to be redirected to an external URL, but will then deliver the followup page (simple GET data) from a vip. From everything I've been reading, one cannot do a true redirect of POST data, but must rewrite the URI to achieve the result, as otherwise the payload will be lost and only GET data will be redirected. Does anyone know of a way to redirect only the post data? That is, A load-balanced page http:///pagename displays a form. The user then posts data which should go to http:///external page. The form however needs to then send the user to a load-balanced page http:///pagename1 Thanks in advance for any ideas.
  • I am quite sure I understand your requirement thoroughly. here is what I think it is. you may try

    you may change ext_uri variable to be your desired url

     
    when RULE_INIT {
        set static::ext_url "http://10.10.71.3/test.post"
    }
    when HTTP_REQUEST {
            
        if { [string tolower [HTTP::method]] eq "post" } {
            HTTP::collect [HTTP::header "Content-Length"]
        }    
    }
    when HTTP_REQUEST_DATA {
        set content " \
            "
            
        foreach p [split [HTTP::payload] &] {
            set name  [getfield $p = 1]
            set value [decode_uri [getfield $p = 2]]
            set content "${content}"
        }
        set content "${content}"
       
        HTTP::respond 200 content $content
    }
    

    feel free to let me know if you have any question

    Nat
  • I'll have to try a variation on this and see how it does. Essentially I want to redirect the post data and nothing else; I realize my explanation was a little sketchy.
  • to explain more about iRule I posted

     

    1) if method = post, it issues HTTP::collect, which will invoke HTTP_REQUEST_DATA

     

    2) then it scan POST-data and prepare new content to respond to client. the new content will include

     

    - form with all INPUT field names retrieved from POST-data

     

    - the "action" parameter in the form points to external server

     

    - all input fields are set as hidden (so client wont see the data during the process

     

    - javascript that submit the form automatically

     

    3) then irule reply to client with HTTP::respond command with content prepared in step2

     

     

    so the idea is when client send post to BIG-IP, BIG-IP replies with html page which contains a form. the form contains post-data that client just sent. the form will be auto-submit by javascript

     

     

    Nat