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.
-
#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
- #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.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/net-http2/request.rb', line 9 def initialize(method, uri, path, ={}) @method = method @uri = uri @path = path @body = [:body] @headers = [:headers] || {} @timeout = [:timeout] || DEFAULT_TIMEOUT @events = {} end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
7 8 9 |
# File 'lib/net-http2/request.rb', line 7 def body @body end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
7 8 9 |
# File 'lib/net-http2/request.rb', line 7 def method @method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/net-http2/request.rb', line 7 def path @path end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
7 8 9 |
# File 'lib/net-http2/request.rb', line 7 def timeout @timeout end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
7 8 9 |
# File 'lib/net-http2/request.rb', line 7 def uri @uri end |
Instance Method Details
#emit(event, arg) ⇒ Object
45 46 47 48 |
# File 'lib/net-http2/request.rb', line 45 def emit(event, arg) return unless @events[event] @events[event].each { |b| b.call(arg) } end |
#headers ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/net-http2/request.rb', line 20 def headers @headers.merge!({ ':scheme' => @uri.scheme, ':method' => @method.to_s.upcase, ':path' => @path, }) @headers.merge!('host' => @uri.host) unless @headers['host'] if @body @headers.merge!('content-length' => @body.bytesize.to_s) else @headers.delete('content-length') end @headers end |
#on(event, &block) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/net-http2/request.rb', line 38 def on(event, &block) raise ArgumentError, 'on event must provide a block' unless block_given? @events[event] ||= [] @events[event] << block end |