ProxyAction action, which redirects requests to another interfaceHttpRequest class and services to create it
			Serializable::inspect to show more useful information
			more_collections :: more_collections
Highly specific, but useful, collections-related classes.curl :: native_curl
Binding of C libCurl which allow us to interact with network.serialization :: serialization_core
Abstract services to serialize Nit objects to different formatscore :: union_find
union–find algorithm using an efficient disjoint-set data structure
# Provides the `ProxyAction` action, which redirects requests to another interface
module proxy
import curl
import reactor
# 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:17,1--71,3