* Make all new connections start in IDLE stage, and switch to REQUEST stage only once any bytes are received from client. This makes new connections without any request obey keepalive timeout rather than request timeout like they currently do.
* Revert typo
* Remove request timeout endpoint test which is no longer working (still tested by mocking). Fix mock timeout test setup.
Co-authored-by: L. Karkkainen <tronic@users.noreply.github.com>
* Initial work on restructure of application state
* Updated MOTD with more flexible input and add basic version
* Remove unnecessary type ignores
* Add wrapping and smarter output per process type
* Add support for ASGI MOTD
* Add Windows color support ernable
* Refactor __main__ into submodule
* Renest arguments
* Passing unit tests
* Passing unit tests
* Typing
* Fix num worker test
* Add context to assert failure
* Add some type annotations
* Some linting
* Line aware searching in test
* Test abstractions
* Fix some flappy tests
* Bump up timeout on CLI tests
* Change test for no access logs on gunicornworker
* Add some basic test converage
* Some new tests, and disallow workers and fast on app.run
* Initial support for using multiple SSL certificates.
* Also list IP address subjectAltNames on log.
* Use Python 3.7+ way of specifying TLSv1.2 as the minimum version. Linter fixes.
* isort
* Cleanup, store server name for later use. Add RSA ciphers. Log rejected SNIs.
* Cleanup, linter.
* Alter the order of initial log messages and handling. In particular, enable debug mode early so that debug messages during init can be shown.
* Store server name (SNI) to conn_info.
* Update test with new error message.
* Refactor for readability.
* Cleanup
* Replace old expired test cert with new ones and a script for regenerating them as needed.
* Refactor TLS tests to a separate file.
* Add cryptography to dev deps for rebuilding TLS certs.
* Minor adjustment to messages.
* Tests added for new TLS code.
* Find the correct log row before testing for message. The order was different on CI.
* More log message order fixup. The tests do not account for the logo being printed first.
* Another attempt at log message indexing fixup.
* Major TLS refactoring.
CertSelector now allows dicts and SSLContext within its list.
Server names are stored even when no list is used.
SSLContext.sanic now contains a dict with any setting passed and information extracted from cert.
That information is available on request.conn_info.cert.
Type annotations added.
More tests incl. a handler for faking hostname in tests.
* Remove a problematic logger test that apparently was not adding any coverage or value to anything.
* Revert accidental commit of uvloop disable.
* Typing fixes / refactoring.
* Additional test for cert selection. Certs recreated without DNS:localhost on sanic.example cert.
* Add tests for single certificate path shorthand and SNI information.
* Move TLS dict processing to CertSimple, make the names field optional and use names from the cert if absent.
* Sanic CLI options --tls and --tls-strict-host to use the new features.
* SSL argument typing updated
* Use ValueError for internal message passing to avoid CertificateError's odd message formatting.
* Linter
* Test CLI TLS options.
* Maybe the right codeclimate option now...
* Improved TLS argument help, removed support for combining --cert/--key with --tls.
* Removed support for strict checking without any certs, black forced fscked up formatting.
* Update CLI tests for stricter TLS options.
Co-authored-by: L. Karkkainen <tronic@users.noreply.github.com>
Co-authored-by: Adam Hopkins <admhpkns@gmail.com>
* Add ability to log all exceptions
* Fix linting 🙄
* Remove shorthand
* Make `ErrorHandler.log` backwards-compat
* Ignore mypy error
* Don't store `noisy_exceptions` attribute in app
* Added tests
* Store noisy exceptions setting in config
* Default to not-noisy if config key not available
* Add CLI tests for `noisy-exceptions`
* Remove debugging line I left in 😅
* Fix tests
Co-authored-by: Adam Hopkins <admhpkns@gmail.com>
* fix ipv6 display in startup info log
* refactored to oneliner by request
* Added test for passing ipv4 host
* Added test for passing ipv6 any host
* Added test for passing ipv6 loopback host
* Smarter auto fallback
* remove config from blueprints
* Add tests for error formatting
* Add check for proper format
* Fix some tests
* Add some tests
* docstring
* Add accept matching
* Add some more tests on matching
* Fix contains bug, earlier return on MediaType eq
* Add matching flags for wildcards
* Add mathing controls to accept
* Cleanup dev cruft
* Add cleanup and resolve OSError relating to test implementation
* Fix test
* Fix some typos
* First attempt at new Websockets implementation based on websockets >= 9.0, with sans-i/o features. Requires more work.
* Update sanic/websocket.py
Co-authored-by: Adam Hopkins <adam@amhopkins.com>
* Update sanic/websocket.py
Co-authored-by: Adam Hopkins <adam@amhopkins.com>
* Update sanic/websocket.py
Co-authored-by: Adam Hopkins <adam@amhopkins.com>
* wip, update websockets code to new Sans/IO API
* Refactored new websockets impl into own modules
Incorporated other suggestions made by team
* Another round of work on the new websockets impl
* Added websocket_timeout support (matching previous/legacy support)
* Lots more comments
* Incorporated suggested changes from previous round of review
* Changed RuntimeError usage to ServerError
* Changed SanicException usage to ServerError
* Removed some redundant asserts
* Change remaining asserts to ServerErrors
* Fixed some timeout handling issues
* Fixed websocket.close() handling, and made it more robust
* Made auto_close task smarter and more error-resilient
* Made fail_connection routine smarter and more error-resilient
* Further new websockets impl fixes
* Update compatibility with Websockets v10
* Track server connection state in a more precise way
* Try to handle the shutdown process more gracefully
* Add a new end_connection() helper, to use as an alterative to close() or fail_connection()
* Kill the auto-close task and keepalive-timeout task when sanic is shutdown
* Deprecate WEBSOCKET_READ_LIMIT and WEBSOCKET_WRITE_LIMIT configs, they are not used in this implementation.
* Change a warning message to debug level
Remove default values for deprecated websocket parameters
* Fix flake8 errors
* Fix a couple of missed failing tests
* remove websocket bench from examples
* Integrate suggestions from code reviews
Use Optional[T] instead of union[T,None]
Fix mypy type logic errors
change "is not None" to truthy checks where appropriate
change "is None" to falsy checks were appropriate
Add more debug logging when debug mode is on
Change to using sanic.logger for debug logging rather than error_logger.
* Fix long line lengths of debug messages
Add some new debug messages when websocket IO is paused and unpaused for flow control
Fix websocket example to use app.static()
* remove unused import in websocket example app
* re-run isort after Flake8 fixes
Co-authored-by: Adam Hopkins <adam@amhopkins.com>
Co-authored-by: Adam Hopkins <admhpkns@gmail.com>
* Explicit static directive for serving file or dir
Co-authored-by: anbuhckr <36891836+anbuhckr@users.noreply.github.com>
Co-authored-by: anbuhckr <miki.suhendra@gmail.com>
* Add some tests
* docstring
* Add accept matching
* Add some more tests on matching
* Add matching flags for wildcards
* Add mathing controls to accept
* Limit uvicorn 14 in testing
* Update some tests
* Resolve#2122 route decorator returning tuple
* Use rc sanic-routing version
* Update unit tests to <:str>
* Minimal working version with some signals implemented
* Add more http signals
* Update ASGI and change listeners to signals
* Allow for dynamic ODE signals
* Allow signals to be stacked
* Begin tests
* Prioritize match_info on keyword argument injection
* WIP on tests
* Compat with signals
* Work through some test coverage
* Passing tests
* Post linting
* Setup proper resets
* coverage reporting
* Fixes from vltr comments
* clear delayed tasks
* Fix bad test
* rm pycache
@cansarigol3megawatt Thanks for looking into this and getting the quick turnaround on this. I will 🍒 pick this into the 21.6 branch and get it out a little later tonight.
* Clean up after a request is complete, before the next pipelined request.
* Limit the size of request body consumed after handler has finished.
* Linter error.
* Add unit test re: bad headers
Co-authored-by: L. Kärkkäinen <tronic@users.noreply.github.com>
Co-authored-by: Adam Hopkins <admhpkns@gmail.com>
Co-authored-by: Adam Hopkins <adam@amhopkins.com>
* Fix the handling of the end of a chunked request.
* Avoid hardcoding final chunk header size.
* Add some unit tests for pipeline body reading
* Decode bytes for json serialization
Co-authored-by: L. Kärkkäinen <tronic@users.noreply.github.com>
Co-authored-by: Adam Hopkins <adam@amhopkins.com>
* Remove duplicated dependencies
* Specify setuptools as the tool for generating distribution (PEP 517)
* Add `isort` to `dev_require`
* manage all dependencies in setup.py
* Execute `make pretty`
* Set usedevelop to true (revert previous change)
* Added new client_ip accessor for ConnInfo class, updated request to use client_ip instead of client to be more representative of what will be returned (actual ipv6 ip instead of bracket wrapped ip)
* Fix ConnInfo init
* add ipv6 test - maybe will work?
* fixed silly indentation error
* Bump testing client
* Extend testing
* Fix text
Co-authored-by: Adam Hopkins <adam@amhopkins.com>
Co-authored-by: Adam Hopkins <admhpkns@gmail.com>
* Small improvements to CLI experience
* Add tests
* Add test server for cli testing
* Add LOGO logging to reloader and some additional context to logging debug
* Cleanup tests
* Deprecate `load_env` in favor of `env_prefix`
`load_env` both enabled/disabled environment variable parsing, while
also letting the user modify the env prefix. Deprecate the ability to
disable environment parsing, and add a new config variable to track the
user's desired prefix for environment-based configuration.
Resolves: #2102
* Add a few common .gitignore patterns
* GIT-2023: Enable GitHub Actions support
* GIT-2023: fix tox runtime trigger
* GIT-2023: add top level action name
* GIT-2023: rename tox step name
* GIT-2023: rename build task names
* GIT-2023: remove macos and windows + nightly versions
* GIT-2023: add macos and windows back to os matrix
* GIT-2023: expermiental flag to conditionally skip failure
* GIT-2023: enable using custom actions
* GIT-2023: fix matrix config rendering type
* GIT-2023: fix naming issue with os label
* GIT-2023: enable type-checking env for tox
* GIT-2023: enable pypy3.7 support
* GIT-2023: enable pypy experimental flag
* GIT-2023: add pypy tox env config
* add max timeout of 5 min for pypy tests
* GIT-2023: add timeout for each actions
* GIT-2023: fix codeQL workflow actions
* GIT-2023: limit test matrix to ubuntu and support on demand
* GIT-2023: enable docker image publish on release
* GIT-2023: fix on-demand pypy action
* GIT-2023: enable pypi publish workflow
* GIT-2023: enable verbose logs for py3.9
* GIT-2023: reduce py3.9 verbosity
* GIT-2023: enable docs linter
* GIT-2023: extend test matrix to include macos + windows
* GIT-2023: move windows based workflow to standalone task
* GIT-2023: fix windows test matrix
* GIT-2023: mark py39-no-ext as flaky test
* GIT-2023: mark flaky test
* GIT-2023: make timeout internal to steps for ease of management
* GIT-2023: rename image publish step name
* GIT-2023: mark keep alive client timeout for linux only
* GIT-2023: enable retries on test failure
Co-authored-by: Adam Hopkins <admhpkns@gmail.com>
* fixing static request handler logging exception when not necessary, adding test to verify exception is gone on 404
* Fixup tests
* Fix tests
* resolve test failure
Co-authored-by: Adam Hopkins <admhpkns@gmail.com>
* fix?: recursion error on Sanic subclass init
* tests: add test case for sanic subclass initialisation
* Remove BaseSanic metaclass
Co-authored-by: Adam Hopkins <admhpkns@gmail.com>
* Temp working version of initial signal api
* fix signals router finalizing
* Additional tests
* Add event test
* finalize test
* remove old comment
* Add some missing annotations
* multiple apps per BP support
* deepsource?
* rtemove deepsource
* nominal change
* fix blueprints test
* trivial change to trigger build
* signal docstring
* squash
* squash
* Add a couple new tests
* Add some suggestions from review
* Remove inaccessible code
* Change where to condition
* GIT-2045: enable versioning and strict slash on BlueprintGroup
* GIT-2045: convert named tuple into typed format + unit tests
* GIT-2045: add example code for versioned bpg
* GIT-2045: None value for strict slashes check
* GIT-2045: refactor handler types and add benchmark for urlparse
* GIT-2045: reduce urlparse benchmark iterations
* GIT-2045: add unit test and url merge behavior
* GIT-2045: cleanup example code and remove print
* GIT-2045: add test for slash duplication avoidence
* GIT-2045: fix issue with tailing / getting appended
* GIT-2045: use Optional instead of Union for Typing
* GIT-2045: use string for version arg
* GIT-2045: combine optional with union
* Add trailing slash when defined and strict_slashes
* Add partial matching, and fix some issues with url_for
* Cover additional edge cases
* cleanup tests
* Allow Pathlib Path objects to be passed to the app.static file endpoint register helper.
* fixed import sort
* Raise error if static file path is not an accepted object type
Added more tests to improve coverage on the new type checks.
* Streaming request by async for.
* Make all requests streaming and preload body for non-streaming handlers.
* Cleanup of code and avoid mixing streaming responses.
* Async http protocol loop.
* Change of test: don't require early bad request error but only after CRLF-CRLF.
* Add back streaming requests.
* Rewritten request body parser.
* Misc. cleanup, down to 4 failing tests.
* All tests OK.
* Entirely remove request body queue.
* Let black f*ckup the layout
* Better testing error messages on protocol errors.
* Remove StreamBuffer tests because the type is about to be removed.
* Remove tests using the deprecated get_headers function that can no longer be supported. Chunked mode is now autodetected, so do not put content-length header if chunked mode is preferred.
* Major refactoring of HTTP protocol handling (new module http.py added), all requests made streaming. A few compatibility issues and a lot of cleanup to be done remain, 16 tests failing.
* Terminate check_timeouts once connection_task finishes.
* Code cleanup, 14 tests failing.
* Much cleanup, 12 failing...
* Even more cleanup and error checking, 8 failing tests.
* Remove keep-alive header from responses. First of all, it should say timeout=<value> which wasn't the case with existing implementation, and secondly none of the other web servers I tried include this header.
* Everything but CustomServer OK.
* Linter
* Disable custom protocol test
* Remove unnecessary variables, optimise performance.
* A test was missing that body_init/body_push/body_finish are never called. Rewritten using receive_body and case switching to make it fail if bypassed.
* Minor fixes.
* Remove unused code.
* Py 3.8 check for deprecated loop argument.
* Fix a middleware cancellation handling test with py38.
* Linter 'n fixes
* Typing
* Stricter handling of request header size
* More specific error messages on Payload Too Large.
* Init http.response = None
* Messages further tuned.
* Always try to consume request body, plus minor cleanup.
* Add a missing check in case of close_if_idle on a dead connection.
* Avoid error messages on PayloadTooLarge.
* Add test for new API.
* json takes str, not bytes
* Default to no maximum request size for streaming handlers.
* Fix chunked mode crash.
* Header values should be strictly ASCII but both UTF-8 and Latin-1 exist. Use UTF-8B to
cope with all.
* Refactoring and cleanup.
* Unify response header processing of ASGI and asyncio modes.
* Avoid special handling of StreamingHTTPResponse.
* 35 % speedup in HTTP/1.1 response formatting (not so much overall effect).
* Duplicate set-cookie headers were being produced.
* Cleanup processed_headers some more.
* Linting
* Import ordering
* Response middleware ran by async request.respond().
* Need to check if transport is closing to avoid getting stuck in sending loops after peer has disconnected.
* Middleware and error handling refactoring.
* Linter
* Fix tracking of HTTP stage when writing to transport fails.
* Add clarifying comment
* Add a check for request body functions and a test for NotImplementedError.
* Linter and typing
* These must be tuples + hack mypy warnings away.
* New streaming test and minor fixes.
* Constant receive buffer size.
* 256 KiB send and receive buffers.
* Revert "256 KiB send and receive buffers."
This reverts commit abc1e3edb2.
* app.handle_exception already sends the response.
* Improved handling of errors during request.
* An odd hack to avoid an httpx limitation that causes test failures.
* Limit request header size to 8 KiB at most.
* Remove unnecessary use of format string.
* Cleanup tests
* Remove artifact
* Fix type checking
* Mark test for skipping
* Cleanup some edge cases
* Add ignore_body flag to safe methods
* Add unit tests for timeout logic
* Add unit tests for timeout logic
* Fix Mock usage in timeout test
* Change logging test to only logger in handler
* Windows py3.8 logging issue with current testing client
* Add test_header_size_exceeded
* Resolve merge conflicts
* Add request middleware to hard exception handling
* Add request middleware to hard exception handling
* Request middleware on exception handlers
* Linting
* Cleanup deprecations
Co-authored-by: L. Kärkkäinen <tronic@users.noreply.github.com>
Co-authored-by: Adam Hopkins <admhpkns@gmail.com>
In ASGI-mode, don't do sanic-side response chunk encoding, leave that to the ASGI-response-transport
Don't set content-length when using chunked-encoding in ASGI mode, this is incompatible with ASGI Chunked Transport-Encoding.
* Ignore writing headers when in ASGI mode for streaming responses
* Move asgi set on streaming until after response type check
* Adds multidict==5.0.0 to pass tests
* Bump version to 20.9.1
This allows blueprint registration to add the bp's static routes to its list of own routes. So now blueprint middlewares will apply to a blueprint's static file routes.
Fixes#1953
* feat: fixes exception due to unread bytes in stream
* feat: additonal unit tests to cover changes
* fix: automated changes by `make fix-import`
* fix: additonal changes by `make fix-import`
Co-authored-by: Adam Hopkins <admhpkns@gmail.com>
* Added fix to include subprotocols from scope
* Added unit test to validate fix
* Changes by black
* Made changes to WebsocketConnection protocol
* Linter changes
* Added unit tests
* Fixing bugs in linting due to isort import checks
* Reverting compat import changes
* Fixing linter errors in compat.py
Co-authored-by: Adam Hopkins <admhpkns@gmail.com>