Handle an HTTP/2 connection. Processes multiplexed HTTP/2 streams until the connection closes.
(self, listener, client, addr)
| 101 | util.close(client) |
| 102 | |
| 103 | def handle_http2(self, listener, client, addr): |
| 104 | """Handle an HTTP/2 connection. |
| 105 | |
| 106 | Processes multiplexed HTTP/2 streams until the connection closes. |
| 107 | """ |
| 108 | listener_name = listener.getsockname() |
| 109 | |
| 110 | try: |
| 111 | h2_conn = http.get_parser(self.cfg, client, addr, http2_connection=True) |
| 112 | h2_conn.initiate_connection() |
| 113 | |
| 114 | while not h2_conn.is_closed and self.alive: |
| 115 | try: |
| 116 | requests = h2_conn.receive_data() |
| 117 | except http.errors.NoMoreData: |
| 118 | self.log.debug("HTTP/2 connection closed by client") |
| 119 | break |
| 120 | |
| 121 | for req in requests: |
| 122 | try: |
| 123 | self.handle_http2_request(listener_name, req, client, addr, h2_conn) |
| 124 | except Exception as e: |
| 125 | self.log.exception("Error handling HTTP/2 request") |
| 126 | try: |
| 127 | h2_conn.send_error(req.stream.stream_id, 500, str(e)) |
| 128 | except Exception: |
| 129 | pass |
| 130 | finally: |
| 131 | h2_conn.cleanup_stream(req.stream.stream_id) |
| 132 | |
| 133 | except ssl.SSLError as e: |
| 134 | if e.args[0] == ssl.SSL_ERROR_EOF: |
| 135 | self.log.debug("HTTP/2 SSL connection closed") |
| 136 | else: |
| 137 | self.log.debug("HTTP/2 SSL error: %s", e) |
| 138 | except OSError as e: |
| 139 | if e.errno not in (errno.EPIPE, errno.ECONNRESET, errno.ENOTCONN): |
| 140 | self.log.exception("HTTP/2 socket error") |
| 141 | except Exception as e: |
| 142 | self.log.exception("HTTP/2 connection error: %s", e) |
| 143 | |
| 144 | def handle_http2_request(self, listener_name, req, sock, addr, h2_conn): |
| 145 | """Handle a single HTTP/2 request.""" |
no test coverage detected