class H2::Server::Stream::Request

Constants

HEADER_HASH

a case-insensitive hash that also handles symbol translation i.e. s/_/-/

Attributes

body[R]
headers[R]
stream[R]

Public Class Methods

new(stream) click to toggle source
# File lib/h2/server/stream/request.rb, line 17
def initialize stream
  @stream  = stream
  @headers = HEADER_HASH.dup
  @body    = ''
end

Public Instance Methods

addr() click to toggle source

retreive the IP address of the connection

# File lib/h2/server/stream/request.rb, line 25
def addr
  @addr ||= @stream.connection.socket.peeraddr[3] rescue nil
end
authority() click to toggle source

retreive the authority from the stream request headers

# File lib/h2/server/stream/request.rb, line 31
def authority
  @authority ||= headers[AUTHORITY_KEY]
end
method() click to toggle source

retreive the HTTP method as a lowercase Symbol

# File lib/h2/server/stream/request.rb, line 37
def method
  return @method if defined? @method
  @method = headers[METHOD_KEY]
  @method = @method.downcase.to_sym if @method
  @method
end
path() click to toggle source

retreive the path from the stream request headers

# 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() click to toggle source

retreive the query string from the stream request headers

# 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: {}) click to toggle source

respond to this request on its stream

# File lib/h2/server/stream/request.rb, line 69
def respond status:, headers: {}, body: ''
  @stream.respond status: status, headers: headers, body: body
end
scheme() click to toggle source

retreive the scheme from the stream request headers

# File lib/h2/server/stream/request.rb, line 63
def scheme
  @scheme ||= headers[SCHEME_KEY]
end