Sha256: 3b2b54e506adb1061763cea5ed2b962ec7cb21ec7224f80e62ac8b732e54e797

Contents?: true

Size: 831 Bytes

Versions: 1

Compression:

Stored size: 831 Bytes

Contents

# frozen_string_literal: true

require_relative 'generic'

require 'uri/http'

module URI
  class HTTP < Generic

    alias raw_request_uri request_uri

    #
    # Returns the full path for an HTTP request.
    #
    # @return [String, nil]
    #   The request URI (path + query params) or `nil` if the URI has no
    #   path.
    #
    # @example
    #   uri.path = '/path'
    #   uri.query_params['foo'] = '1'
    #   uri.query_params['bar'] = '2'
    #   uri.request_uri
    #   # => "/path?foo=1&bar=2"
    #
    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

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
uri-query_params-0.8.2 lib/uri/query_params/core_ext/uri/http.rb