Class: Stub::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/stub/server.rb

Overview


Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRequest

Returns a new instance of Request.



30
# File 'lib/stub/server.rb', line 30

def initialize; @state, @prelude = :init, "" end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



29
30
31
# File 'lib/stub/server.rb', line 29

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



29
30
31
# File 'lib/stub/server.rb', line 29

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.



29
30
31
# File 'lib/stub/server.rb', line 29

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



29
30
31
# File 'lib/stub/server.rb', line 29

def path
  @path
end

Instance Method Details

#completed?(str) ⇒ Boolean

adds data to the request, returns true if request is complete

Returns:

  • (Boolean)


67
68
69
70
71
72
73
74
# File 'lib/stub/server.rb', line 67

def completed?(str)
  str, @prelude = @prelude + str, "" unless @prelude.empty?
  add_lines(str)
  return unless @state == :body && @body.bytesize >= @content_length
  @prelude = bslice(@body, @content_length..-1)
  @body = bslice(@body, 0..@content_length)
  @state = :init
end

#cookiesObject



76
77
78
79
80
81
82
# File 'lib/stub/server.rb', line 76

def cookies
  return {} unless chdr = @headers["cookie"]
  chdr.strip.split(/\s*;\s*/).each_with_object({}) do |pair, o|
    k, v = pair.split(/\s*=\s*/)
    o[k.downcase] = v
  end
end