MCPcopy
hub / github.com/mitmproxy/mitmproxy / test_no_normalization

Function test_no_normalization

test/mitmproxy/proxy/layers/http/test_http2.py:557–622  ·  view source on GitHub ↗

Test that we don't normalize headers when we just pass them through.

(tctx, normalize)

Source from the content-addressed store, hash-verified

555
556@pytest.mark.parametrize("normalize", [True, False])
557def test_no_normalization(tctx, normalize):
558 """Test that we don't normalize headers when we just pass them through."""
559 tctx.options.normalize_outbound_headers = normalize
560 tctx.options.validate_inbound_headers = False
561
562 server = Placeholder(Server)
563 flow = Placeholder(HTTPFlow)
564 playbook, cff = start_h2_client(tctx)
565
566 request_headers = list(example_request_headers) + [
567 (b"Should-Not-Be-Capitalized! ", b" :) ")
568 ]
569 request_headers_lower = [(k.lower(), v) for (k, v) in request_headers]
570 response_headers = list(example_response_headers) + [(b"Same", b"Here")]
571 response_headers_lower = [(k.lower(), v) for (k, v) in response_headers]
572
573 initial = Placeholder(bytes)
574 assert (
575 playbook
576 >> DataReceived(
577 tctx.client,
578 cff.build_headers_frame(request_headers, flags=["END_STREAM"]).serialize(),
579 )
580 << http.HttpRequestHeadersHook(flow)
581 >> reply()
582 << http.HttpRequestHook(flow)
583 >> reply()
584 << OpenConnection(server)
585 >> reply(None, side_effect=make_h2)
586 << SendData(server, initial)
587 )
588 frames = decode_frames(initial())
589 assert [type(x) for x in frames] == [
590 hyperframe.frame.SettingsFrame,
591 hyperframe.frame.WindowUpdateFrame,
592 hyperframe.frame.HeadersFrame,
593 ]
594 assert (
595 hpack.hpack.Decoder().decode(frames[2].data, True) == request_headers_lower
596 if normalize
597 else request_headers
598 )
599
600 sff = FrameFactory()
601 (
602 playbook
603 >> DataReceived(
604 server,
605 sff.build_headers_frame(response_headers, flags=["END_STREAM"]).serialize(),
606 )
607 << http.HttpResponseHeadersHook(flow)
608 >> reply()
609 << http.HttpResponseHook(flow)
610 >> reply()
611 )
612 if normalize:
613 playbook << Log(
614 "Lowercased 'Same' header as uppercase is not allowed with HTTP/2."

Callers

nothing calls this directly

Calls 11

build_headers_frameMethod · 0.95
PlaceholderFunction · 0.90
DataReceivedClass · 0.90
replyClass · 0.90
OpenConnectionClass · 0.90
SendDataClass · 0.90
FrameFactoryClass · 0.90
LogClass · 0.90
start_h2_clientFunction · 0.85
decode_framesFunction · 0.85
decodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…