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

Function main

httpx/_main.py:452–506  ·  httpx/_main.py::main

An HTTP command line client. Sends a request and displays the response.

(
    url: str,
    method: str,
    params: list[tuple[str, str]],
    content: str,
    data: list[tuple[str, str]],
    files: list[tuple[str, click.File]],
    json: str,
    headers: list[tuple[str, str]],
    cookies: list[tuple[str, str]],
    auth: tuple[str, str] | None,
    proxy: str,
    timeout: float,
    follow_redirects: bool,
    verify: bool,
    http2: bool,
    download: typing.BinaryIO | None,
    verbose: bool,
)

Source from the content-addressed store, hash-verified

450 help=class="st">"Show this message and exit.",
451)
452def main(
453 url: str,
454 method: str,
455 params: list[tuple[str, str]],
456 content: str,
457 data: list[tuple[str, str]],
458 files: list[tuple[str, click.File]],
459 json: str,
460 headers: list[tuple[str, str]],
461 cookies: list[tuple[str, str]],
462 auth: tuple[str, str] | None,
463 proxy: str,
464 timeout: float,
465 follow_redirects: bool,
466 verify: bool,
467 http2: bool,
468 download: typing.BinaryIO | None,
469 verbose: bool,
470) -> None:
471 class="st">"""
472 An HTTP command line client.
473 Sends a request and displays the response.
474 class="st">"""
475 if not method:
476 method = class="st">"POST" if content or data or files or json else class="st">"GET"
477
478 try:
479 with Client(proxy=proxy, timeout=timeout, http2=http2, verify=verify) as client:
480 with client.stream(
481 method,
482 url,
483 params=list(params),
484 content=content,
485 data=dict(data),
486 files=files, class="cm"># type: ignore
487 json=json,
488 headers=headers,
489 cookies=dict(cookies),
490 auth=auth,
491 follow_redirects=follow_redirects,
492 extensions={class="st">"trace": functools.partial(trace, verbose=verbose)},
493 ) as response:
494 if download is not None:
495 download_response(response, download)
496 else:
497 response.read()
498 if response.content:
499 print_response(response)
500
501 except RequestError as exc:
502 console = rich.console.Console()
503 console.print(fclass="st">"[red]{type(exc).__name__}[/red]: {exc}")
504 sys.exit(1)
505
506 sys.exit(0 if response.is_success else 1)

Callers

nothing calls this directly

Calls 5

ClientClass · 0.85
download_responseFunction · 0.85
print_responseFunction · 0.85
streamMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected