Class: NetHttp2::Request
- Inherits:
-
Object
- Object
- NetHttp2::Request
- 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
- #emit(event, arg) ⇒ Object
- #full_path ⇒ Object
- #headers ⇒ Object
-
#initialize(method, uri, path, options = {}) ⇒ Request
constructor
A new instance of Request.
- #on(event, &block) ⇒ Object
Constructor Details
#initialize(method, uri, path, options = {}) ⇒ Request
Returns a new instance of Request.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/net-http2/request.rb', line 11 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.
9 10 11 |
# File 'lib/net-http2/request.rb', line 9 def body @body end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
9 10 11 |
# File 'lib/net-http2/request.rb', line 9 def method @method end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
9 10 11 |
# File 'lib/net-http2/request.rb', line 9 def params @params end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/net-http2/request.rb', line 9 def path @path end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
9 10 11 |
# File 'lib/net-http2/request.rb', line 9 def timeout @timeout end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
9 10 11 |
# File 'lib/net-http2/request.rb', line 9 def uri @uri end |
Instance Method Details
#emit(event, arg) ⇒ Object
54 55 56 57 |
# File 'lib/net-http2/request.rb', line 54 def emit(event, arg) return unless @events[event] @events[event].each { |b| b.call(arg) } end |
#full_path ⇒ Object
41 42 43 44 45 |
# File 'lib/net-http2/request.rb', line 41 def full_path path = @path path += "?#{to_query(@params)}" unless @params.empty? path end |
#headers ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/net-http2/request.rb', line 23 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.to_s) else @headers.delete('content-length') end @headers end |
#on(event, &block) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/net-http2/request.rb', line 47 def on(event, &block) raise ArgumentError, 'on event must provide a block' unless block_given? @events[event] ||= [] @events[event] << block end |