Metadata-Version: 2.4
Name: wpr-http
Version: 0.2.1
Summary: Standalone HTTP client using version-selected Firefox Necko/NSS Workers
License: MPL-2.0-compatible client; see runtime bundle notices
Project-URL: Repository, https://github.com/childclm/wpr-http
Project-URL: Documentation, https://github.com/childclm/wpr-http/blob/main/README.md
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: wpr-runtime-core<0.3,>=0.2.3

# WPR HTTP

Standalone HTTP requests using real, version-selected Firefox Necko/NSS network
Workers. Installing this package does not install the WPR browser client.
The native runtime is downloaded separately and remains centrally built.

```python
import asyncio
from wpr_http import AsyncClient

async def main():
    async with AsyncClient(firefox_version="155") as client:
        response = await client.get("https://www.baidu.com/")
        async with response:
            response.raise_for_status()
            print(response.status_code, await response.atext())

asyncio.run(main())
```

`firefox_version` selects a genuine installed Gecko network engine, not a
User-Agent string or a simulated browser. Only Firefox 155 is currently built
and supported. Selecting another version raises an explicit compatibility error;
it never silently uses 155. Different installed engine versions use separate
runtime/profile locations and separate Worker processes.

Runtime installation and supported versions:

```powershell
python -m wpr_http runtimes
python -m wpr_http install-runtime --version 155
```

An explicit `runtime_home` can select another verified runtime installation.
Existing `AsyncWprHttpClient`, Request/Response/Timeout and exception names remain
available. `WprHttpClient` remains the historical asynchronous alias.

The native network runtime is a separate download from the private
`childclm/gecko-web-runtime` Release. Installation needs access to that repository. Set
`WPR_GITHUB_TOKEN` or `GH_TOKEN`, or use Git Credential Manager, then run
`python -m wpr_http install-runtime --version 155`.
# Per-request Fetch Metadata policy

`header_policy="native"` is the backward-compatible default. Gecko generates
Fetch Metadata from the native Channel context and may overwrite explicit
`Sec-Fetch-*` headers. To preserve explicit metadata in the standalone HTTP
transport, use:

```python
response = await client.get(
    "https://example.com/api",
    headers={"Sec-Fetch-Mode": "cors", "Sec-Fetch-Site": "cross-site"},
    header_policy="passthrough",
)
```

The policy can also be a client default and overridden per request. It is
stored on prepared `Request` objects. Passthrough requires the native
`network_header_passthrough` capability; older Workers raise
`RuntimeCompatibilityError` before the request is sent.

Passthrough suppresses automatic Fetch Metadata generation for that network
Channel. Explicit `Sec-Fetch-*` fields survive redirects. Omitted metadata is
not invented. This is semantic header preservation, not byte-for-byte HTTP
replay: Host, Content-Length, HTTP/2 normalization and Gecko's credential,
Cookie and redirect rules remain in effect. In particular this option does
not restore Authorization or arbitrary sensitive headers on redirects. It
does not turn the request into page `fetch()` or enable CORS preflight.
Browser/page Workers retain Firefox's native behavior; no global preference
or upstream SecFetch implementation is changed.

This requires Network Runtime 155.0.9 or later; the Python change alone does
not update an installed binary. Upgrade both components:

```powershell
uv pip install --upgrade wpr-http
python -m wpr_http install-runtime --version 155
```

`wpr-runtime-core` 0.2.3 selects network and browser defaults independently:
network 155.0.9, browser 155.0.8. An explicitly pinned older runtime stays
pinned and raises a compatibility error for passthrough requests.
