Class: Wsv::Request

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

Defined Under Namespace

Classes: TooLarge

Constant Summary collapse

REQUEST_LINE_LIMIT =
8192
HEADER_LINE_LIMIT =
8192
HEADER_COUNT_LIMIT =
100
HEADER_TOTAL_LIMIT =
16384

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method:, target:, version:, headers:) ⇒ Request

Returns a new instance of Request.



21
22
23
24
25
26
# File 'lib/wsv/request.rb', line 21

def initialize(method:, target:, version:, headers:)
  @method = method
  @target = target
  @version = version
  @headers = headers
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



19
20
21
# File 'lib/wsv/request.rb', line 19

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.



19
20
21
# File 'lib/wsv/request.rb', line 19

def method
  @method
end

#targetObject (readonly)

Returns the value of attribute target.



19
20
21
# File 'lib/wsv/request.rb', line 19

def target
  @target
end

#versionObject (readonly)

Returns the value of attribute version.



19
20
21
# File 'lib/wsv/request.rb', line 19

def version
  @version
end

Class Method Details

.parse(io) ⇒ Object

Raises:



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/wsv/request.rb', line 32

def self.parse(io)
  line = io.gets(REQUEST_LINE_LIMIT)
  return :empty unless line
  raise TooLarge, 414 if line.bytesize >= REQUEST_LINE_LIMIT && !line.end_with?("\n")

  method, target, version = line.split(/\s+/, 3)
  version = version&.strip
  return :malformed unless method && target && version&.start_with?("HTTP/")

  headers = read_headers(io)
  new(method: method, target: target, version: version, headers: headers)
end

Instance Method Details

#head?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/wsv/request.rb', line 28

def head?
  method == "HEAD"
end