Class: Stub::Request

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

Overview


Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRequest

Returns a new instance of Request.



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

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

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



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

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.



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

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#completed?(str) ⇒ Boolean

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

Returns:

  • (Boolean)


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

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



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

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