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

Method check

tests/treq_asgi.py:203–256  ·  view source on GitHub ↗

Parse request and verify it matches expected values.

(self, cfg, sender)

Source from the content-addressed store, hash-verified

201 read += chunk
202
203 def check(self, cfg, sender):
204 """Parse request and verify it matches expected values."""
205 body_chunks = []
206
207 # Handle limit_request_field_size=0 meaning "use default"
208 field_size = cfg.limit_request_field_size
209 if field_size <= 0:
210 field_size = 8190 # Default max
211
212 parser = PythonProtocol(
213 on_body=lambda chunk: body_chunks.append(chunk),
214 limit_request_line=cfg.limit_request_line,
215 limit_request_fields=cfg.limit_request_fields,
216 limit_request_field_size=field_size,
217 permit_unconventional_http_method=cfg.permit_unconventional_http_method,
218 permit_unconventional_http_version=cfg.permit_unconventional_http_version,
219 proxy_protocol=getattr(cfg, 'proxy_protocol', 'off'),
220 )
221
222 for chunk in sender():
223 parser.feed(chunk)
224 parser.finish() # Signal EOF
225
226 # Verify parsed request matches expected
227 exp = self.expect[0] # For now, handle single request
228
229 assert parser.method == exp["method"].encode('latin-1'), \
230 f"Method mismatch: {parser.method} != {exp['method']}"
231
232 # Path comparison - parser stores raw bytes
233 expected_path = exp["uri"]["raw"].encode('latin-1')
234 assert parser.path == expected_path, \
235 f"Path mismatch: {parser.path} != {expected_path}"
236
237 assert parser.http_version == exp["version"], \
238 f"Version mismatch: {parser.http_version} != {exp['version']}"
239
240 # Headers - convert to comparable format
241 parsed_headers = [
242 (n.decode('latin-1').upper(), v.decode('latin-1'))
243 for n, v in parser.headers
244 ]
245 assert parsed_headers == exp["headers"], \
246 f"Headers mismatch: {parsed_headers} != {exp['headers']}"
247
248 # Body - ensure expected_body is bytes for comparison
249 body = b"".join(body_chunks)
250 expected_body = exp["body"]
251 if isinstance(expected_body, str):
252 expected_body = expected_body.encode('latin-1')
253 assert body == expected_body, \
254 f"Body mismatch: {body!r} != {expected_body!r}"
255
256 assert parser.is_complete, "Parser did not complete"
257
258
259class badrequest:

Callers

nothing calls this directly

Calls 5

feedMethod · 0.95
finishMethod · 0.95
PythonProtocolClass · 0.90
encodeMethod · 0.80
decodeMethod · 0.80

Tested by

no test coverage detected