Commit Graph

775 Commits

Author SHA1 Message Date
Andrey Sobolev d0989bc852
Fix readme for ChannelBox package (#1188)
Fix domain name
2021-05-26 09:15:39 +01:00
Tom Christie 54e6ed38de
Update README.md (#1185)
Drop defunct "community" link, since we're just using GitHub "discussions" now.
2021-05-25 11:35:18 +01:00
Jamie Hewland d26f44b4ae
Use non-deprecated jinja2.pass_context in Jinja 3.0+ (#1183) 2021-05-13 15:11:14 +01:00
Yurii Karabas b7aeae70fd
Add better exception msg for duplicated param names (#1177) 2021-05-04 10:36:16 +01:00
hitrust 1a51dfabf7
Update authentication.md (#1165)
import 'Starlette'

Co-authored-by: Joe <nigelchiang@outlook.com>
2021-04-28 17:42:02 +08:00
Shahriyar Rzayev f58c4c22ed
Removed the empty elif clause as it has no effect (#1168)
Co-authored-by: Joe <nigelchiang@outlook.com>
2021-04-28 17:35:01 +08:00
Shahriyar Rzayev 89ab6756a2
Removed redundant parantheses as returning with comma will return tuple (#1171)
Co-authored-by: Joe <nigelchiang@outlook.com>
2021-04-28 17:28:54 +08:00
Shahriyar Rzayev f934a65ace
Replaced mutable default argument with None to eliminate anti-pattern (#1173)
Co-authored-by: Joe <nigelchiang@outlook.com>
2021-04-28 17:24:42 +08:00
Shahriyar Rzayev a4f4dff732
Replaced built-in type name with type_ as it may shadow the global scope; removed redundant variable assignment (#1174) 2021-04-28 17:20:14 +08:00
wim glenn 4750e7b613
prevent setup from generating an incorrect top_level.txt file in the wheel distribution (#1166) 2021-04-21 09:29:35 +01:00
Ben Falk f997938916
use quote instead of quote_plus for RedirectResponse location header (#1164)
* use quote instead of quote_plus for RedirectResponse location header

adjust safe characters: rem. duplicate & symbol

add test for redirect quoting

* remove unused import

Co-authored-by: Jamie Hewland <jhewland@gmail.com>
2021-04-14 20:14:53 +01:00
Josh Wilson 995d70c7c6
Set explicit Origin in CORS preflight response if allow_credentials is True and allow_origins is wildcard (#1113)
* Set explicit Origin in CORS preflight response if allow_credentials is True and allow_origins is wildcard

When making a preflight request, the browser makes no indication as to whether the actual subsequent
request will pass up credentials. However, unless the preflight response explicitly allows the
request's `Origin` in the `Access-Control-Response-Header`, the browser will fail the CORS check and
prevent the actual follow-up CORS request. This means that responding with the `*` wildcard is not
sufficient to allow preflighted credentialed requests. The current workaround is to provide an
equivalently permissive `allow_origin_regex` pattern.

The `simple_response()` code already performs similar logic which currently only applies to
non-preflighted requests since the browser would never make a preflighted request that hits this
code due to this issue:

```
if self.allow_all_origins and has_cookie:
    headers["Access-Control-Allow-Origin"] = origin
```

This just bring the two halves inline with each other.

* Add Vary header to preflight response if allow_credentials

* Use allow_explicit_origin() for preflight request_headers

This simplifies the code slightly by using this recently added method.

It has some trade-offs, though. We now construct a `MutableHeaders` instead of a simple `dict` when
copying the pre-computed preflight headers, and we move the `Vary` header construction out of the
pre-computation and into the call handler.

I think it makes the code more maintainable and the added per-call computation is minimal.

* Convert MutableHeaders to dict for PlainTextResponse

* Revert back to dict() for preflight headers

This also names and caches some of the boolean tests in __init__() which we use in later if-blocks.
This follows the existing pattern in order to better self-document the code.

* Clean up comments

* Remove unused self.allow_credentials attribute
2021-04-14 20:10:20 +01:00
Josh Wilson f5ecb53895
Add HEAD to CORS ALL_METHODS list (#1112)
* Add HEAD to CORS ALL_METHODS list

The HEAD method is conspicuously absent from the allowed methods list when `allow_methods="*"` is
used. This doesn't really affect CORS preflight requests, as HEAD requests aren't preflighted by the
browser, but it does prevent the actual cross-origin HEAD response from being read by the calling
app.
[This can catch people off-guard.](https://discuss.encode.io/t/for-cors-middleware-why-is-head-not-included-in-all-methods/939)

This simply adds HEAD to the `ALL_METHODS` list in the CORS middleware module and includes some
additional tests to validate the new behavior.

* Update tests/middleware/test_cors.py to use more explicit status code check

Co-authored-by: euri10 <euri10@users.noreply.github.com>

Co-authored-by: euri10 <euri10@users.noreply.github.com>
Co-authored-by: Jamie Hewland <jhewland@gmail.com>
2021-04-06 21:38:48 +01:00
Josh Wilson 602212613c
Add Origin to Vary header on credentialed CORS response (#1111)
* Add Origin to Vary header on credentialed CORS response

According to the [MDN CORS docs]
(https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#Access-Control-Allow-Origin), the `Origin`
item should be added to the `Vary` header when the `Access-Control-Allow-Origin` is set to an
explicit origin value, as opposed to the `*` wildcard.

>If the server specifies a single origin (that may dynamically change based on the requesting origin
as part of a white-list) rather than the "*" wildcard, then the server should also include Origin in
the Vary response header — to indicate to clients that server responses will differ based on the
value of the Origin request header.

The existing code fails to update the `Vary` list when the server is configured to allow all
origins (`*`) and the request has a `Cookie` header (ie. credentialed). In that situation, the
`Access-Control-Allow-Origin` header will be set to the request's `Origin` value.

It appears this may have just been a simple oversight in the original implementation. This updates
the code to add `Origin` to the `Vary` header under these circumstancesIf it was intentionally
omitted, I'd be delighted to learn why.

* Add type annotations

* Add test to ensure that the vary header does not contain origin if request is non-credentialed
2021-04-06 21:36:41 +01:00
oTree-org 1222e78a15
Don't use 'raise exc from None' because it suppresses exception causes (#1158)
Co-authored-by: oTree-org <chris@otree.org>
2021-03-29 16:02:22 +01:00
Mahmoud Hossam 5ee04ef9b1
Make session cookie use ASGI root path (#1147)
* Make session cookie use ASGI root path

* Check if ASGI root_path exists before using it

Co-authored-by: Tom Christie <tom@tomchristie.com>

* Remove comment

* Add test

Co-authored-by: Mahmoud Hanafy <mahmoud.hanafy@retresco.de>
Co-authored-by: Tom Christie <tom@tomchristie.com>
2021-03-12 12:49:52 +00:00
Jamie Hewland 23e15789bf
Fix docs syntax highlighting (#1136)
* mkdocs: Use python-markdown-extensions syntax highlighter

* mkdocs: Use 2-space indent consistently in config file
2021-02-07 19:06:30 +00:00
ilunev 0ac60bbeb2
StaticFiles: Fix cache validation bug for deleted files in html mode (#1023)
* StaticFiles: Fix cache validation bug for deleted files in html mode

Previously StaticFiles would return 304 for a deleted file if its
Last-Modified date was the same as that of 404.html

* Use black formatter

Co-authored-by: Jamie Hewland <jhewland@gmail.com>
2021-02-05 20:15:25 +00:00
Jamie Hewland 32745944b0
Deprecate built-in GraphQL support (#1135)
* Deprecate GraphQLApp

* Add deprecation warning to pytest ignore list

* Tweak deprecation warnings
2021-02-05 19:13:39 +00:00
Jamie Hewland ea1990415e
Version 0.14.2 (#1133)
* Prepare version 0.14.2

* Tweak changelog: Changed -> Fixed
2021-02-02 20:10:02 +00:00
John Bampton ed73b97c9b
Fix spelling (#1115)
Co-authored-by: Jamie Hewland <jhewland@gmail.com>
2021-02-02 11:13:59 +00:00
Tim Gates b48b80f41e
docs: fix simple typo, ougoging -> outgoing (#1120)
There is a small typo in starlette/middleware/gzip.py.

Should read `outgoing` rather than `ougoging`.

Co-authored-by: Jamie Hewland <jhewland@gmail.com>
2021-02-02 11:09:29 +00:00
Denis Eliseev 2b83c8cea6
Remove self from websocker example app (#1103)
Co-authored-by: Jamie Hewland <jhewland@gmail.com>
2021-02-02 11:01:03 +00:00
Vlad Stefan Munteanu fe908b1c29
Fix functools.partial async handlers for classmethods (#1106)
* Showcase the bug

* Fixed functools.partial usage with classmethods

* Updated comment

* Updated docstring according to suggestion

Co-authored-by: Jamie Hewland <jhewland@gmail.com>

Co-authored-by: Jamie Hewland <jhewland@gmail.com>
2021-02-02 10:30:30 +00:00
Jamie Hewland 62e95b89fc
Fix middleware traceback fetching on Python 3.8+, fix ResourceWarnings in TestClient, fix CI build (#1132)
* Add __init__ file for tests.middleware so Mypy 0.800 is happy

* testclient: Tie loop lifetime to thread

* ServerErrorMiddleware: Don't use undocumented TracebackException.exc_traceback attribute
2021-01-31 12:43:07 +01:00
Roman e4307065ea
Add missing status codes (#1096) 2020-11-23 17:06:26 +01:00
Roman 029882ee88
Add 208 Already Reported status code (#1095) 2020-11-20 10:18:39 +01:00
Jamie Hewland 71443747ae
Version 0.14.1 (#1088)
* Prepare version 0.14.1

* Add link to docs about custom JSON serialization

* Bump release date

* Add link to PR removing UJSONResponse
2020-11-09 17:15:31 +02:00
Jamie Hewland 99b37781eb
Remove UJSONResponse (#1047)
* Remove UJSONResponse

* Add documentation about custom JSON serialization
2020-11-08 22:49:12 +02:00
Erik 8bfc2a3c26
Version 0.14.0 (#1087)
* Version 0.14.0 release preparation: write release-notes and version bump.
2020-11-08 11:50:12 -08:00
Vlad Stefan Munteanu fe961dd22c
Allow usage of functools.partial async handlers (#984)
* Allow usage of async partial methods

* Added test for partial async endpoint

* Double quotes vs single quotes

* Support multiple levels of partials, check Python < 3.8

* Skip coverage for py3.8 branch

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
2020-11-07 17:33:11 -08:00
Parzival 7a783d3b0e
Update responses.md (#1080)
Small grammar correction.
2020-10-28 14:55:53 +02:00
manuelzander 5193cdb55b
Add 418 I'm A Teapot status code (#1076) 2020-10-22 17:15:48 +02:00
witling a9f8821f3b
fix 793: allow custom async iterator (#1041)
* fix 793

* custom async generator: implement pr notes

* custom async generator: cleanup dependencies

* update tests

* newline at end of tests

* fix linting

* Update tests/test_responses.py

Co-authored-by: Jamie Hewland <jhewland@gmail.com>

* Update tests/test_responses.py

Co-authored-by: Jamie Hewland <jhewland@gmail.com>

* fix naming for custom generator tests

* comply with pep 492

* Shift streaming tests to be in one place

Co-authored-by: witling <noreply@my.email>
Co-authored-by: Jamie Hewland <jhewland@gmail.com>
2020-10-21 20:10:30 +02:00
Jeff Astor c300bdc5b8
Friendly spell check in `routing.md` docs. (#1073)
Co-authored-by: Jamie Hewland <jhewland@gmail.com>
2020-10-15 11:23:52 +01:00
Moriyoshi Koizumi 192ac4e988
Add type: ignore for aiofiles to make mypy happier (#1072)
* Add type: ignore to make mypy happier

* Tentatively ignore type checking failure until the following patch gets merged

https://github.com/python/typeshed/pull/4650
2020-10-14 22:51:28 +02:00
Jamie Hewland c08aefca69
Test on Python 3.9 (#1068)
* Test on Python 3.9

* Update trove classifiers
2020-10-07 21:58:59 +02:00
Jamie Hewland bfa61ad92b
Create tasks from coroutines before providing to asyncio.wait (#1066) 2020-10-07 21:20:55 +02:00
Andrey Semakin b3271a53b0
Fix return value of TestClient's __enter__ method (#1064) 2020-10-02 09:53:40 +01:00
Thomas Grainger 8dac5c2c7c
apply pyupgrade --py36-plus (#1048) 2020-09-27 19:47:51 +01:00
Jamie Hewland 41218ac546
Move lifespan tests out of obsolete middleware test module (#1055)
* Move lifespan tests out of obsolete middleware test module

* Add test_lifespan_async
2020-09-11 15:26:55 +02:00
Elliana May faea6c290a
Use format_exception instead of format_tb (#1031)
* Use format_exception instead of format_tb

This gives much more information about the exception, including causes, and the exception message itself, in addition to the trackback

* Update test

Co-authored-by: Jamie Hewland <jhewland@gmail.com>
2020-09-11 13:15:50 +02:00
Thomas Grainger b043fe56bc
configure pytest to be stricter (#1040)
* fix tests/test_datastructures::TestUploadFile PytestCollectionWarning

enhance pytest strictness to catch warnings that would have prevented
thest TestUploadFile file warning

restore cov-report and require 100% coverage

* Apply suggestions from code review

Co-authored-by: Jamie Hewland <jhewland@gmail.com>

* remove cov-fail-under

* Apply suggestions from code review

Co-authored-by: Jamie Hewland <jhewland@gmail.com>

* Apply suggestions from code review

Co-authored-by: Jamie Hewland <jhewland@gmail.com>

* Update setup.cfg

Co-authored-by: Jamie Hewland <jhewland@gmail.com>

Co-authored-by: Jamie Hewland <jhewland@gmail.com>
2020-09-11 11:19:47 +02:00
Jamie Hewland 7113ee8dc4
Add issue templates (#1054) 2020-09-10 21:30:52 +02:00
Jamie Hewland 46be17f7c6
Run coverage check in CI (#1051)
* Run coverage check in CI

* Use the same step name as httpx
2020-09-08 08:54:55 +02:00
Thomas Grainger aa85713d82
allow black to pass on v20.8b1 and v19.10b0 (#1049)
by running black v19.3b0 (we miss you) and then running black v20.8b1
2020-09-07 09:19:20 +02:00
Jamie Hewland b95acea973
Update CI scripts to match httpcore (#1043)
* Update CI scripts to match httpcore

* Run test suite on pushes to master

* Update scripts README

* Don't bother with flake8 extensions for now

* Remove unnecessary PYTHONPATH from build, publish

* test_routing: Use a stub app instead of ellipsis

* Add link to issue about type-checking tests
2020-09-06 12:08:07 +02:00
Jamie Hewland 8729e9fc69
Use and pin black 20 (#1042) 2020-09-05 15:16:56 +02:00
Hannes Küttner c566fc6c81
Be more lenient with route arguments in AuthencationMiddleware 'requires' decorator (#942) 2020-08-16 07:24:23 -07:00
Erik 061853550f
Install dependencies before attempting to publish. (#1030) 2020-08-14 20:52:58 -07:00