Forum Discussion
GavinW_29074
Nimbostratus
Feb 02, 2012Streamline error and response handling...
Hi there,
Currently we've got several rules set-up to do various functions.
A couple of examples are:
* Maintenance page handling
* Application error handling
* SSL Cli...
GavinW_29074
Nimbostratus
Feb 06, 2012Ok, after a bit of experimentation, I came up with this:
when RULE_INIT {
set static::RespondDebug 1
set static::unavailable_page [ifile get unavailable_page_html]
set static::offline_page [ifile get offline_page_html]
set static::secure_failure_page [ifile get secure_connection_failure_html]
set static::act_logo [ifile get act_logo_png]
}
when CLIENT_ACCEPTED priority 1 {
if {$static::RespondDebug > 0} { log local0.info "Processing CLIENT_ACCEPTED at priority 1" }
Set-up base variables.
set pool_error 0
set maintenance_mode 0
set ssl_error 0
set failure_result ""
set response_error 0
if {$static::RespondDebug > 0} { log local0.info "Variables set: \$pool_error = $pool_error, \$maintenance_mode = $maintenance_mode, \$ssl_error = $ssl_error, \$failure_result = '$failure_result', \$response_error = $response_error" }
}
when HTTP_REQUEST priority 20 {
if {$static::RespondDebug > 0} { log local0.info "Processing HTTP_REQUEST at Priority 20..." }
if {$static::RespondDebug > 0} { log local0.info "\$maintenance_mode = $maintenance_mode, \$ssl_error = $ssl_error, \$failure_result = '$failure_result'" }
Catch ACT Logo and return.
if { [HTTP::uri] ends_with "logo-act.png" } {
if {$static::RespondDebug > 0} { log local0.info "Returning ACT Logo..." }
HTTP::respond 200 content $static::act_logo "Content-Type" "image/png" "Connection" "Close"
TCP::close
event disable
return
}
Handle maintenance mode.
if {$maintenance_mode} {
if {$static::RespondDebug > 0} { log local0.info "Returning Maintenance page html..." }
switch -glob [HTTP::method] {
POST {
if {$static::RespondDebug > 0} { log local0.info "POST Method - Returning Code 503" }
HTTP::respond 503
event disable
return
}
GET {
if {$static::RespondDebug > 0} { log local0.info "GET Method - Returning HTML and Code 200" }
HTTP::respond 200 content $static::offline_page "Content-Type" "text/html"
event disable
return
}
}
TCP::close
}
Handle SSL error
if {$ssl_error} {
if {$static::RespondDebug > 0} { log local0.info "Returning SSL Error page html..." }
HTTP::respond 403 content [subst $static::secure_failure_page] "Content-Type" "text/html"
event disable
TCP::close
return
}
}
when HTTP_REQUEST priority 750 {
if {$static::RespondDebug > 0} { log local0.info "Processing HTTP_REQUEST at Priority 750..." }
if {$static::RespondDebug > 0} { log local0.info "\$pool_error = $pool_error" }
Handle error page.
if {$pool_error} {
switch -glob [HTTP::method] {
POST {
if {$static::RespondDebug > 0} { log local0.info "POST Method - Returning Code 503" }
HTTP::respond 503
event disable
return
}
GET {
if {$static::RespondDebug > 0} { log local0.info "GET Method - Returning HTML and Code 200" }
HTTP::respond 503 content $static::unavailable_page "Content-Type" "text/html"
event disable
return
}
}
TCP::close
}
if {$static::RespondDebug > 0} { log local0.info "Passed error checking... Continuing..." }
return
}
when HTTP_RESPONSE priority 250 {
if {$static::RespondDebug > 0} { log local0.info "Processing HTTP_RESPONSE... at Priority 250" }
if {$static::RespondDebug > 0} { log local0.info "\$response_error = $response_error" }
if {$response_error} {
switch -glob [string toupper $HTTP_METHOD] {
"POST" {
if {$static::RespondDebug > 0} { log local0.info "POST Method - Returning Code 503" }
HTTP::respond 503
event disable
return
}
"GET" {
if {$static::RespondDebug > 0} { log local0.info "GET Method - Returning HTML and Code 200" }
HTTP::respond 200 content $static::unavailable_page "Content-Type" "text/html"
event disable
return
}
}
}
}
Comment welcome.
Cheers
Gavin
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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