Repository navigation
Set and delete cookies with all of Starlette's options through ViewSetResult (0.14.1) - #73
Merged
Merged
Conversation
✅ Incremental coverage — 100%
11 files not graded (4 ignored by pattern, 7 not source files)
Coverage reports: coverage.json (coverage.py, 69 files) · coverage/clover.xml (clover, 13 files) — incremental-coverage-check v3.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ViewSetResultsets and deletes cookies with every option of Starlette'sResponse.set_cookie()/Response.delete_cookie(), so an action or a command middleware sets anHttpOnly,Secure,SameSitesessioncookie with a
Max-Age, and deletes it, without putting it into the body and withoutmodifies_response_shape.Changes
Cookie(value, max_age, expires, path, domain, secure, httponly, samesite, partitioned)andDeleteCookie(path, domain, secure, httponly, samesite)infastapi_viewsets.middleware: dataclasses withStarlette's parameters and defaults,
SerializableObjects.ViewSetResult.set_cookie()/ViewSetResult.delete_cookie()with the signatures of the Starlette methods; theystore a
Cookie/DeleteCookieinViewSetResult.cookies. Any other value incookiesis set asstr(value)with Starlette's defaults, as before.apply_cookies(response, cookies)applies them with Starlette's ownset_cookie()/delete_cookie(); thelifecycle runner uses it.
partitionedis passed on only whenTrue.ViewSetResult.__serialize__/__deserialize__and thecelery_viewsetresult transport carryCookie/DeleteCookiewith all options (expiresasdatetime, number or string keeps its type).cookiesvalues, the two methods, a login/logout session-cookieexample, and that
status_code/headers/cookiesdo not change the response shape; howroute_viewsetdecidesto drop the
response_model(global list, read at decoration, every route of the class; instances injected by@action_configurationnot consulted). The muxws guide states that reply headers hold the last value of a repeatedheader. Docstrings updated accordingly.
Tests
OpenAPI schema kept; headers compared with what Starlette's own
Responseproduces for the same arguments.set-cookiein the reply headers for a set and a deletion.worker_e2e_test.py).expirestype.