Class: Wsv::Request
- Inherits:
-
Object
- Object
- Wsv::Request
- 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
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #head? ⇒ Boolean
-
#initialize(method:, target:, version:, headers:) ⇒ Request
constructor
A new instance of Request.
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
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
19 20 21 |
# File 'lib/wsv/request.rb', line 19 def headers @headers end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
19 20 21 |
# File 'lib/wsv/request.rb', line 19 def method @method end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
19 20 21 |
# File 'lib/wsv/request.rb', line 19 def target @target end |
#version ⇒ Object (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
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
28 29 30 |
# File 'lib/wsv/request.rb', line 28 def head? method == "HEAD" end |