Class: Nonnative::HTTPProxy

Inherits:
Sinatra::Application
  • Object
show all
Defined in:
lib/nonnative/http_proxy_server.rb

Instance Method Summary collapse

Instance Method Details

#api_response(verb, uri, opts) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/nonnative/http_proxy_server.rb', line 19

def api_response(verb, uri, opts)
  client = RestClient::Resource.new(uri, opts)

  client.send(verb)
rescue RestClient::Exception => e
  e.response
end

#build_url(request, settings) ⇒ Object



15
16
17
# File 'lib/nonnative/http_proxy_server.rb', line 15

def build_url(request, settings)
  URI::HTTPS.build(host: settings.host, path: request.path_info, query: request.query_string).to_s
end

#retrieve_headers(request) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/nonnative/http_proxy_server.rb', line 6

def retrieve_headers(request)
  headers = request.env.map do |header, value|
    [header[5..].split('_').map(&:capitalize).join('-'), value] if header.start_with?('HTTP_')
  end
  headers = headers.compact.to_h

  headers.except('Host', 'Accept-Encoding', 'Version')
end