Class: WebMock::HttpLibAdapters::CurbAdapter

Inherits:
WebMock::HttpLibAdapter show all
Defined in:
lib/webmock/http_lib_adapters/curb_adapter.rb

Constant Summary collapse

OriginalCurlEasy =
Curl::Easy

Class Method Summary collapse

Methods inherited from WebMock::HttpLibAdapter

adapter_for

Class Method Details

.disable!Object



24
25
26
27
# File 'lib/webmock/http_lib_adapters/curb_adapter.rb', line 24

def self.disable!
  Curl.send(:remove_const, :Easy)
  Curl.send(:const_set, :Easy, OriginalCurlEasy)
end

.enable!Object



19
20
21
22
# File 'lib/webmock/http_lib_adapters/curb_adapter.rb', line 19

def self.enable!
  Curl.send(:remove_const, :Easy)
  Curl.send(:const_set, :Easy, Curl::WebMockCurlEasy)
end

.parse_header_string(header_string) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/webmock/http_lib_adapters/curb_adapter.rb', line 31

def self.parse_header_string(header_string)
  status, headers = nil, {}

  header_string.split(/\r\n/).each do |header|
    if header =~ %r|^HTTP/1.[01] \d\d\d (.*)|
      status = $1
    else
      parts = header.split(':', 2)
      unless parts.empty?
        parts[1].strip! unless parts[1].nil?
        if headers.has_key?(parts[0])
          headers[parts[0]] = [headers[parts[0]]] unless headers[parts[0]].kind_of? Array
          headers[parts[0]] << parts[1]
        else
          headers[parts[0]] = parts[1]
        end
      end
    end
  end

  return status, headers
end