Forum Discussion

Mohammad_1363's avatar
Mohammad_1363
Icon for Altocumulus rankAltocumulus
Jul 15, 2021

Redirect HTTP along with header

Hello

I am trying to redirect HTTP request from one service to another URL like below

when HTTP_REQUEST {

   if { [string tolower [HTTP::host]] equals "service-api.xx.com" } {

      HTTP::redirect "https://newservice.api.xx.com/test-cg[HTTP::uri]"

      HTTP::header ????

   }

}

so when client initiate a request the initial call comes to the F5 and F5 will redirect from service-api.xx.com to https://newservice.api.xx.com/test-cg[HTTP::uri] the redirection is happening as expected but looks like when the initial call is coming, comes with a header to send the auth to the the token key, the example of initial call is https://new-api.xx.com/auth/sessions so my question is how can i send the header and its value while i am redirecting the request.

 

 

Thanks

  • You can try below

    when HTTP_REQUEST {
        switch -glob [string tolower [HTTP::host]] {
    	  "service-api.xx.com"
    	   {
    	    if { [HTTP::header exists "Auth_header"] } {
            set token [HTTP::header value Auth_header]
    		HTTP::respond 301 Location https://newservice.api.xx.com/test-cg[HTTP::uri]" "Auth_header" "$token"
    		return
               }
               } default {
              return
          }
        }
     }