bffdb3b5c2
* 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
|
||
---|---|---|
.. | ||
benchmark | ||
certs | ||
performance | ||
static | ||
conftest.py | ||
test_app.py | ||
test_asgi_client.py | ||
test_asgi.py | ||
test_bad_request.py | ||
test_blueprint_group.py | ||
test_blueprints.py | ||
test_config.py | ||
test_cookies.py | ||
test_create_task.py | ||
test_custom_protocol.py | ||
test_custom_request.py | ||
test_dynamic_routes.py | ||
test_exceptions_handler.py | ||
test_exceptions.py | ||
test_headers.py | ||
test_helpers.py | ||
test_keep_alive_timeout.py | ||
test_logging.py | ||
test_logo.py | ||
test_middleware.py | ||
test_multiprocessing.py | ||
test_named_routes.py | ||
test_payload_too_large.py | ||
test_redirect.py | ||
test_request_buffer_queue_size.py | ||
test_request_cancel.py | ||
test_request_data.py | ||
test_request_stream.py | ||
test_request_timeout.py | ||
test_requests.py | ||
test_response_timeout.py | ||
test_response.py | ||
test_routes.py | ||
test_server_events.py | ||
test_signal_handlers.py | ||
test_static.py | ||
test_test_client_port.py | ||
test_url_building.py | ||
test_url_for_static.py | ||
test_utf8.py | ||
test_vhosts.py | ||
test_views.py | ||
test_worker.py |