Class: Fluent::PluginHelper::HttpServer::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin_helper/http_server/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Request

Returns a new instance of Request.



27
28
29
30
31
# File 'lib/fluent/plugin_helper/http_server/request.rb', line 27

def initialize(request)
  @request = request
  path = request.path
  @path, @query_string = path.split('?', 2)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



25
26
27
# File 'lib/fluent/plugin_helper/http_server/request.rb', line 25

def path
  @path
end

#query_stringObject (readonly)

Returns the value of attribute query_string.



25
26
27
# File 'lib/fluent/plugin_helper/http_server/request.rb', line 25

def query_string
  @query_string
end

Instance Method Details

#bodyObject



47
48
49
# File 'lib/fluent/plugin_helper/http_server/request.rb', line 47

def body
  @request.body&.read
end

#headersObject



33
34
35
# File 'lib/fluent/plugin_helper/http_server/request.rb', line 33

def headers
  @request.headers
end

#queryObject



37
38
39
40
41
42
43
44
45
# File 'lib/fluent/plugin_helper/http_server/request.rb', line 37

def query
  if @query_string
    hash = Hash.new { |h, k| h[k] = [] }
    # For compatibility with CGI.parse
    URI.decode_www_form(@query_string).each_with_object(hash) do |(key, value), h|
      h[key] << value
    end
  end
end