Forum Discussion
mart_58302
Nimbostratus
Aug 15, 2008Serving wpad.dat with F5?
Hello.
Maybe wrong area, but I'm trying to find out, is it possible to use F5 himself as web server, to serve text based file like wpad.dat or cache.pac for clients?
How to do it?
23 Replies
- hoolio
Cirrostratus
This version would match the same host header values, but for a URI of /cache3.pac, it sends the proxygateway2.internal:8080 response:when HTTP_REQUEST { log local0. "[IP::client_addr]:[TCP::client_port]: New request to [HTTP::host], [HTTP::uri]" Check if requested Host header is wpad.internal switch [string tolower [HTTP::host]] { "cache.internal" - "wpad.internal" { log local0. "[IP::client_addr]:[TCP::client_port]: Request matched host check" Host check matched. Now check the requested URI switch -glob [HTTP::uri] { "/wpad.dat*" - "/cache1.pac" { log local0. "[IP::client_addr]:[TCP::client_port]: Request matched URI check for /wpad.dat, /cache1.pac" HTTP::respond 200 content { function FindProxyForURL(url, host) { if(shExpMatch(host, "*[^0123456789.]*") == false) if( isInNet\(host, "127.0.0.0", "255.0.0.0") || isInNet(host, "172.17.0.0", "255.255.0.0") || isInNet(host, "172.18.0.0", "255.255.0.0") ) return "DIRECT"; \ else return "PROXY proxygateway.internal:8080; DIRECT";} } } "/cache3.pac" { log local0. "[IP::client_addr]:[TCP::client_port]: Request matched URI check for /cache3.pac" HTTP::respond 200 content { function FindProxyForURL(url, host) { if(shExpMatch(host, "*[^0123456789.]*") == false) if( isInNet\(host, "127.0.0.0", "255.0.0.0") || isInNet(host, "172.17.0.0", "255.255.0.0") || isInNet(host, "172.18.0.0", "255.255.0.0") ) return "DIRECT"; \ else return "PROXY proxygateway2.internal:8080; DIRECT";} } } default { Take some default action if the requested host matched, but the URI didn't? HTTP::respond 400 content "Invalid URI" } } } default { Take some default action if the requested host didn't matched? HTTP::respond 400 content "Invalid host" } } }
Aaron - mart_58302
Nimbostratus
This version would match the same host header values, but for a URI of /cache3.pac, it sends the proxygateway2.internal:8080 response:
Yes, it does, thank You Aaron, You are super! - J-H_Johansen
Altostratus
9 years later...
I'm testing the LTM to server wpad/pac with irules and came up with this little script based on the response in this thread.
when HTTP_REQUEST { switch [string tolower [HTTP::host]] { "wpadtest.local" - "wpad.local" { set exp "function FindProxyForURL(url, host) {" append exp "\n" "if(isPlainHostName(host)) return \"DIRECT\";" append exp "\n" "if(shExpMatch(host, \"*\[^0123456789.\]*\") == false) return \"DIRECT\";" append exp "\n" "if(isInNet(host, \"127.0.0.0\", \"255.0.0.0\")) return \"DIRECT\";" append exp "\n" "if(isInNet(host, \"10.0.0.0\", \"255.0.0.0\")) return \"DIRECT\";" append exp "\n" "if(isInNet(host, \"172.16.0.0\", \"255.240.0.0\")) return \"DIRECT\";" append exp "\n" "if(isInNet(host, \"192.168.0.0\", \"255.255.0.0\")) return \"DIRECT\";" foreach mm [class names dg_wpad_shExpMatch] { append exp "" "if(shExpMatch(host, \"$mm\")) return \"DIRECT\";" } Last line append exp "\n" "return \"PROXY proxy.local:80\";\n}" HTTP::respond 200 content $exp "Content-Type" "application/x-ns-proxy-autoconfig" } default { HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri] } } }The data group list dg_wpad_shExpMatch contains all the exceptions where the client must bypass the proxy.
In a production environment this will be used by at least 1000-2000 users daily. Is there any way I can cache the output and set a 600 seconds TTL on the contents? Is this a good way of doing it or should I find other ways of serving this script?
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
