mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-04 00:00:37 -04:00
introducing base_path option
This should complement the `:origin` option, in order to provide good defaults to build REST SDKs around of. Ex: ```ruby HTTPX.with(origin: "https://api.this-product.com", base_path: "/v3.1") ```
This commit is contained in:
parent
e3191f0d6c
commit
0d01f728aa
@ -132,6 +132,7 @@ module HTTPX
|
||||
def freeze
|
||||
super
|
||||
@origin.freeze
|
||||
@base_path.freeze
|
||||
@timeout.freeze
|
||||
@headers.freeze
|
||||
@addresses.freeze
|
||||
@ -141,6 +142,10 @@ module HTTPX
|
||||
URI(value)
|
||||
end
|
||||
|
||||
def option_base_path(value)
|
||||
String(value)
|
||||
end
|
||||
|
||||
def option_headers(value)
|
||||
Headers.new(value)
|
||||
end
|
||||
|
@ -49,7 +49,9 @@ module HTTPX
|
||||
origin = @options.origin
|
||||
raise(Error, "invalid URI: #{@uri}") unless origin
|
||||
|
||||
@uri = origin.merge(@uri)
|
||||
base_path = @options.base_path
|
||||
|
||||
@uri = origin.merge("#{base_path}#{@uri}")
|
||||
end
|
||||
|
||||
raise(Error, "unknown method: #{verb}") unless METHODS.include?(@verb)
|
||||
|
@ -20,6 +20,14 @@ module Requests
|
||||
verify_body_length(response)
|
||||
end
|
||||
|
||||
def test_http_get_option_origin_base_path
|
||||
status_uri = URI(build_uri("/status"))
|
||||
http = HTTPX.with(origin: status_uri.origin, base_path: status_uri.request_uri)
|
||||
response = http.get("/200")
|
||||
verify_status(response, 200)
|
||||
assert response.uri.request_uri == "#{status_uri.request_uri}/200"
|
||||
end
|
||||
|
||||
def test_http_request
|
||||
uri = build_uri("/get")
|
||||
response = HTTPX.request(:get, uri)
|
||||
|
Loading…
x
Reference in New Issue
Block a user