From 2aea8354ea60c1ec906905ca006fd4d4c928fe63 Mon Sep 17 00:00:00 2001 From: vvanglro Date: Thu, 21 Nov 2024 03:04:55 +0800 Subject: [PATCH 1/5] fix(http): enable httptools lenient data (#2488) Co-authored-by: Marcelo Trylesinski --- pyproject.toml | 2 +- uvicorn/protocols/http/httptools_impl.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 17ee643c5..6dd4916db 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,7 @@ dependencies = [ [project.optional-dependencies] standard = [ "colorama>=0.4;sys_platform == 'win32'", - "httptools>=0.5.0", + "httptools>=0.6.3", "python-dotenv>=0.13", "PyYAML>=5.1", "uvloop>=0.14.0,!=0.15.0,!=0.15.1; sys_platform != 'win32' and (sys_platform != 'cygwin' and platform_python_implementation != 'PyPy')", diff --git a/uvicorn/protocols/http/httptools_impl.py b/uvicorn/protocols/http/httptools_impl.py index 00f1fb720..f3396a768 100644 --- a/uvicorn/protocols/http/httptools_impl.py +++ b/uvicorn/protocols/http/httptools_impl.py @@ -58,6 +58,14 @@ def __init__( self.access_logger = logging.getLogger("uvicorn.access") self.access_log = self.access_logger.hasHandlers() self.parser = httptools.HttpRequestParser(self) + + try: + # Enable dangerous leniencies to allow server to a response on the first request from a pipelined request. + self.parser.set_dangerous_leniencies(lenient_data_after_close=True) + except AttributeError: # pragma: no cover + # httptools < 0.6.3 + pass + self.ws_protocol_class = config.ws_protocol_class self.root_path = config.root_path self.limit_concurrency = config.limit_concurrency From fc6c51b8bba48454685907ba629ca404543e9f42 Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Wed, 20 Nov 2024 20:19:24 +0100 Subject: [PATCH 2/5] Drop ASGI spec version to 2.3 on HTTP (#2513) --- tests/protocols/test_http.py | 4 ++-- uvicorn/protocols/http/h11_impl.py | 5 +---- uvicorn/protocols/http/httptools_impl.py | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/protocols/test_http.py b/tests/protocols/test_http.py index b3b060b0f..d8711af5b 100644 --- a/tests/protocols/test_http.py +++ b/tests/protocols/test_http.py @@ -860,8 +860,8 @@ async def asgi(receive: ASGIReceiveCallable, send: ASGISendCallable): @pytest.mark.parametrize( "asgi2or3_app, expected_scopes", [ - (asgi3app, {"version": "3.0", "spec_version": "2.4"}), - (asgi2app, {"version": "2.0", "spec_version": "2.4"}), + (asgi3app, {"version": "3.0", "spec_version": "2.3"}), + (asgi2app, {"version": "2.0", "spec_version": "2.3"}), ], ) async def test_scopes( diff --git a/uvicorn/protocols/http/h11_impl.py b/uvicorn/protocols/http/h11_impl.py index 932ddf62b..b8cdde3ab 100644 --- a/uvicorn/protocols/http/h11_impl.py +++ b/uvicorn/protocols/http/h11_impl.py @@ -200,10 +200,7 @@ def handle_events(self) -> None: full_raw_path = self.root_path.encode("ascii") + raw_path self.scope = { "type": "http", - "asgi": { - "version": self.config.asgi_version, - "spec_version": "2.4", - }, + "asgi": {"version": self.config.asgi_version, "spec_version": "2.3"}, "http_version": event.http_version.decode("ascii"), "server": self.server, "client": self.client, diff --git a/uvicorn/protocols/http/httptools_impl.py b/uvicorn/protocols/http/httptools_impl.py index f3396a768..e8795ed35 100644 --- a/uvicorn/protocols/http/httptools_impl.py +++ b/uvicorn/protocols/http/httptools_impl.py @@ -222,7 +222,7 @@ def on_message_begin(self) -> None: self.headers = [] self.scope = { # type: ignore[typeddict-item] "type": "http", - "asgi": {"version": self.config.asgi_version, "spec_version": "2.4"}, + "asgi": {"version": self.config.asgi_version, "spec_version": "2.3"}, "http_version": "1.1", "server": self.server, "client": self.client, From 04c6320f396938363e5f5488ffbf19adf528681e Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Wed, 20 Nov 2024 20:22:48 +0100 Subject: [PATCH 3/5] Version 0.32.1 (#2515) * Version 0.32.1 * Update CHANGELOG.md --- CHANGELOG.md | 7 +++++++ uvicorn/__init__.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74af8e5ee..ffa11d53f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## 0.32.1 (2024-11-20) + +### Fixed + +* Drop ASGI spec version to 2.3 on HTTP scope [#2513](https://github.com/encode/uvicorn/pull/2513) +* Enable httptools lenient data on `httptools >= 0.6.3` [#2488](https://github.com/encode/uvicorn/pull/2488) + ## 0.32.0 (2024-10-15) ### Added diff --git a/uvicorn/__init__.py b/uvicorn/__init__.py index c5c7b8f33..869de7984 100644 --- a/uvicorn/__init__.py +++ b/uvicorn/__init__.py @@ -1,5 +1,5 @@ from uvicorn.config import Config from uvicorn.main import Server, main, run -__version__ = "0.32.0" +__version__ = "0.32.1" __all__ = ["main", "run", "Config", "Server"] From 8c3402dd222d2773770bf0de8e68d85931efdf84 Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Wed, 20 Nov 2024 20:34:29 +0100 Subject: [PATCH 4/5] Update `publish.yaml` with latest PyPI recommendations (#2516) * Update `publish.yaml` with latest PyPI recommendations * Update .github/workflows/publish.yml * Simplify pipeline * Simplify pipeline * Use Python 3.12 --- .github/workflows/publish.yml | 88 ++++++++++++++++++++++++++++------- 1 file changed, 72 insertions(+), 16 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 7ecef5559..c97c1acac 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,24 +6,80 @@ on: - '*' jobs: - publish: - name: "Publish release" - runs-on: "ubuntu-latest" + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install dependencies + run: scripts/install + + - name: Build package & docs + run: scripts/build + + - name: Upload package distributions + uses: actions/upload-artifact@v2 + with: + name: package-distributions + path: dist/ + + - name: Upload documentation + uses: actions/upload-artifact@v2 + with: + name: documentation + path: site/ + + pypi-publish: + runs-on: ubuntu-latest + needs: build + + permissions: + id-token: write environment: - name: deploy + name: pypi + url: https://pypi.org/project/uvicorn steps: - - uses: "actions/checkout@v4" - - uses: "actions/setup-python@v5" + - name: Download artifacts + uses: actions/download-artifact@v2 with: - python-version: "3.8" - - name: "Install dependencies" - run: "scripts/install" - - name: "Build package & docs" - run: "scripts/build" - - name: "Publish to PyPI & deploy docs" - run: "scripts/publish" - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} + name: package-distributions + path: dist/ + + - name: Publish distribution 📦 to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + + docs-publish: + runs-on: ubuntu-latest + needs: build + + permissions: + contents: write + + steps: + - name: Download artifacts + uses: actions/download-artifact@v2 + with: + name: documentation + path: site/ + + - name: Configure Git Credentials + run: | + git config user.name github-actions[bot] + git config user.email 41898282+github-actions[bot]@users.noreply.github.com + + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install dependencies + run: scripts/install + + - name: Publish documentation 📚 to GitHub Pages + run: mkdocs gh-deploy --force From 5279296e620fad6c6839263c279ff23b4be8df32 Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Wed, 20 Nov 2024 20:38:07 +0100 Subject: [PATCH 5/5] Upgrade upload/download GitHub Actions (#2517) --- .github/workflows/publish.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c97c1acac..ad9481f35 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -23,13 +23,13 @@ jobs: run: scripts/build - name: Upload package distributions - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: package-distributions path: dist/ - name: Upload documentation - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: documentation path: site/ @@ -47,7 +47,7 @@ jobs: steps: - name: Download artifacts - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4 with: name: package-distributions path: dist/ @@ -64,7 +64,7 @@ jobs: steps: - name: Download artifacts - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4 with: name: documentation path: site/