mirror of
https://github.com/frappe/gunicorn.git
synced 2026-07-07 13:11:30 +08:00
Add support for the uWSGI binary protocol, enabling gunicorn to work
with nginx's uwsgi_pass directive.
New module gunicorn/uwsgi/ with:
- UWSGIRequest: Parses 4-byte binary header and key-value vars block
- UWSGIParser: Protocol parser following existing Parser pattern
- Error classes: InvalidUWSGIHeader, UnsupportedModifier, ForbiddenUWSGIRequest
New configuration options:
- --protocol: Select 'http' (default) or 'uwsgi' protocol
- --uwsgi-allow-from: IP allowlist for uWSGI requests (default: localhost)
Worker integration via get_parser() factory in gunicorn/http/__init__.py,
updates to sync, gthread, and base_async workers.
Example nginx config:
upstream gunicorn {
server 127.0.0.1:8000;
}
location / {
uwsgi_pass gunicorn;
include uwsgi_params;
}
28 lines
820 B
Python
28 lines
820 B
Python
#
|
|
# This file is part of gunicorn released under the MIT license.
|
|
# See the NOTICE for more information.
|
|
|
|
from gunicorn.http.message import Message, Request
|
|
from gunicorn.http.parser import RequestParser
|
|
|
|
|
|
def get_parser(cfg, source, source_addr):
|
|
"""Get appropriate parser based on protocol config.
|
|
|
|
Args:
|
|
cfg: Gunicorn config object
|
|
source: Socket or iterable source
|
|
source_addr: Source address tuple or None
|
|
|
|
Returns:
|
|
Parser instance (RequestParser or UWSGIParser)
|
|
"""
|
|
protocol = getattr(cfg, 'protocol', 'http')
|
|
if protocol == 'uwsgi':
|
|
from gunicorn.uwsgi.parser import UWSGIParser
|
|
return UWSGIParser(cfg, source, source_addr)
|
|
return RequestParser(cfg, source, source_addr)
|
|
|
|
|
|
__all__ = ['Message', 'Request', 'RequestParser', 'get_parser']
|