MCPcopy
hub / github.com/encode/httpx / _merge_url

Method _merge_url

httpx/_client.py:391–411  ·  view source on GitHub ↗

Merge a URL argument together with any 'base_url' on the client, to create the URL used for the outgoing request.

(self, url: URL | str)

Source from the content-addressed store, hash-verified

389 )
390
391 def _merge_url(self, url: URL | str) -> URL:
392 """
393 Merge a URL argument together with any 'base_url' on the client,
394 to create the URL used for the outgoing request.
395 """
396 merge_url = URL(url)
397 if merge_url.is_relative_url:
398 # To merge URLs we always append to the base URL. To get this
399 # behaviour correct we always ensure the base URL ends in a '/'
400 # separator, and strip any leading '/' from the merge URL.
401 #
402 # So, eg...
403 #
404 # >>> client = Client(base_url="https://www.example.com/subpath")
405 # >>> client.base_url
406 # URL('https://www.example.com/subpath/')
407 # >>> client.build_request("GET", "/path").url
408 # URL('https://www.example.com/subpath/path')
409 merge_raw_path = self.base_url.raw_path + merge_url.raw_path.lstrip(b"/")
410 return self.base_url.copy_with(raw_path=merge_raw_path)
411 return merge_url
412
413 def _merge_cookies(self, cookies: CookieTypes | None = None) -> CookieTypes | None:
414 """

Callers 1

build_requestMethod · 0.95

Calls 2

URLClass · 0.85
copy_withMethod · 0.45

Tested by

no test coverage detected