Forum Discussion

AS_6517's avatar
AS_6517
Icon for Nimbostratus rankNimbostratus
Jul 24, 2012

add a comment just before </body> tag to any HTTP response

Hi,

 

Can some help me with a trivial thing, I would like to simply add a comment just before tag to any HTTP response going out off the F5 . How do I do that?

 

 

I am a beginner so excuse my ignorance

 

2 Replies

  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus
    AS,

     

     

    See wiki entry here: https://devcentral.f5.com/wiki/iRules.InsertContentIntoServerResponse.ashx (Insert Content Into Server Response).

     

     

    However, Hoolio makes the point whether you need to HTTP::collect first and I tend to agree.

     

     

    This wiki should help: https://devcentral.f5.com/wiki/irules.HTTP__collect.ashx

     

     

    Hope this helps,

     

    N
  • You could also do this more efficiently using a stream profile versus buffering the full payload with HTTP::collect. You'd need to add a blank stream profile and a custom HTTP profile with response chunking set to rechunk.

    
    when HTTP_REQUEST {
    
     Javascript to inject in text responses (wrap in curly braces to avoid having to escape meta-characters).
    set js {my javascript goes here...}
    
     Disable the stream filter by default 
    STREAM::disable 
    } 
     
    when HTTP_RESPONSE { 
     
     Check for text responses
    if {[HTTP::header value Content-Type] contains "text"} {
    
     Replace  closing tag with $js
    STREAM::expression "@@$js@"
    STREAM::enable 
    }
    }
    

    Aaron