Module: Weary::Adapter

Included in:
Excon, Excon, NetHttp, NetHttp, Typhoeus, Typhoeus
Defined in:
lib/weary/adapter.rb,
lib/weary/adapters/excon.rb,
lib/weary/adapters/net_http.rb,
lib/weary/adapters/typhoeus.rb

Overview

An abstract interface. A subclass should be something that actually opens a socket to make the request, e.g. Net/HTTP, Curb, etc.

Defined Under Namespace

Classes: Excon, NetHttp, Typhoeus

Constant Summary

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



15
16
17
# File 'lib/weary/adapter.rb', line 15

def call(env)
  connect(Rack::Request.new(env)).finish
end

#connect(request) ⇒ Object

request is a Rack::Request This computation is performed in a Promise/Future Returns a Rack::Response



22
23
24
# File 'lib/weary/adapter.rb', line 22

def connect(request)
  Rack::Response.new [""], 501, {"Content-Type" => "text/plain"}
end

#initialize(app = nil) ⇒ Object



11
12
13
# File 'lib/weary/adapter.rb', line 11

def initialize(app=nil)
  @app = app
end

#normalize_request_headers(env) ⇒ Object

Modify the headers of an Env to be Capitalized strings with dashes (as opposed to the CGI-like headers needed by Rack).



28
29
30
31
32
33
34
35
# File 'lib/weary/adapter.rb', line 28

def normalize_request_headers(env)
  req_headers = env.reject {|k,v| !k.start_with? "HTTP_" }
  normalized = req_headers.map do |k, v|
    new_key = k.sub("HTTP_",'').split('_').map(&:capitalize).join('-')
    [new_key, v] unless UNWANTED_REQUEST_HEADERS.include? new_key
  end
  Hash[normalized]
end

#normalize_response(headers) ⇒ Object

According to the Rack Spec: > The header must not contain a Status key…



39
40
41
# File 'lib/weary/adapter.rb', line 39

def normalize_response(headers)
  headers.reject {|k,v| k.downcase == 'status' }
end