Class: NetHttp2::Request
- Inherits:
-
Object
- Object
- NetHttp2::Request
- Includes:
- Callbacks
- Defined in:
- lib/net-http2/request.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
60
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #full_path ⇒ Object
- #headers ⇒ Object
-
#initialize(method, uri, path, options = {}) ⇒ Request
constructor
A new instance of Request.
Methods included from Callbacks
Constructor Details
#initialize(method, uri, path, options = {}) ⇒ Request
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/net-http2/request.rb', line 13 def initialize(method, uri, path, ={}) @method = method @uri = uri @path = path @params = [:params] || {} @body = [:body] @headers = [:headers] || {} @timeout = [:timeout] || DEFAULT_TIMEOUT @events = {} end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
11 12 13 |
# File 'lib/net-http2/request.rb', line 11 def body @body end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
11 12 13 |
# File 'lib/net-http2/request.rb', line 11 def method @method end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
11 12 13 |
# File 'lib/net-http2/request.rb', line 11 def params @params end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/net-http2/request.rb', line 11 def path @path end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
11 12 13 |
# File 'lib/net-http2/request.rb', line 11 def timeout @timeout end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
11 12 13 |
# File 'lib/net-http2/request.rb', line 11 def uri @uri end |
Instance Method Details
#full_path ⇒ Object
46 47 48 49 50 |
# File 'lib/net-http2/request.rb', line 46 def full_path path = @path path += "?#{to_query(@params)}" unless @params.empty? path end |
#headers ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/net-http2/request.rb', line 25 def headers @headers.merge!({ ':scheme' => @uri.scheme, ':method' => @method.to_s.upcase, ':path' => full_path, }) @headers.merge!(':authority' => "#{@uri.host}:#{@uri.port}") unless @headers[':authority'] if @body @headers.merge!('content-length' => @body.bytesize) else @headers.delete('content-length') end @headers.update(@headers) { |_k, v| v.to_s } # see <https://github.com/ostinelli/apnotic/issues/68> @headers.sort.to_h end |