Forum Discussion

Toni_Brown_2069's avatar
Toni_Brown_2069
Icon for Nimbostratus rankNimbostratus
Jun 18, 2015

Parsing request using iRules : trying to find the equivalent of scriptname

Hi,

 

I am trying to do a request header insert based on finding the 'scriptname' within the url, where the term scriptname is something I am familiar with from experiences with another reverse proxy server.

 

I have looked at the HTTP object properties and can't find an elegant solution for this that will be fast and reliable and I am still building up confidence with the iRules language.

 

For say a url of http://www.TSite.com/art/gallery.cgi/mammals?animal=dog&color=black

 

I want to get the bit that corresponds to /art/gallery.cgi

 

(this is just an example.. but my urls are similar in nature)

 

Any help would be really appreciated! :)

 

Thanks,

 

Toni

 

9 Replies

  • Hi,

    The irule wiki is there to help you find example of irules.

    when HTTP_REQUEST {
        if { [HTTP::path] starts_with "/art/gallery.cgi" } {
        HTTP::header insert header_1 value_1
        }
    }
    
  • Hi,

     

    Thanks. I've looked through quite a few examples... I can see the HTTP::path one and thought that might be ideal, but using the example :

     

    http://www.TSite.com/art/gallery.cgi/mammals?animal=dog&color=black

     

    HTTP:path would return /art/gallery.cgi/mammals most likely...

     

    I need it to only go up to the file name... i.e. /art/gallery.cgi

     

    The url above is really just an example by the way, but my urls are similar in that there can be a forward slash after the filename before the question mark query string comes into play.

     

    And from there the value would get injected into the HTTP:header which I know what to do from there...

     

    I guess I could some string manipulation, but it would be nice to avoid that if possible.

     

    Thanks,

     

    Toni

     

  • What was suggested above would provide the results you are looking for. Are you looking to insert a header value based on a path (e.g. /art/gallery.cgi)? The HTTP::path wiki page https://devcentral.f5.com/wiki/iRules.HTTP__path.ashx states that Returns or sets the path part of the HTTP request. The path is defined as the path and filename in a request. It does not include the query string; which was suggested above, or....are you wanting to change something else?

     

  • You can replace the operator starts_with by equals if you want only /art/gallery.cgi and not sub-directories.

    Can you send examples of what you need? like:

    clientside request :

    GET /art/gallery.cgi/mammals?animal=dog&color=black HTTP/1.1
    HOST: www.TSite.com
    

    Serverside request :

    GET /art/gallery.cgi/mammals?animal=dog&color=black HTTP/1.1
    HOST: www.TSite.com
    NewHeader: XXX
    
  • Hi,

     

    Yes I've had a good look at the HTTP::path option, but the problem is that it will take say a url of

     

    http://www.TSite.com/art/gallery.cgi/mammals?animal=dog&color=black

     

    and make it

     

    /art/gallery.cgi/mammals

     

    I need to extract just up to the filename... however many directories that might be... e.g. want this

     

    /art/gallery.cgi

     

    So in other words what makes it tricky is that we have other stuff after the filename, but before the querystring component.

     

    But it's looking like it isn't very easy... with the apache rewrite utility, I think this was the equivalent of asking for the scriptname.

     

    Thanks,

     

    Toni

     

  • you can extract filename from HTTP::path with commands:

     

    [findstr [HTTP::path] / 0 "cgi/"]

     

  • Hi Stanislas

     

    I guess it is more that I want to get the HTTP::path up to and including the end of the filename

     

    i.e. for http://www.TSite.com/art/gallery.cgi/mammals?animal=dog&color=black

     

    I want

     

    /art/gallery.cgi

     

    not definitely not anything further... e.g.

     

    /art/gallery.cgi/mammals

     

    I also would prefer not to assume what the filename ext is for the request and let the F5 functions figure that out.

     

    Thanks,

     

    Toni

     

  • Thanks for that... I had a good look around after looking through suggestions and used that to get something that has worked for me.

     

    Thanks,

     

    Toni