Last active
August 29, 2015 13:57
-
-
Save travisbell/9349123 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'goliath' | |
require 'em-synchrony' | |
require "em-synchrony/em-http" | |
class ProxyTest < Goliath::API | |
use Goliath::Rack::Render, 'json' | |
def response(env) | |
http_request = EM::HttpRequest.new("http://localhost:4568#{env['REQUEST_URI']}", :connect_timeout => 1) | |
request = case(env['REQUEST_METHOD']) | |
when 'HEAD' then http_request.head(:keepalive => true) | |
when 'GET' then http_request.get(:keepalive => true) | |
end | |
raise Goliath::Validation::GatewayTimeoutError.new({ "status_code" => 7, "status_message" => "Request Timed Out" }) if request.error == Errno::ECONNREFUSED | |
[request.response_header.status, response_headers, request.response] | |
end | |
def to_http_header(k) | |
k.downcase.split('_').collect { |e| e.capitalize }.join('-') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment