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

Method receive_data

gunicorn/http2/connection.py:122–186  ·  view source on GitHub ↗

Process received data and return completed requests. Args: data: Optional bytes to process. If None, reads from socket. Returns: list: List of HTTP2Request objects for completed requests Raises: HTTP2ConnectionError: On protocol or conne

(self, data=None)

Source from the content-addressed store, hash-verified

120 self._initialized = True
121
122 def receive_data(self, data=None):
123 """Process received data and return completed requests.
124
125 Args:
126 data: Optional bytes to process. If None, reads from socket.
127
128 Returns:
129 list: List of HTTP2Request objects for completed requests
130
131 Raises:
132 HTTP2ConnectionError: On protocol or connection errors
133 """
134 if data is None:
135 try:
136 data = self.sock.recv(self.READ_BUFFER_SIZE)
137 except (OSError, IOError) as e:
138 raise HTTP2ConnectionError(f"Socket read error: {e}")
139
140 if not data:
141 # Connection closed by peer
142 self._closed = True
143 return []
144
145 # Feed data to h2
146 # Note: Specific exceptions must come before ProtocolError (their parent class)
147 try:
148 events = self.h2_conn.receive_data(data)
149 except _h2_exceptions.FlowControlError as e:
150 # Send GOAWAY with FLOW_CONTROL_ERROR
151 self.close(error_code=HTTP2ErrorCode.FLOW_CONTROL_ERROR)
152 raise HTTP2ProtocolError(str(e))
153 except _h2_exceptions.FrameTooLargeError as e:
154 # Send GOAWAY with FRAME_SIZE_ERROR
155 self.close(error_code=HTTP2ErrorCode.FRAME_SIZE_ERROR)
156 raise HTTP2ProtocolError(str(e))
157 except _h2_exceptions.InvalidSettingsValueError as e:
158 # Use error_code from h2 exception (RFC 7540 Section 6.5.2):
159 # INITIAL_WINDOW_SIZE > 2^31-1 gives FLOW_CONTROL_ERROR
160 # Other invalid settings give PROTOCOL_ERROR
161 error_code = getattr(e, 'error_code', None)
162 if error_code is not None:
163 self.close(error_code=error_code)
164 else:
165 self.close(error_code=HTTP2ErrorCode.PROTOCOL_ERROR)
166 raise HTTP2ProtocolError(str(e))
167 except _h2_exceptions.TooManyStreamsError as e:
168 # Send GOAWAY with REFUSED_STREAM
169 self.close(error_code=HTTP2ErrorCode.REFUSED_STREAM)
170 raise HTTP2ProtocolError(str(e))
171 except _h2_exceptions.ProtocolError as e:
172 # Send GOAWAY with PROTOCOL_ERROR before raising
173 self.close(error_code=HTTP2ErrorCode.PROTOCOL_ERROR)
174 raise HTTP2ProtocolError(str(e))
175
176 # Process events
177 completed_requests = []
178 for event in events:
179 request = self._handle_event(event)

Calls 6

closeMethod · 0.95
_handle_eventMethod · 0.95
_send_pending_dataMethod · 0.95
HTTP2ProtocolErrorClass · 0.85
recvMethod · 0.45