Sha256: 6cfb5ea131dbac1d018b73a9a41b9db7abaf7b14860104b98a28a3199e649907

Contents?: true

Size: 701 Bytes

Versions: 2

Compression:

Stored size: 701 Bytes

Contents

require 'excon'

module Twimock
  module API
    # Rack Application
    # Net::HTTP は ShamRack で偽装されるため, Excon (Socket) で通信する
    class Application
      def call(env)
        request(env)
      end

      private

      def request(env)
        rackreq = Rack::Request.new(env)
        connection = Excon.new(rackreq.url)

        options = {}
        options[:method]  = rackreq.request_method
        options[:path]    = rackreq.path
        options[:headers] = rackreq.env.select{|k,v| k !~ /^rack\./}
        options[:body]    = rackreq.body.read

        res = connection.request(options)
        [ res.status, res.headers, [ res.body ] ]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
twimock-0.0.2 lib/twimock/api/application.rb
twimock-0.0.1 lib/twimock/api/application.rb