MCPcopy
hub / github.com/httpie/cli / ensure_path_as_is

Function ensure_path_as_is

httpie/client.py:377–400  ·  view source on GitHub ↗

Handle `--path-as-is` by replacing the path component of the prepared URL with the path component from the original URL. Other parts stay untouched because other (welcome) processing on the URL might have taken place. <https://ec

(orig_url: str, prepped_url: str)

Source from the content-addressed store, hash-verified

375
376
377def ensure_path_as_is(orig_url: str, prepped_url: str) -> str:
378 """
379 Handle `--path-as-is` by replacing the path component of the prepared
380 URL with the path component from the original URL. Other parts stay
381 untouched because other (welcome) processing on the URL might have
382 taken place.
383
384 <https://github.com/httpie/cli/issues/895>
385
386
387 <https://ec.haxx.se/http/http-basics#path-as-is>
388 <https://curl.haxx.se/libcurl/c/CURLOPT_PATH_AS_IS.html>
389
390 >>> ensure_path_as_is('http://foo/../', 'http://foo/?foo=bar')
391 'http://foo/../?foo=bar'
392
393 """
394 parsed_orig, parsed_prepped = urlparse(orig_url), urlparse(prepped_url)
395 final_dict = {
396 # noinspection PyProtectedMember
397 **parsed_prepped._asdict(),
398 'path': parsed_orig.path,
399 }
400 return urlunparse(tuple(final_dict.values()))

Callers 1

collect_messagesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected