Forum Discussion

grmanikantan's avatar
grmanikantan
Icon for Altostratus rankAltostratus
Aug 10, 2023

Need help on irule: External content for internal request in F5

I have a requirement and trying to achive through irule but some how not working as expected..

Requirement:

Client to access Internal URL : https://www.abcd.com

F5 to call the content from this external URL: https://www.myexternal.com

Insert external URL content and send back to internal URL as response

I tried this way but not working...

========

when HTTP_REQUEST {
if { [HTTP::host] equals "www.abcd.com" } {
# Call the subroutine to handle the internal request and respond to the client
internal_call_and_respond
}
}

# Subroutine to handle the internal call and response
proc internal_call_and_respond {} {
set backend_response [HTTP::get "https://www.myexternal.com"]

set response_status [HTTP::status]
set response_headers [HTTP::header]

# Set the response status code and headers from the backend response
HTTP::respond $response_status [HTTP::header replace $response_headers] -persist {
# Send the backend response content as the body of the client response
echo $backend_response
}
}

==========

Thanks in advance...

 

 

  • Have you used log statements to verify expected variable inputs in each section of the iRule? That is the first thing I'd do.

    • grmanikantan's avatar
      grmanikantan
      Icon for Altostratus rankAltostratus

      Hi AubreyKing,

      Thanks for your response.

      While updating this irule, i got below messages...

      01070151:3: Rule [/Common/irule-test] error: /Common/irule-test:4: error: [undefined procedure: internal_call_and_respond][internal_call_and_respond]
      /Common/irule-test:7: error: [command is not valid in the current scope][proc internal_call_and_respond {} {
      set backend_response [HTTP::get "https://www.myexternal.com"]
      set response_status [HTTP::status]
      set response_headers [HTTP::header]
      }]

       

      • Paulius's avatar
        Paulius
        Icon for MVP rankMVP

        grmanikantan Based on the log it seems like the subroutine isn't configured properly. Before we go any further with this, what's the requirement that is forcing you to have to take care of this on the F5?

  • grmanikantan - If your post was solved it would be helpful to the community to select *Accept As Solution*.
    This helps future readers find answers more quickly and confirms the efforts of those who helped.
    Thanks for being part of our community.
    Lief