Forum Discussion

DarkSideOfTheQ_'s avatar
DarkSideOfTheQ_
Icon for Nimbostratus rankNimbostratus
Mar 27, 2009

Change content-type and status code

OK, so I've been asked to change the status code and also the content-type for one of our apps. I know I can change the status code, but haven't done anything with changing the content-type. Can I do this in the same iRule and if so...how? Help is much appreciated.

 

 

Here is the iRule I've been using to change the status code for their app. (NOTE: I modified the 'content' returned to what they want to return now, before it was just "No Content")

 

 

 
 when HTTP_REQUEST {   
     switch -glob [HTTP::host] {   
       "*server1.mydomain.com" -   
       "*server2.mydomain.com" - 
       "*server3.mydomain.com" - 
       "*server4.mydomain.com" {   
         HTTP::respond 200 content "%FDF-1.21 0 obj<> >>>>endobjtrailer<>%%EOF"   
       }   
     }   
   } 
 

 

 

They would like to return the content-type of "application/vnd.fdf"

 

 

TIA,

 

DarkSide

2 Replies

  • You can add headers to the response with HTTP::respond. Also, you can consolidate the server using glob style wildcard matching:

     
     when HTTP_REQUEST {    
         switch -glob [string tolower [HTTP::host]] {    
            "*server[1-4].mydomain.com"  { 
              HTTP::respond 200 content {%FDF-1.21 0 obj<> >>>>endobjtrailer<>%%EOF} "Content-Type" "application/vnd.fdf" 
           }    
        }    
     }  
     

    Aaron
  • Hoolio - Thanks for the help with this. I've got another question about the content I'm try to return. The string I provided before had to be tweaked and once I put it in the LB, it gets some characters converted.

     

     

    %FDF-1.2%Õ×ÙÏ1 0 obj << /FDF << /JavaScript << /Before (serverResponse(\))>> >> >> endobjtrailer<>%%EOF

     

     

    The "Õ×ÙÏ" is being converted to "????" when I add it, can the formatting be kept somehow?

     

     

    Like the TCL references, is there a list of accepted characters that can go into an iRule?

     

     

    TIA

     

    DarkSide