fix: preview() works without a running loop; set_cookie honors path when domain=None
preview()'s default cookie lookup reached the backend session and could force-
build it, raising RuntimeError('no running event loop') off-loop and defeating
the v0.1.7 lazy-session pre-loop use case; it's now skipped when the session
isn't built yet. set_cookie(domain=None) returned before setting the morsel's
path, so a shared cookie always stored path='/' regardless of the path= arg;
the morsel path is now set before that early return.
Signed-off-by: disqualifier <dev@disqualifier.me>
This commit is contained in:
@@ -11,18 +11,18 @@ and swap the HTTP client while inheriting everything else.
|
||||
`requirements.txt`:
|
||||
|
||||
```
|
||||
aioweb @ git+ssh://git@git.rethinkstudios.io/rethink-public/aioweb.git@v0.1.10
|
||||
aioweb @ git+ssh://git@git.rethinkstudios.io/rethink-public/aioweb.git@v0.1.11
|
||||
```
|
||||
|
||||
Direct:
|
||||
|
||||
```bash
|
||||
pip install "aioweb @ git+ssh://git@git.rethinkstudios.io/rethink-public/aioweb.git@v0.1.10"
|
||||
pip install "aioweb @ git+ssh://git@git.rethinkstudios.io/rethink-public/aioweb.git@v0.1.11"
|
||||
```
|
||||
|
||||
Requires `aiohttp` and `yarl` (pulled transitively).
|
||||
|
||||
Drop the `@v0.1.10` suffix from the line above to install the latest unpinned.
|
||||
Drop the `@v0.1.11` suffix from the line above to install the latest unpinned.
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -97,10 +97,15 @@ s.overwrite_domain("internal.local", "127.0.0.1") # host-substring rewrite
|
||||
print(s.preview("POST", url, json={"a": 1}).as_curl()) # equivalent cURL command
|
||||
```
|
||||
|
||||
`as_curl()` renders `params` (merged into the url's query string) and `timeout` (as
|
||||
`--max-time`) as well as headers/body/proxy, so the emitted command is faithful to what
|
||||
`request()` actually sends. Pass `debug=True` to `request_with_retries` to log the cURL
|
||||
preview and request flow.
|
||||
`preview()` is synchronous and never touches the backend session — it works before any
|
||||
event loop is running (e.g. building a preview at import/setup time), not just inside
|
||||
`asyncio.run()`. Its default cookie lookup only reads cookies from an already-built
|
||||
session; if the session hasn't been built yet there are no cookies to read, so it
|
||||
returns none by default (pass `cookies=` explicitly to preview cookies for a session
|
||||
that hasn't sent a request yet). `as_curl()` renders `params` (merged into the url's
|
||||
query string) and `timeout` (as `--max-time`) as well as headers/body/proxy, so the
|
||||
emitted command is faithful to what `request()` actually sends. Pass `debug=True` to
|
||||
`request_with_retries` to log the cURL preview and request flow.
|
||||
|
||||
## Custom backends
|
||||
|
||||
@@ -144,6 +149,23 @@ Two changes can't be shimmed without re-introducing the bugs they fix:
|
||||
|
||||
## Changelog
|
||||
|
||||
### v0.1.11
|
||||
|
||||
- **`preview()` no longer requires a running event loop.** Its default cookie
|
||||
lookup (`cookies=` not passed) previously called `_cookies_for_url()`, which
|
||||
reached the backend session and built it if absent — under aiohttp>=3.14 that
|
||||
needs a running loop, so `preview()` raised `RuntimeError('no running event
|
||||
loop')` when called before the loop starts, defeating its own pre-loop
|
||||
build/inspect use case (v0.1.7). Now the default cookie lookup is skipped
|
||||
entirely when the session hasn't been built yet (nothing could have been set
|
||||
on a session that doesn't exist); `cookies={}` and in-loop calls are unaffected.
|
||||
- **`set_cookie(domain=None)` now honors `path`.** The `domain=None` branch
|
||||
returned right after `update_cookies()`, before the line that sets the
|
||||
morsel's `path` — so a shared cookie (`set_cookie(name, value, path="/api")`,
|
||||
no `domain=`) always stored the `SimpleCookie` default `path="/"` instead. The
|
||||
morsel's `path` is now set before the `domain=None` early return. The
|
||||
domain-bound branch was already correct and is unchanged.
|
||||
|
||||
### v0.1.10
|
||||
|
||||
- Docs-only pass: compressed module/method docstrings and comments that restated
|
||||
|
||||
Reference in New Issue
Block a user