File: request.rb

package info (click to toggle)
ruby-webmock 3.25.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,172 kB
  • sloc: ruby: 12,829; makefile: 6
file content (28 lines) | stat: -rw-r--r-- 634 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

module HTTP
  class Request
    def webmock_signature
      request_body = nil

      if defined?(HTTP::Request::Body)
        request_body = String.new
        first_chunk_encoding = nil
        body.each do |part|
          request_body << part
          first_chunk_encoding ||= part.encoding
        end

        request_body.force_encoding(first_chunk_encoding) if first_chunk_encoding
        request_body
      else
        request_body = body
      end

      ::WebMock::RequestSignature.new(verb, uri.to_s, {
        headers: headers.to_h,
        body: request_body
      })
    end
  end
end