Commit Graph

2326 Commits

Author SHA1 Message Date
Eric Nieuwland
a9c669f17b
Forgotten slot
Crashes the server at __init__() time
2019-12-28 15:21:27 +01:00
Stephen Sadowski
075affec23
Release v19.12.0 (#1740)
* Bumping up version from 19.9.0 to 19.12.0

* Pipfile crud removed
2019-12-27 07:10:46 -06:00
Stephen Sadowski
3411a12c40 Pipfile crud removed 2019-12-26 18:50:52 -06:00
Stephen Sadowski
28899356c8 Bumping up version from 19.12.0 to 19.12.0 2019-12-26 18:47:56 -06:00
Eli Uriegas
2b5f8d20de ci: Add python nightlies to test matrix (#1710)
Signed-off-by: Eli Uriegas <seemethere101@gmail.com>
2019-12-25 16:50:31 -08:00
Adam Hopkins
243f240e5f Add RFC labels to stale exclusion list (#1737) 2019-12-23 17:31:33 -06:00
L. Kärkkäinen
0a25868a86 HTTP1 header formatting moved to headers.format_headers and rewritten. (#1669)
* HTTP1 header formatting moved to headers.format_headers and rewritten.

- New implementation is one line of code and twice faster than the old one.
- Whole header block encoded to UTF-8 in one pass.
- No longer supports custom encode method on header values.
- Cookie objects now have __str__ in addition to encode, to work with this.

* Add an import missed in merge.
2019-12-23 17:30:45 -06:00
Liran Nuna
fccbc1adc4 Allow empty body without Content-Type; Introduce response.empty() (#1736) 2019-12-23 14:16:53 -06:00
Adam Hopkins
3f6a978328 Swap out requests-async for httpx (#1728)
* Begin swap of requests-async for httpx

* Finalize httpx adoption and resolve tests

Resolve linting and formatting

* Remove documentation references to requests-async in favor of httpx
2019-12-20 19:23:52 -08:00
Harsha Narayana
a6077a1790 GIT-37: fix blueprint middleware application (#1690)
* GIT-37: fix blueprint middleware application

1. If you register a middleware via `@blueprint.middleware` then it will apply only to the routes defined by the blueprint.
2. If you register a middleware via `@blueprint_group.middleware` then it will apply to all blueprint based routes that are part of the group.
3. If you define a middleware via `@app.middleware` then it will be applied on all available routes

Fixes #37

Signed-off-by: Harsha Narayana <harsha2k4@gmail.com>

* GIT-37: add changelog

Signed-off-by: Harsha Narayana <harsha2k4@gmail.com>
2019-12-20 10:01:04 -06:00
Eli Uriegas
179a07942e
Merge pull request #1734 from seemethere/testing_host
testing: Add host argument to SanicTestClient
2019-12-18 16:50:59 -08:00
Eli Uriegas
c3aed01096
testing: Add host argument to SanicTestClient
Adds the ability to specify a host argument when using the
SanicTestClient.

Signed-off-by: Eli Uriegas <eliuriegas@fb.com>
2019-12-18 16:31:38 -08:00
7
028778ed56 Fix #1714 (#1716)
* fix abort call errors out when calling inside stream handler

* handle pending task properly after cleanup
2019-12-16 09:46:18 -06:00
Adam Bannister
2d72874b0b Add return type to Sanic.create_server for type hinting and docs (#1724)
* add type hint and doc when create_server returns AsyncioServer

* fix linting
2019-12-12 10:25:13 -06:00
Seonghyeon Kim
4c45d30400 FIX: invalid rst syntax (#1727) 2019-12-12 10:24:11 -06:00
Junyeong Jeong
ecbe5c839f pass request_buffer_queue_size argument to HttpProtocol (#1717)
* pass request_buffer_queue_size argument to HttpProtocol

* fix to use simultaneously only one task to put body to stream buffer

* add a test code for REQUEST_BUFFER_QUEUE_SIZE
2019-11-21 09:33:50 -06:00
Vinícius Dantas
ed1f367a8a Reduce nesting for the sample authentication decorator (#1715)
* Reduce nesting for the sample authentication decorator

* Add missing decorator argument
2019-11-14 14:57:41 -06:00
Lagicrus
a4185a0ba7 Doc rework (#1698)
* blueprints

* class_based_views

* config

* decorators

* deploying

* exceptions

* extensions

* getting_started

* middleware

* request_data

* response

* routing

* static_files

* streaming

* testing

* versioning

* Fix bug and links

* spelling mistakes

* Bug fixes and minor tweaks

* Create 1691.doc.rst

* Bug fixes and tweaks

Co-Authored-By: Harsha Narayana <harsha2k4@gmail.com>
2019-11-14 14:11:38 -06:00
Harsha Narayana
e81a8ce073 fix SERVER_NAME enforcement in url_for and request.args documentation (#1708)
* 🐛 fix SERVER_NAME enforcement in url_for

fixes #1707

* 💡 add additional documentation for using request.args

fixes #1704

*  add additional test to check url_for without SERVER_NAME

* 📝 add changelog for fixes
2019-11-01 10:32:49 -07:00
Harsha Narayana
e506c89304 deprecate None value support for app name (#1705)
*  deprecate None value support for app name

* 🚨 cleanup linter issues across the codebase
2019-10-23 09:12:20 -07:00
Bruno Oliveira
fcdc9c83c5 Add 'python_requires' key to setup.py (#1701)
This key is important so that `pip` doesn't try to install `sanic` in unsupported Python versions:

https://packaging.python.org/guides/distributing-packages-using-setuptools/#python-requires
2019-10-14 21:17:05 -07:00
7
be0d539746 19.9.0 release (#1699) 2019-10-12 09:54:47 -05:00
Lagicrus
4f9739ed2c Update helpers.py (#1693) 2019-10-08 16:29:03 -07:00
Lagicrus
0df37fa653 Update websocket.rst (#1694) 2019-10-08 16:28:09 -07:00
Eli Uriegas
3e932505b0
Bump up pytest version for fixing ci build (#1689)
Bump up pytest version for fixing ci build
2019-10-08 14:32:38 -07:00
Yun Xu
01be691936 misc: bump up pytest version for fixing ci build 2019-10-07 11:41:44 -07:00
Simon
134c414fe5 Support websockets 8.x as well as 7.x (#1687)
Sanic currently requires websockets 7.x, but it's straightforward to
also support the more recent 8.x.
2019-10-01 23:03:09 -07:00
L. Kärkkäinen
c54a8b10bb Implement dict-like API on request objects for custom data. (#1666)
* Implement dict-like API on request objects for custom data.
* Updated docs about custom_context.
2019-09-26 14:11:31 -07:00
Vinícius Dantas
6fc3381229 Add a type checking pipeline (#1682)
* Integrate with mypy
2019-09-22 13:55:36 -07:00
Ashley Sommer
927c0e082e Fix tests for multiprocessing pickle app and pickle blueprint (#1680)
The old tests were not quite checking for the right thing.
Fixing the test does not change Sanic code, expose any bugs, or fix any bugs.
2019-09-18 10:22:24 -07:00
Ashley Sommer
7674e917e4 Fixes "after_server_start" when using return_asyncio_server. (#1676)
* Fixes ability to trigger "after_server_start", "before_server_stop", "after_server_stop" server events when using app.create_server to start your own asyncio_server
See example file run_async_advanced for a full example

* Fix a missing method on AsyncServer that some tests need
Add a tiny bit more documentation in-code
Change name of AsyncServerCoro to AsyncioServer
2019-09-16 10:59:16 -07:00
ku-mu
e13f42c17b Fix docstring style in Sanic.register_listener (#1678)
* Fix docstring style: google -> reST
2019-09-16 10:27:22 -07:00
Lagicrus
b7d4121586 Update static_files.md (#1672) 2019-09-11 14:37:14 -07:00
L. Kärkkäinen
fbcd4b9767 Sanic does not support Python 3.5 and won't need this code. (#1670)
* imports code cleanup as we dropping python3.5 support
2019-09-08 14:08:34 -07:00
7
17c5e28727
Merge pull request #1665 from snguyenthanh/fix-changelog-link
doc: fix the link to CHANGELOG in README.rst
2019-09-06 11:07:41 -07:00
Son
e62b29ca44 Fix link to CHANGELOG in README.rst 2019-09-02 21:51:45 +08:00
L. Kärkkäinen
1e4b1c4d1a Forwarded headers and otherwise improved proxy handling (#1638)
* Added support for HTTP Forwarded header and combined parsing of other proxy headers.

- Accessible via request.forwarded that tries parse_forwarded and then parse_xforwarded
- parse_forwarded uses the Forwarded header, if config.FORWARDED_SECRET is provided and a matching header field is found
- parse_xforwarded uses X-Real-IP and X-Forwarded-* much alike the existing implementation
- This commit does not change existing request properties that still use the old code and won't make use of Forwarded headers.

* Use req.forwarded in req properties server_name, server_port, scheme and remote_addr.

X-Scheme handling moved to parse_xforwarded.

* Cleanup and fix req.server_port; no longer reports socket port if any forwards headers are used.

* Update docstrings to incidate that forwarded header is used first.

* Remove testing function.

* Fix tests and linting.

- One test removed due to change of semantics - no socket port will be used if any forwarded headers are in effect.
- Other tests augmented with X-Forwarded-For, to allow the header being tested take effect (shouldn't affect old implementation).

* Try to workaround buggy tools complaining about incorrect ordering of imports.

* Cleanup forwarded processing, add comments. secret is now also returned.

* Added tests, fixed quoted string handling, cleanup.

* Further tests for full coverage.

* Try'n make linter happy.

* Add support for multiple Forwarded headers. Unify parse_forwarded parameters with parse_xforwarded.

* Implement multiple headers support for X-Forwarded-For.

- Previously only the first header was used, so this BUGFIX may affect functionality.

* Bugfix for request.server_name: strip port and other parts.

- request.server_name docs claim that it returns the hostname only (no port).
- config.SERVER_NAME may be full URL, so strip scheme, port and path
- HTTP Host and consequently forwarded Host may include port number, so
  strip that also for forwarded hosts (previously only done for HTTP Host).
- Possible performance benefit of limiting to one split.

* Fallback to app.url_for and let it handle SERVER_NAME if defined (until a proper solution is implemented).

* Revise previous commit. Only fallback for full URL SERVER_NAMEs; allows host to be defined and proxied information still being used.

* Heil lintnazi.

* Modify testcase not to use underscores in URLs. Use hyphens which the spec allows for.

* Forwarded and Host header parsing improved.

- request.forwarded lowercases hosts, separates host:port into their own fields and lowercases addresses
- forwarded.parse_host helper function added and used for parsing all host-style headers (IPv6 cannot be simply split(":")).
- more tests fixed not to use underscores in hosts as those are no longer accepted and lead to the field being rejected

* Fixed typo in docstring.

* Added IPv6 address tests for Host header.

* Fix regex.

* Further tests and stricter forwarded handling.

* Fix merge commit

* Linter

* Linter

* Linter

* Add  to avoid re-using the  variable. Make a few raw strings non-raw.

* Remove unnecessary or

* Updated docs (work in progress).

* Enable REAL_IP_HEADER parsing irregardless of PROXIES_COUNT setting.

- Also cleanup and added comments

* New defaults for PROXIES_COUNT and REAL_IP_HEADER, updated tests.

* Remove support for PROXIES_COUNT=-1.

* Linter errors.

- This is getting ridiculous: cannot fit an URL on one line, linter requires
  splitting the string literal!

* Add support for by=_proxySecret, updated docs, updated tests.

* Forwarded headers' semantics tuning.

- Forwarded host is now preserved in original format
- request.host now returns a forwarded host if available, else the Host header
- Forwarded options are preserved in original order, and later keys override earlier ones
- Forwarded path is automatically URL-unquoted
- Forwarded 'by' and 'for' are omitted if their value is unknown
- Tests modified accordingly
- Cleanup and improved documentation

* Add ASGI test.

* Linter

* Linter #2
2019-09-02 08:50:56 -05:00
Subham Roy
ae91852cd5 check for already set asyncio event loop policy (#1637)
* check for already set asyncio event loop policy

* fix linting warning
2019-08-28 11:30:23 -05:00
L. Kärkkäinen
2011f3a0b2 PEP 594 has cgi module scheduled for deprecation in Python 3.8 (#1649)
* PEP 594 has cgi module scheduled for deprecation in Python 3.8. Reimplement
cgi.parse_header in Sanic. The new implementation is much faster than either
cgi.parse_header or equivalent werkzeug.parse_options_header, and unlike the
two, handles also quoted values with semicolons or \" in them.

* Fix string escape.

* Useless linter complaints.

* More linter issues

* Add return type hint.

* Do not support quoted-pair escapes.

- Improved documentation and renamed the function more aptly as it only seems
  to apply to content-type and content-disposition headers.

* Unquote filenames also in normal mode.

* Add tests for headers. Adapted from CPython parse_header tests with changes on the final test.

* Linter

* Revert "Unquote filenames also in normal mode."

This reverts commit bf0d502bcd.

* Improved parse_content_header and added tests with Firefox and Chrome.

- Unescaping of quotes moved to parse_content_header because it affects all fields,
  not just filenames.
- It is impossible to handle all cases correctly but the current heuristics should
  suffice well for typical cases and beyond.
- Added comparisons with cgi.parse_header and werkzeug.parse_options_header.

* Updated comments as well.
2019-08-27 08:30:23 -05:00
7
228a31ee0a
Merge pull request #1657 from huge-success/release-19.6.3
release: 19.6.3
2019-08-21 23:00:51 -07:00
Yun Xu
8bf2bdff74 Bumping up version from 19.6.2 to 19.6.3 2019-08-20 18:51:17 -07:00
7
41862eca61
Merge pull request #1654 from huge-success/asgi-content-type
Add content-type headers in response in ASGI mode
2019-08-13 12:30:40 -07:00
Yun Xu
21307b397b release: 19.6.3 2019-08-13 10:03:08 -07:00
7
3f9c94ba4a
Merge pull request #1635 from huge-success/upgrade-websockets
Upgrade websockets, resolve incompatible issue between multidict and websockets
2019-08-12 10:48:56 -07:00
Adam Hopkins
aa270d3ac2 Add content-type headers in response in ASGI mode 2019-08-11 11:29:08 +03:00
7
a15d9552c4
Merge pull request #1632 from harshanarayana/feature/GIT-1631-Enable_Towncrier
feature: GIT-1631 enable towncrier
2019-08-06 08:33:10 -07:00
7
2363c0653e
Merge pull request #1640 from Tronic/sockaddrfix
Fix server crash on request.server_port when bound to IPv6.
2019-07-25 00:10:56 -07:00
Harsha Narayana
651c98d19a
fix: #1631: add ignore file to ensure empty changelog dir is retained
Signed-off-by: Harsha Narayana <harsha2k4@gmail.com>
2019-07-24 05:39:20 +05:30
Harsha Narayana
c1a7e0e3cd
feat: #1631: enable change log as part of release script
Signed-off-by: Harsha Narayana <harsha2k4@gmail.com>
2019-07-24 05:32:00 +05:30
Harsha Narayana
80b32d0c71
feat: #1631: enable make command to support settings up release
Signed-off-by: Harsha Narayana <harsha2k4@gmail.com>
2019-07-24 05:03:04 +05:30