Sha256: 1327133503ed89e1a6e9bca1c01c4761514baeb0bf51bd7a0376de2ad9fd5e8b

Contents?: true

Size: 1.05 KB

Versions: 57

Compression:

Stored size: 1.05 KB

Contents

module HTTP
  class Response
    def to_webmock
      webmock_response = ::WebMock::Response.new

      webmock_response.status  = [status.to_i, reason]
      webmock_response.body    = body.to_s
      webmock_response.headers = headers.to_h

      webmock_response
    end

    class << self
      def from_webmock(webmock_response, request_signature = nil)
        status  = Status.new(webmock_response.status.first)
        headers = webmock_response.headers || {}
        body    = Body.new Streamer.new webmock_response.body
        uri     = normalize_uri(request_signature && request_signature.uri)

        return new(status, "1.1", headers, body, uri) if HTTP::VERSION < "1.0.0"

        new({
          status: status,
          version: "1.1",
          headers: headers,
          body: body,
          uri: uri
        })
      end

      private

      def normalize_uri(uri)
        return unless uri

        uri = Addressable::URI.parse uri
        uri.port = nil if uri.default_port && uri.port == uri.default_port

        uri
      end
    end
  end
end

Version data entries

57 entries across 51 versions & 5 rubygems

Version Path
webmock-3.7.1 lib/webmock/http_lib_adapters/http_rb/response.rb
webmock-3.7.0 lib/webmock/http_lib_adapters/http_rb/response.rb
webmock-3.6.2 lib/webmock/http_lib_adapters/http_rb/response.rb
webmock-3.6.0 lib/webmock/http_lib_adapters/http_rb/response.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/http_rb/response.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/http_rb/response.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/http_rb/response.rb
webmock-3.5.1 lib/webmock/http_lib_adapters/http_rb/response.rb
webmock-3.5.0 lib/webmock/http_lib_adapters/http_rb/response.rb
vagrant-unbundled-2.2.2.0 vendor/bundle/ruby/2.5.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/http_rb/response.rb
vagrant-unbundled-2.2.0.0 vendor/bundle/ruby/2.5.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/http_rb/response.rb
vagrant-unbundled-2.1.4.0 vendor/bundle/ruby/2.5.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/http_rb/response.rb
vagrant-unbundled-2.1.2.0 vendor/bundle/ruby/2.3.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/http_rb/response.rb
webmock-3.4.2 lib/webmock/http_lib_adapters/http_rb/response.rb
vagrant-unbundled-2.1.1.0 vendor/bundle/ruby/2.5.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/http_rb/response.rb
vagrant-unbundled-2.0.4.0 vendor/bundle/ruby/2.5.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/http_rb/response.rb
webmock-3.4.1 lib/webmock/http_lib_adapters/http_rb/response.rb
webmock-3.4.0 lib/webmock/http_lib_adapters/http_rb/response.rb
vagrant-unbundled-2.0.3.0 vendor/bundle/ruby/2.5.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/http_rb/response.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.5.0/gems/webmock-2.3.2/lib/webmock/http_lib_adapters/http_rb/response.rb