Forum Discussion
mblachford_3582
May 30, 2018Nimbostratus
HTTP::respond and header request modifications
Hey everyone.
Trying to federate AWS S3 and an on premises S3 compliant storage box with iRules/iRulesLX. The calling client connecting to the BigIP will by default have the access key and secret ...
mblachford_3582
May 30, 2018Nimbostratus
Good points on seeing the sanitized iRule. I don't think there is anything proprietary. Here it is (the relevant bit is in the GET case under when HTTP_REQUEST. iRulesLX returns an array of data that we want to HTTP::respond with)
when RULE_INIT {
set static::debug 0
}
proc logger { mthd httpc msg } {
switch -exact -- $mthd {
request {
if { $static::debug != 0 } {
log -noname local0.debug "=START HTTP REQUEST=============================="
log -noname local0.debug "Client [IP::client_addr]:[TCP::client_port] -> [HTTP::method] [HTTP::host] [HTTP::uri]"
foreach reqHeader [HTTP::header names] {
log -noname local0.debug "$reqHeader: [HTTP::header value $reqHeader]"
}
log -noname local0.debug "=END HTTP REQUEST==============================="
} else {
log -noname local0.info "Client [IP::client_addr] -> [HTTP::method] [HTTP::host] [HTTP::uri] (HTTP REQUEST)"
log -noname local0.info $msg
}
}
response {
if { $static::debug != 0 } {
log -noname local0.debug "=START HTTP RESPONSE=============================="
log -noname local0.debug "HTTP RESPONSE - status: $httpc"
foreach resHeader $msg {
set key [ getfield $resHeader "|" 1]
set value [ getfield $resHeader "|" 2]
log -noname local0.debug "$key: $value"
}
log -noname local0.debug "=END HTTP RESPONSE=============================="
} else {
log -noname local0.info "HTTP RESPONSE - status: $httpc"
}
}
default {
log -noname local0.info "$msg"
}
}
}
when HTTP_REQUEST {
set rpc_handle [ILX::init syncp-plugin syncp-extension]
switch [HTTP::method] {
HEAD {
if {[ catch {ILX::call $rpc_handle -timeout 12000 "syncp_http_head_req" [HTTP::method] [HTTP::uri] } result ]} {
call logger request null "ILX syncp_http_head_req timeout. Reason: $result"
}
call logger request null null
set httpresponse [ lindex $result 0 ]
set httpheaders [ lindex $result 1 ]
set httpcontent [ lindex $result 2 ]
if { [string length $httpcontent] == 0 } {
set stringtoeval "HTTP::respond $httpresponse -version auto noserver"
} else {
set stringtoeval "HTTP::respond $httpresponse -version auto content {$httpcontent} noserver"
}
foreach hdrs $httpheaders {
set key [ getfield $hdrs "|" 1]
set value [ getfield $hdrs "|" 2]
append stringtoeval " {$key} {$value} "
}
call logger response $httpresponse $httpheaders
eval $stringtoeval
}
GET {
if {[ catch {ILX::call $rpc_handle -timeout 12000 "syncp_http_get_req" [HTTP::method] [HTTP::uri] } result ]} {
call logger request null "ILX syncp_http_get_req timeout. Reason: $result"
}
call logger request null null
set host [ lindex $result 0 ]
set xamzcontentsha256 [ lindex $result 1 ]
set xamzdate [ lindex $result 2 ]
set authorization [ lindex $result 3 ]
HTTP::respond 302 noserver Location "$host" Authorization "$authorization" X-Amz-Date "$xamzdate" X-Amz-Content-Sha256 "$xamzcontentsha256"
}
PUT {
if {[ catch {ILX::call $rpc_handle -timeout 12000 "syncp_http_put_req" [HTTP::method] [HTTP::uri] } result ]} {
call logger request null "ILX syncp_http_put_req timeout. Reason: $result"
}
call logger request null null
}
DELETE {
if {[ catch {ILX::call $rpc_handle -timeout 12000 "syncp_http_delete_req" [HTTP::method] [HTTP::uri] } result ]} {
call logger request "ILX syncp_http_delete_req timeout. Reason: $result"
}
call logger request null null
}
}
}
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