Class: Richard::Internal::BasicRequestLineParser

Inherits:
Object
  • Object
show all
Defined in:
lib/richard_iii/internal/curl.rb

Class Method Summary collapse

Class Method Details

.from(text, headers) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/richard_iii/internal/curl.rb', line 5

def from(text, headers)
  lines = text.lines.map(&:chomp).map(&:strip)

  verb = lines.first.match(/^(\w+)/)[1]
  path = lines.first.match(/(\S+)$/)[1]
  host = headers["Host"]

  is_absolute = path.include?('://')

  fail "Missing host header. When you supply a relative earl you have to supply host header too." if !is_absolute && host.nil?

  earl = is_absolute ? path : "https://#{host}#{path}"

  RequestLine.new(verb, earl)
end