Forum Discussion

John_Adams's avatar
John_Adams
Icon for Altocumulus rankAltocumulus
Dec 18, 2024

iRule: Failure to activate payload

Hi, folks,

     I'm getting a result I don't understand on a very simple iRule. It works in this version:

when HTTP_REQUEST { if {some_stuff} {

     drop

     log local0.warn "Warning"

}

 

     But this does not display the HTML:

when HTTP_REQUEST { if {some_stuff} {

    HTTP::respond 200 content {     <html>Some HTML</html>  }

    log local0.warn "Warning"

}

 

     And neither does this:

when HTTP_REQUEST { if {some_stuff} {

    HTTP::respond 200 content { [ifile get _our_ifile] "Content-Type" "text/html;charset=utf-8" }

    log local0.warn "Warning"

}

 

     I've verified that the HTML is valid. What am I missing?

Thanks,

     John A

  • Hi John,

     

    Not sure of the error your getting but essentially something like this should work:

     

    when HTTP_REQUEST {
        # Log the intercepted request (optional, for debugging)
        log local0. "HTTP Request intercepted: [HTTP::method] [HTTP::uri]"

        # Respond with custom HTML content
        HTTP::respond 200 content {
            <!DOCTYPE html>
            <html>
            <head>
                <title>Custom Response</title>
                <style>
                    body { font-family: Arial, sans-serif; background-color: #f0f0f0; text-align: center; padding: 50px; }
                    h1 { color: #333; }
                    p { font-size: 18px; color: #666; }
                </style>
            </head>
            <body>
                <h1>Welcome to F5 BIG-IP!</h1>
                <p>This response was generated directly by an F5 iRule.</p>
                <p>Have a great day!</p>
            </body>
            </html>
        }
    }

     

    • John_Adams's avatar
      John_Adams
      Icon for Altocumulus rankAltocumulus

      Hi, Jeffery,

           That's very much like what I have, and yet, it does not work. I'm not getting an error, and the logging works. It just fails to deliver the page.

      Thanks,

           John A

    • John_Adams's avatar
      John_Adams
      Icon for Altocumulus rankAltocumulus

      You know what fixed me up? Changing that first line to: when HTTP_REQUEST priority 1000 {

  • Interesting, did you already have other HTTP_Request event handlers elsewhere?  or were there additional irules applied to the VS... Either way if you use the same event handlers across different irules applied to a VS or within the same irule you should apply priority to direct what event and action should be processed first 😀

    • John_Adams's avatar
      John_Adams
      Icon for Altocumulus rankAltocumulus

      There were additional iRules applied, mostly with explicit priorities set.