Class: URI::HTTP

Inherits:
Generic show all
Defined in:
lib/uri/query_params/core_ext/uri/http.rb

Instance Attribute Summary

Attributes included from QueryParams::Mixin

#query_params

Instance Method Summary collapse

Methods inherited from Generic

#to_s

Methods included from QueryParams::Mixin

#each_query_param, included, #initialize_copy

Instance Method Details

#raw_request_uriObject



10
# File 'lib/uri/query_params/core_ext/uri/http.rb', line 10

alias raw_request_uri request_uri

#request_uriString?

Returns the full path for an HTTP request.

Examples:

uri.path = '/path'
uri.query_params['foo'] = '1'
uri.query_params['bar'] = '2'
uri.request_uri
# => "/path?foo=1&bar=2"

Returns:

  • (String, nil)

    The request URI (path + query params) or nil if the URI has no path.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/uri/query_params/core_ext/uri/http.rb', line 26

def request_uri
  if defined?(@query_params) && @query_params
    return unless @path

    query = URI::QueryParams.dump(@query_params)

    url = "#{@path}?#{query}"
    url = "/#{url}" unless url.start_with?('/')
    url
  else
    raw_request_uri
  end
end