Sha256: 04a5e340d9a2fd9554ac157f39e96ed4babee0d3e724f95855bb015249a6e1ce

Contents?: true

Size: 843 Bytes

Versions: 4

Compression:

Stored size: 843 Bytes

Contents

require 'faraday'

module Infrataster
  module Contexts
    class HttpContext < BaseContext
      def response
        server.forward_port(resource.uri.port) do |address, port|
          url = "#{resource.uri.scheme}://#{address}:#{port}"

          conn = Faraday.new(:url => url) do |faraday|
            faraday.request  :url_encoded
            faraday.response :logger, Logger
            faraday.adapter  Faraday.default_adapter
          end

          conn.public_send(resource.method) do |req|
            resource.params.each_pair do |k, v|
              req.params[k] = v
            end
            req.headers['Host'] = resource.uri.host
            resource.headers.each_pair do |k, v|
              req.headers[k] = v
            end
            req.url resource.uri.path
          end
        end
      end
    end
  end
end


Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
infrataster-0.1.11 lib/infrataster/contexts/http_context.rb
infrataster-0.1.10 lib/infrataster/contexts/http_context.rb
infrataster-0.1.9 lib/infrataster/contexts/http_context.rb
infrataster-0.1.8 lib/infrataster/contexts/http_context.rb