Skip to content

Instantly share code, notes, and snippets.

@travisbell
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save travisbell/9349123 to your computer and use it in GitHub Desktop.
Save travisbell/9349123 to your computer and use it in GitHub Desktop.
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