cancel
Showing results for 
Search instead for 
Did you mean: 

irule for request and response

Mikesisav
Altostratus
Altostratus

All,

 

Looking to irule a request and response header edit for https://example.com/x/y

 

So, that when user inputs https://example.com/x/y , request is sent to server as https://example.com/y

 

Anything input into y as a string is request to server.

 

I have created this:

 

when HTTP_REQUEST {

 if { [HTTP::path] equals "/x/y" }{ 

  HTTP::redirect "/y/"

 }

}

 

This returns above irule https://example.com/y . but, the ask is to add x back to the response and return https://example.com/x/y to the user.

 

The parts I am working on now are the response edit and how to use the string input by the user - y - to reflect anything. Similarly, to x when responding back.

 

1 REPLY 1

Mikesisav
Altostratus
Altostratus

So, I got some direction...

 

Here are the three possible paths : 

 

/x

/y

/z 

 

Each could have another resource behind the initial path i.e. /x/ping or /x/file or z/path or z/box.

 

The other resource /ping or /file or /path or /box is what I don't know will be called but needs to be requested to the server and /x, /y, or /z needs to be edited out and only the second resource needs to be sent to server.  

 

So user puts in /x/ping and /ping gets request to server.  

 

Similarly, when the response is sent back the first resource needs to be added back. As in if we called /x/ping, x would be add back from the server that only was called /ping.

 

So.. all that written, let me see how to apply the below with x.  

 

when HTTP_REQUEST {

  if { [HTTP::uri] starts_with "/x/1" } {

    #Comment:The string map is used to replace the uri value from /uri/1 to /uri/2.   

    HTTP::uri [string map {"/x/1/" "/x/2"} [HTTP::uri]]

    pool pool_x

  }

 

when HTTP_RESPONSE {

  if { [HTTP::uri] starts_with "/x/2" } {

    HTTP::uri [string map {"/x/2/" "/x/1"} [HTTP::uri]]

  }

 

 

So, with the three first resources - x, y, z - and this all being one virtual server, would I just create three irules and apply them all to the one virtual server?  

 

Happy Irulz Friday.