10-Aug-2023 03:56 - edited 10-Aug-2023 04:15
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...
10-Aug-2023 08:21
Have you used log statements to verify expected variable inputs in each section of the iRule? That is the first thing I'd do.
10-Aug-2023 09:01
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]
}]
10-Aug-2023 21:41
@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?
11-Aug-2023 04:00
Hi Paul, My requirement is simple. There is one internal URL which is configured in F5 VS, if user hit that URL ( https://www.abcd.com ) F5 should be respond with external content (webpages) which is available in the outside of F5 (https://www.myexternal.com). I'm trying various methods subroutine is one of that...
11-Aug-2023 07:10
@grmanikantan If you are just forwarding the content of that external site you might be better off configuring a pool with a pool member using the FQDN www.myexternal.com and then using a string map to replace instances of www.abcd.com with www.myexternal.com before it's set to the the destination. Keep in mind that you will have to enable SNAT for this to work most likely. The stringmap should look something like the following.
when HTTP_REQUEST priority 500 {
if {[HTTP::uri] starts_with "/public/"} {
HTTP::host [string map {"www.abcd.com" "www.myexternal.com"}[HTTP::host]]
pool POOL_ExternalWeb_443
}
}
21-Aug-2023 15:42
@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