Class: H2::Server::Stream::Request
- Inherits:
-
Object
- Object
- H2::Server::Stream::Request
- Defined in:
- lib/h2/server/stream/request.rb
Constant Summary collapse
- HEADER_HASH =
a case-insensitive hash that also handles symbol translation i.e. s/_/-/
Hash.new do |hash, key| k = key.to_s.upcase k.gsub! '_', '-' if Symbol === key _, value = hash.find {|header_key,v| header_key.upcase == k} hash[key] = value if value end
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Instance Method Summary collapse
-
#addr ⇒ Object
retreive the IP address of the connection.
-
#authority ⇒ Object
retreive the authority from the stream request headers.
-
#initialize(stream) ⇒ Request
constructor
A new instance of Request.
-
#method ⇒ Object
retreive the HTTP method as a lowercase
Symbol
. -
#path ⇒ Object
retreive the path from the stream request headers.
-
#query_string ⇒ Object
retreive the query string from the stream request headers.
-
#respond(status:, headers: {}, body: '') ⇒ Object
respond to this request on its stream.
-
#scheme ⇒ Object
retreive the scheme from the stream request headers.
Constructor Details
#initialize(stream) ⇒ Request
Returns a new instance of Request.
17 18 19 20 21 |
# File 'lib/h2/server/stream/request.rb', line 17 def initialize stream @stream = stream @headers = HEADER_HASH.dup @body = '' end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
15 16 17 |
# File 'lib/h2/server/stream/request.rb', line 15 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
15 16 17 |
# File 'lib/h2/server/stream/request.rb', line 15 def headers @headers end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
15 16 17 |
# File 'lib/h2/server/stream/request.rb', line 15 def stream @stream end |
Instance Method Details
#addr ⇒ Object
retreive the IP address of the connection
25 26 27 |
# File 'lib/h2/server/stream/request.rb', line 25 def addr @addr ||= @stream.connection.socket.peeraddr[3] rescue nil end |
#authority ⇒ Object
retreive the authority from the stream request headers
31 32 33 |
# File 'lib/h2/server/stream/request.rb', line 31 def @authority ||= headers[AUTHORITY_KEY] end |
#method ⇒ Object
retreive the HTTP method as a lowercase Symbol
37 38 39 40 41 42 |
# File 'lib/h2/server/stream/request.rb', line 37 def method return @method unless @method.nil? @method = headers[METHOD_KEY] @method = @method.downcase.to_sym if @method @method end |
#path ⇒ Object
retreive the path from the stream request headers
46 47 48 49 50 |
# File 'lib/h2/server/stream/request.rb', line 46 def path return @path if defined?(@path) @path = headers[PATH_KEY] @path = @path.split('?').first if @path end |
#query_string ⇒ Object
retreive the query string from the stream request headers
54 55 56 57 58 59 |
# File 'lib/h2/server/stream/request.rb', line 54 def query_string return @query_string if defined?(@query_string) @query_string = headers[PATH_KEY].index '?' return if @query_string.nil? @query_string = headers[PATH_KEY][(@query_string + 1)..-1] end |
#respond(status:, headers: {}, body: '') ⇒ Object
respond to this request on its stream
69 70 71 |
# File 'lib/h2/server/stream/request.rb', line 69 def respond status:, headers: {}, body: '' @stream.respond status: status, headers: headers, body: body end |
#scheme ⇒ Object
retreive the scheme from the stream request headers
63 64 65 |
# File 'lib/h2/server/stream/request.rb', line 63 def scheme @scheme ||= headers[SCHEME_KEY] end |