mirror of
https://github.com/frappe/gunicorn.git
synced 2026-07-05 04:01:29 +08:00
Core classes for HTTP/2 server-side protocol handling: - HTTP2Stream: Stream state management matching RFC 7540 Section 5.1 - StreamState enum for proper lifecycle tracking - Request/response tracking and body buffering - Pseudo-header extraction for :method, :path, etc. - Proper state transitions for half-close semantics - HTTP2Request: Request interface compatibility layer - Wraps HTTP2Stream for worker consumption - HTTP2Body provides file-like interface for request body - Converts HTTP/2 pseudo-headers to standard attributes - Transforms lowercase headers to uppercase for WSGI - Adds HOST header from :authority pseudo-header - HTTP2ServerConnection: h2 library integration - Lazy import of h2 for graceful degradation - Connection initialization with configurable settings - Stream management for concurrent requests - Event handling for HEADERS, DATA, RST_STREAM, GOAWAY - Response sending with proper frame generation - Flow control window management with chunked data sending - get_parser() extension for HTTP/2 dispatch
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
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, http2_connection=False):
|
|
"""Get appropriate parser based on protocol config.
|
|
|
|
Args:
|
|
cfg: Gunicorn config object
|
|
source: Socket or iterable source
|
|
source_addr: Source address tuple or None
|
|
http2_connection: If True, create HTTP/2 connection handler
|
|
|
|
Returns:
|
|
Parser instance (RequestParser, UWSGIParser, or HTTP2ServerConnection)
|
|
"""
|
|
# HTTP/2 connection
|
|
if http2_connection:
|
|
from gunicorn.http2.connection import HTTP2ServerConnection
|
|
return HTTP2ServerConnection(cfg, source, source_addr)
|
|
|
|
# uWSGI protocol
|
|
protocol = getattr(cfg, 'protocol', 'http')
|
|
if protocol == 'uwsgi':
|
|
from gunicorn.uwsgi.parser import UWSGIParser
|
|
return UWSGIParser(cfg, source, source_addr)
|
|
|
|
# Default HTTP/1.x
|
|
return RequestParser(cfg, source, source_addr)
|
|
|
|
|
|
__all__ = ['Message', 'Request', 'RequestParser', 'get_parser']
|