Class: Protocol::HTTP::Request
- Inherits:
-
Object
- Object
- Protocol::HTTP::Request
- Includes:
- Body::Reader
- Defined in:
- lib/protocol/http/request.rb
Instance Attribute Summary collapse
-
#authority ⇒ Object
The request authority, usually a hostname and port number.
-
#body ⇒ Object
The request body, an instance of Protocol::HTTP::Body::Readable or similar.
-
#headers ⇒ Object
The request headers, contains metadata associated with the request such as the user agent, accept (content type), accept-language, etc.
-
#method ⇒ Object
The request method, usually one of “GET”, “HEAD”, “POST”, “PUT”, “DELETE”, “CONNECT” or “OPTIONS”.
-
#path ⇒ Object
The request path, usually a path and query string.
-
#protocol ⇒ Object
The request protocol, usually empty, but occasionally “websocket” or “webtransport”, can be either single value ‘String` or multi-value `Array` of `String` instances.
-
#scheme ⇒ Object
The request scheme, usually one of “http” or “https”.
-
#version ⇒ Object
The request version, usually “http/1.0”, “http/1.1”, “h2”, or “h3”.
Class Method Summary collapse
Instance Method Summary collapse
-
#call(connection) ⇒ Object
Send the request to the given connection.
- #connect? ⇒ Boolean
- #head? ⇒ Boolean
- #idempotent? ⇒ Boolean
-
#initialize(scheme = nil, authority = nil, method = nil, path = nil, version = nil, headers = Headers.new, body = nil, protocol = nil) ⇒ Request
constructor
A new instance of Request.
- #to_s ⇒ Object
Methods included from Body::Reader
#body?, #close, #each, #finish, #read, #save
Constructor Details
#initialize(scheme = nil, authority = nil, method = nil, path = nil, version = nil, headers = Headers.new, body = nil, protocol = nil) ⇒ Request
Returns a new instance of Request.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/protocol/http/request.rb', line 17 def initialize(scheme = nil, = nil, method = nil, path = nil, version = nil, headers = Headers.new, body = nil, protocol = nil) @scheme = scheme @authority = @method = method @path = path @version = version @headers = headers @body = body @protocol = protocol end |
Instance Attribute Details
#authority ⇒ Object
The request authority, usually a hostname and port number.
32 33 34 |
# File 'lib/protocol/http/request.rb', line 32 def @authority end |
#body ⇒ Object
The request body, an instance of Protocol::HTTP::Body::Readable or similar.
47 48 49 |
# File 'lib/protocol/http/request.rb', line 47 def body @body end |
#headers ⇒ Object
The request headers, contains metadata associated with the request such as the user agent, accept (content type), accept-language, etc.
44 45 46 |
# File 'lib/protocol/http/request.rb', line 44 def headers @headers end |
#method ⇒ Object
The request method, usually one of “GET”, “HEAD”, “POST”, “PUT”, “DELETE”, “CONNECT” or “OPTIONS”.
35 36 37 |
# File 'lib/protocol/http/request.rb', line 35 def method @method end |
#path ⇒ Object
The request path, usually a path and query string.
38 39 40 |
# File 'lib/protocol/http/request.rb', line 38 def path @path end |
#protocol ⇒ Object
The request protocol, usually empty, but occasionally “websocket” or “webtransport”, can be either single value ‘String` or multi-value `Array` of `String` instances. In HTTP/1, it is used to request a connection upgrade, and in HTTP/2 it is used to indicate a specfic protocol for the stream.
50 51 52 |
# File 'lib/protocol/http/request.rb', line 50 def protocol @protocol end |
#scheme ⇒ Object
The request scheme, usually one of “http” or “https”.
29 30 31 |
# File 'lib/protocol/http/request.rb', line 29 def scheme @scheme end |
#version ⇒ Object
The request version, usually “http/1.0”, “http/1.1”, “h2”, or “h3”.
41 42 43 |
# File 'lib/protocol/http/request.rb', line 41 def version @version end |
Class Method Details
.[](method, path, headers = nil, body = nil) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/protocol/http/request.rb', line 65 def self.[](method, path, headers = nil, body = nil) body = Body::Buffered.wrap(body) headers = ::Protocol::HTTP::Headers[headers] self.new(nil, nil, method, path, nil, headers, body) end |
Instance Method Details
#call(connection) ⇒ Object
Send the request to the given connection.
53 54 55 |
# File 'lib/protocol/http/request.rb', line 53 def call(connection) connection.call(self) end |
#connect? ⇒ Boolean
61 62 63 |
# File 'lib/protocol/http/request.rb', line 61 def connect? @method == Methods::CONNECT end |
#head? ⇒ Boolean
57 58 59 |
# File 'lib/protocol/http/request.rb', line 57 def head? @method == Methods::HEAD end |
#idempotent? ⇒ Boolean
72 73 74 |
# File 'lib/protocol/http/request.rb', line 72 def idempotent? @method != Methods::POST && (@body.nil? || @body.empty?) end |
#to_s ⇒ Object
76 77 78 |
# File 'lib/protocol/http/request.rb', line 76 def to_s "#{@scheme}://#{@authority}: #{@method} #{@path} #{@version}" end |