MCPcopy
hub / github.com/benoitc/gunicorn / handle

Method handle

gunicorn/workers/base_async.py:33–101  ·  view source on GitHub ↗
(self, listener, client, addr)

Source from the content-addressed store, hash-verified

31 return respiter == ALREADY_HANDLED
32
33 def handle(self, listener, client, addr):
34 req = None
35 try:
36 # Complete the handshake to ensure ALPN negotiation is done
37 # (needed if do_handshake_on_connect is False)
38 if isinstance(client, ssl.SSLSocket) and not self.cfg.do_handshake_on_connect:
39 client.do_handshake()
40
41 # Check if HTTP/2 was negotiated (for SSL connections)
42 is_http2 = gunicorn_sock.is_http2_negotiated(client)
43
44 if is_http2:
45 # Handle HTTP/2 connection
46 self.handle_http2(listener, client, addr)
47 return
48
49 parser = http.get_parser(self.cfg, client, addr)
50 try:
51 listener_name = listener.getsockname()
52 if not self.cfg.keepalive:
53 req = next(parser)
54 self.handle_request(listener_name, req, client, addr)
55 else:
56 # keepalive loop
57 proxy_protocol_info = {}
58 while True:
59 req = None
60 with self.timeout_ctx():
61 req = next(parser)
62 if not req:
63 break
64 if req.proxy_protocol_info:
65 proxy_protocol_info = req.proxy_protocol_info
66 else:
67 req.proxy_protocol_info = proxy_protocol_info
68 self.handle_request(listener_name, req, client, addr)
69 except http.errors.NoMoreData as e:
70 self.log.debug("Ignored premature client disconnection. %s", e)
71 except StopIteration as e:
72 self.log.debug("Closing connection. %s", e)
73 except ssl.SSLError:
74 # pass to next try-except level
75 util.reraise(*sys.exc_info())
76 except OSError:
77 # pass to next try-except level
78 util.reraise(*sys.exc_info())
79 except Exception as e:
80 self.handle_error(req, client, addr, e)
81 except ssl.SSLError as e:
82 if e.args[0] == ssl.SSL_ERROR_EOF:
83 self.log.debug("ssl connection closed")
84 client.close()
85 else:
86 self.log.debug("Error processing SSL request.")
87 self.handle_error(req, client, addr, e)
88 except OSError as e:
89 if e.errno not in (errno.EPIPE, errno.ECONNRESET, errno.ENOTCONN):
90 self.log.exception("Socket error processing request.")

Callers

nothing calls this directly

Calls 8

handle_http2Method · 0.95
handle_requestMethod · 0.95
timeout_ctxMethod · 0.95
handle_errorMethod · 0.80
getsocknameMethod · 0.45
debugMethod · 0.45
closeMethod · 0.45
exceptionMethod · 0.45

Tested by

no test coverage detected