Class: Zapp::HTTPContext::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/zapp/http_context/request.rb

Overview

Represents an HTTP Request to be processed by a worker

Constant Summary collapse

PARSER_THREAD_HASH_KEY =

Request parsing is done threaded, but not in separate Ractors. So we allocate an HTTP parser per thread and assign it to this hash key in Thread.current

"PUMA_PARSER_INSTANCE"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(socket:) ⇒ Request

Returns a new instance of Request.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/zapp/http_context/request.rb', line 13

def initialize(socket:)
  # Max Request size of 8KB TODO: Make a config value for this setting
  @raw = socket.readpartial(8192)
  @data = {}

  parser.execute(data, raw, 0)

  @body = Zapp::InputStream.new(string: parser.body)

  parser.reset
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/zapp/http_context/request.rb', line 7

def body
  @body
end

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/zapp/http_context/request.rb', line 7

def data
  @data
end

#rawObject (readonly)

Returns the value of attribute raw.



7
8
9
# File 'lib/zapp/http_context/request.rb', line 7

def raw
  @raw
end

Instance Method Details

#parserObject



25
26
27
# File 'lib/zapp/http_context/request.rb', line 25

def parser
  Thread.current[PARSER_THREAD_HASH_KEY] ||= Puma::HttpParser.new
end