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

Method _merge_url

httpx/_client.py:391–411  ·  httpx/_client.py::BaseClient._merge_url

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 class="st">"""
393 Merge a URL argument together with any &class="cm">#x27;base_url' on the client,
394 to create the URL used for the outgoing request.
395 class="st">"""
396 merge_url = URL(url)
397 if merge_url.is_relative_url:
398 class="cm"># To merge URLs we always append to the base URL. To get this
399 class="cm"># behaviour correct we always ensure the base URL ends in a class="st">'/'
400 class="cm"># separator, and strip any leading class="st">'/' from the merge URL.
401 class="cm">#
402 class="cm"># So, eg...
403 class="cm">#
404 class="cm"># >>> client = Client(base_url=class="st">"https://www.example.com/subpath")
405 class="cm"># >>> client.base_url
406 class="cm"># URL(class="st">'https://www.example.com/subpath/')
407 class="cm"># >>> client.build_request(class="st">"GET", class="st">"/path").url
408 class="cm"># URL(class="st">'https://www.example.com/subpath/path')
409 merge_raw_path = self.base_url.raw_path + merge_url.raw_path.lstrip(bclass="st">"/")
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 class="st">"""

Callers 1

build_requestMethod · 0.95

Calls 2

URLClass · 0.85
copy_withMethod · 0.45

Tested by

no test coverage detected