Class: NetHttp2::Request

Inherits:
Object
  • Object
show all
Includes:
Callbacks
Defined in:
lib/net-http2/request.rb

Constant Summary collapse

DEFAULT_TIMEOUT =
60

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Callbacks

#callback_events, #emit, #on

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, options={})
  @method  = method
  @uri     = uri
  @path    = path
  @params  = options[:params] || {}
  @body    = options[:body]
  @headers = options[:headers] || {}
  @timeout = options[:timeout] || DEFAULT_TIMEOUT

  @events = {}
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



11
12
13
# File 'lib/net-http2/request.rb', line 11

def body
  @body
end

#methodObject (readonly)

Returns the value of attribute method.



11
12
13
# File 'lib/net-http2/request.rb', line 11

def method
  @method
end

#paramsObject (readonly)

Returns the value of attribute params.



11
12
13
# File 'lib/net-http2/request.rb', line 11

def params
  @params
end

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/net-http2/request.rb', line 11

def path
  @path
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



11
12
13
# File 'lib/net-http2/request.rb', line 11

def timeout
  @timeout
end

#uriObject (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_pathObject



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

#headersObject



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