its target. All headers are forwarded including User-Agent.
Please note: Requests passed to this action are blocking.
nitcorn :: ProxyAction :: defaultinit
nitcorn :: ProxyAction :: target
Target interface where to dispatch proxied requestsnitcorn :: ProxyAction :: target=
Target interface where to dispatch proxied requestsnitcorn $ ProxyAction :: SELF
Type of this instance, automatically specialized in every classnitcorn $ ProxyAction :: answer
Prepare aHttpResponse
destined to the client in response to the request
HttpResponse
destined to the client in response to the request
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
nitcorn :: Action :: defaultinit
core :: Object :: defaultinit
nitcorn :: ProxyAction :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: output_class_name
Display class name on stdout (debug only).nitcorn :: Action :: prepare_respond_and_close
Full to arequest
with sending the response and closing of the http_server
nitcorn :: ProxyAction :: target
Target interface where to dispatch proxied requestsnitcorn :: ProxyAction :: target=
Target interface where to dispatch proxied requests
# A request proxy. All requests received by this action will be redirected to
# its target. All headers are forwarded including User-Agent.
#
# Please note: Requests passed to this action are blocking.
class ProxyAction
super Action
# Target interface where to dispatch proxied requests
var target: Interface
redef fun answer(http_request, turi) do
var request = new CurlHTTPRequest("http://{self.target}{turi}")
var curl_headers = new HeaderMap
for k, v in http_request.header do
if k == "User-Agent" then
request.user_agent = v
else
curl_headers[k] = v
end
end
var curl_response = request.execute
var response: HttpResponse
if curl_response isa CurlResponseSuccess then
response = new HttpResponse(curl_response.status_code)
response.body = curl_response.body_str
else if curl_response isa CurlResponseFailed then
response = new HttpResponse(500)
# CURLE_COULDNT_RESOLVE_HOST
if curl_response.error_code == 6 then
response.status_code = 502 # Bad Gateway
# CURLE_URL_MALFORMAT
else if curl_response.error_code == 3 then
response.status_code = 520 # Unknown Error
# CURLE_COULDNT_CONNECT
else if curl_response.error_code == 7 then
response.status_code = 502 # Bad Gateway
end
else abort
return response
end
end
lib/nitcorn/proxy.nit:23,1--71,3