Allow WSGI applications to use Transfer-Encoding: chunked under uWSGI.
Project description
uwsgi-chunked
WSGI application wrapper that handles Transfer-Encoding: chunked
This library provides a simple wrapper for a WSGI application that uses the uwsgi low-level api for reading requests that use Transfer-Encoding: chunked.
In normal operation, it will read the entire request into memory, so if you expect large requests (like uploads), you should offload these to a proxy such as nginx, or if your application allows it, use stream mode.
Installation
$ pip install uwsgi_chunked
Usage
When you run uwsgi, pass the argument: --http-chunked-input.
Usage with Django is as follows, you should edit the wsgi.py file provided in the default Django application.
"""
WSGI config for myapp project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
from uwsgi_chunked import Chunked
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myapp.settings')
application = Chunked(get_wsgi_application())
To use stream mode, pass the optional keyword argument stream=True to Chunked. Be careful with stream mode as it does not set the Content-Length header as required by the WSGI spec.
application = Chunked(get_wsgi_application(), stream=True)
How it works
The Chunked object looks for a request with Transfer-Encoding: chunked and reads the request data using the low-level uwsgi api. It then places the request data into a BytesIO instance in environ['wsgi.input'] where it is expected. It also sets the Content-Length header as WSGI requires. When not using stream mode, the entire request is read into memory in order to calculate the Content-Length header.
Development
Issues and PRs welcome. This is a simple module that has no dependencies except that it only works when running under uwsgi. When running under uwsgi a special module is available that provides the necessary api.
You can run the demo application in docker with make run. The demo application uses auto reloading to detect changes to the python modules.
Tests require the demo application (running under uwsgi) to function. Therefore, do make run in one terminal and make test in another.
You can also test using curl with the make curl target (while the demo app is running).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file uwsgi-chunked-0.1.8.tar.gz
.
File metadata
- Download URL: uwsgi-chunked-0.1.8.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4571ce818adca2bf79eb496ba4b6e206a471a46d504d7ce7efd3eff697821974 |
|
MD5 | 6a38b3e91e15325f8264d6455a429dc9 |
|
BLAKE2b-256 | e2161900ed91f3611d0f9234e72250c40977487e52d76d67a13610bf551c1e0e |
File details
Details for the file uwsgi_chunked-0.1.8-py3-none-any.whl
.
File metadata
- Download URL: uwsgi_chunked-0.1.8-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 463010354b778b67b5e1f04529ec54ca35b6f3016ef0814fa4af48b8cb23b8b7 |
|
MD5 | baddd21e152d53696c8af2b89cd29772 |
|
BLAKE2b-256 | ec80ea9f38147e6663e8e4b6dd8d1148799756608fb6f6e16e35c47cb7e263af |