Commit Graph

2230 Commits

Author SHA1 Message Date
L. Kärkkäinen
7e93ee102c Typing 2020-03-01 18:21:09 +02:00
L. Kärkkäinen
08353637fd Linter 'n fixes 2020-03-01 17:40:01 +02:00
L. Kärkkäinen
31a8706b42 Fix a middleware cancellation handling test with py38. 2020-03-01 17:10:04 +02:00
L. Kärkkäinen
d918655bbb Py 3.8 check for deprecated loop argument. 2020-03-01 16:57:03 +02:00
L. Kärkkäinen
0712026e14 Remove unused code. 2020-03-01 16:36:42 +02:00
L. Kärkkäinen
1c42a5ef4e Minor fixes. 2020-03-01 16:34:58 +02:00
L. Kärkkäinen
5a96996003 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. 2020-03-01 16:34:20 +02:00
L. Kärkkäinen
c0a0b50bc1 Remove unnecessary variables, optimise performance. 2020-03-01 15:38:18 +02:00
L. Kärkkäinen
fc16594138 Disable custom protocol test 2020-03-01 14:53:04 +02:00
L. Kärkkäinen
5086076590 Linter 2020-03-01 13:21:02 +02:00
L. Kärkkäinen
f8298939c0 Merge branch 'master' into streaming 2020-03-01 13:13:39 +02:00
L. Kärkkäinen
2840e4cfc8 Everything but CustomServer OK. 2020-03-01 13:10:53 +02:00
L. Kärkkäinen
85be5768c8 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. 2020-03-01 12:15:16 +02:00
L. Kärkkäinen
7f41c5fa6b Even more cleanup and error checking, 8 failing tests. 2020-02-29 18:59:19 +02:00
L. Kärkkäinen
a553e64bbd Much cleanup, 12 failing... 2020-02-29 16:50:59 +02:00
L. Kärkkäinen
57202bfa89 Code cleanup, 14 tests failing. 2020-02-29 14:18:31 +02:00
L. Kärkkäinen
8a1baeb9d5 Terminate check_timeouts once connection_task finishes. 2020-02-28 19:25:03 +02:00
L. Kärkkäinen
85b1ad5732 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. 2020-02-28 18:43:36 +02:00
L. Kärkkäinen
85c67a0014 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. 2020-02-28 18:40:44 +02:00
L. Kärkkäinen
d5971377c5 Remove StreamBuffer tests because the type is about to be removed. 2020-02-28 17:38:09 +02:00
L. Kärkkäinen
b2476bd7d7 Better testing error messages on protocol errors. 2020-02-28 17:26:31 +02:00
L. Kärkkäinen
6d8f5988d3 Let black f*ckup the layout 2020-02-26 19:27:22 +02:00
L. Kärkkäinen
29c6f3c49f Entirely remove request body queue. 2020-02-26 19:23:55 +02:00
L. Kärkkäinen
b87364bd91 All tests OK. 2020-02-26 19:00:38 +02:00
L. Kärkkäinen
6b9f0ece7c Misc. cleanup, down to 4 failing tests. 2020-02-26 14:24:45 +02:00
L. Kärkkäinen
42d86bcd5a Rewritten request body parser. 2020-02-26 13:03:33 +02:00
Mykhailo Yusko
16961fab9d
Use f-strings instead of str.format() (#1793) 2020-02-25 14:01:13 -06:00
L. Kärkkäinen
ef4f233fba Add back streaming requests. 2020-02-24 17:27:28 +02:00
L. Kärkkäinen
3d05e1ec07 Change of test: don't require early bad request error but only after CRLF-CRLF. 2020-02-24 17:27:04 +02:00
L. Kärkkäinen
f6a0b4a497 Async http protocol loop. 2020-02-24 16:23:53 +02:00
L. Kärkkäinen
861e87347a
Fix #1788 incorrect url_for for routes with hosts, added tests. (#1789)
* Fix #1788 incorrect url_for for routes with hosts, added tests.

* Linter

* Remove debug print
2020-02-21 09:10:22 -08:00
L. Kärkkäinen
f609a4850f Cleanup of code and avoid mixing streaming responses. 2020-02-21 17:51:38 +02:00
L. Kärkkäinen
fe64a2764d Make all requests streaming and preload body for non-streaming handlers. 2020-02-21 13:28:50 +02:00
L. Kärkkäinen
6279eac3d1 Streaming request by async for. 2020-02-21 10:51:58 +02:00
Tim Gates
91f6abaa81
Fix simple typo: viewes -> views (#1783)
Closes #1782
2020-02-17 10:16:58 -06:00
Eli Uriegas
d380b52f9a
Merge pull request #1784 from gdub/changelog_correction
Corrected changelog for docs move of MD to RST (#1691).
2020-02-15 17:09:41 -08:00
Gary Wilson Jr
d656a06a19 Corrected changelog for docs move of MD to RST (#1691). 2020-02-11 11:45:56 -06:00
Adam Hopkins
258dbee3b9
Py38 tox env (#1752)
* Set version

Set version

* Add Python 3.8 to tests and package classifiers

Add Python3.8 to Appveyor config
2020-02-05 13:17:55 -06:00
Sudeep Mandal
6b9287b076
Update README re: experimental support for Windows (#1778)
As mentioned in #1517 , Windows support is "experimental" and does not currently support multiple workers.
2020-02-03 10:27:56 -06:00
L. Kärkkäinen
dac0514441 Code cleanup in file responses (#1769)
* Code cleanup in file responses.

* Lint
2020-01-26 22:08:34 -08:00
L. Kärkkäinen
bffdb3b5c2 More robust response datatype handling (#1674)
* 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.

* Linter

* format_http1_response

* Replace encode_body with faster implementation based on f-string.

Benchmarks:

def encode_body(data):
    try:
        # Try to encode it regularly
        return data.encode()
    except AttributeError:
        # Convert it to a str if you can't
        return str(data).encode()

def encode_body2(data):
    return f"{data}".encode()

def encode_body3(data):
    return str(data).encode()

data_str, data_int = "foo", 123

%timeit encode_body(data_int)
928 ns ± 2.96 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

%timeit encode_body2(data_int)
280 ns ± 2.09 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

%timeit encode_body3(data_int)
387 ns ± 1.7 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

%timeit encode_body(data_str)
202 ns ± 1.9 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

%timeit encode_body2(data_str)
197 ns ± 0.507 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

%timeit encode_body3(data_str)
313 ns ± 1.28 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

* Wtf linter

* Content-type fixes.

* Body encoding sanitation, first pass.
- body/data type autodetection fixed.
- do not repr(body).encode() bytes-ish values.
- support __html__ and _repr_html_ in sanic.response.html().

* <any type>-to-str response autoconversion limited to sanic.response.text() only.

* Workaround MyPy issue.

* Add an empty line to make isort happy.

* Add html test for __html__ and _repr_html_.

* Remove StreamingHTTPResponse.get_headers helper function.

* Add back HTTPResponse Keep-Alive removed by earlier merge or something.

* Revert "Remove StreamingHTTPResponse.get_headers helper function."

Tests depend on this otherwise useless function.

This reverts commit 9651e6ae01.

* Add deprecation warnings; instead of assert for wrong HTTP version, and for non-string response.text.

* Add back missing import.

* Avoid duplicate response header tweaking code.

* Linter errors
2020-01-20 10:34:32 -06:00
L. Kärkkäinen
e908ca8cef [Trio] Quick fixes to make Sanic usable on hypercorn -k trio myweb.app (#1767)
* Quick fixes to make Sanic usable on hypercorn -k trio myweb.app

* Quick'n dirty compatibility and autodetection of hypercorn trio mode.

* mypy ignore for aiofiles/trio.

* lint
2020-01-20 10:29:06 -06:00
Ashley Sommer
801595e24a Add server.start_serving and server.serve_forever to AsyncioServer proxy object, to match asyncio-python3.7 example doc, fixes #1754 (#1762) 2020-01-20 09:00:48 -06:00
L. Kärkkäinen
ba9b432993 No tracebacks on normal errors and prettier error pages (#1768)
* Default error handler now only logs traceback on 500 errors and all responses are HTML formatted.

* Tests passing.

* Ability to flag any exception object with self.quiet = True following @ashleysommer suggestion.

* Refactor HTML formatting into errorpages.py. String escapes for debug tracebacks.

* Remove extra includes

* Auto-set quiet flag also when decorator is used.

* Cleanup, make error pages (probably) HTML5-compliant and similar for debug and non-debug modes.

* Fix lookup of non-existant status codes

* No logging of 503 errors after all.

* lint
2020-01-20 08:58:14 -06:00
Ashley Sommer
b565072ed9 Allow route decorators to stack up again (#1764)
* Allow route decorators to stack up without causing a function signature inspection crash
Fix #1742

* Apply fix to @websocket routes docorator too
Add test for double-stacked websocket decorator
remove introduction of new variable in route wrapper, extend routes in-place.
Add explanation of why a handler will be a tuple in the case of a double-stacked route decorator
2020-01-10 21:50:16 -08:00
Ashley Sommer
caa1b4d69b Fix dangling comma in arguments list for HTTPResponse in response.empty() (#1761)
* Fix dangling comma arguments list for HTTPResponse in response.empty()

* Found another black error, including another dangling comma
2020-01-10 19:58:01 -08:00
Liran Nuna
865536c5c4 Simplify status code to text lookup (#1738) 2020-01-10 08:43:44 -06:00
Eli Uriegas
784d5cce52
Merge pull request #1755 from Lagicrus/empty-response
Update docs
2020-01-04 19:15:24 -08:00
Lagicrus
0fd08c6114 Update response.rst 2020-01-04 21:26:03 +00:00
Lagicrus
cd779b6e4f Update response.rst 2020-01-04 19:51:50 +00:00