Test that we don't normalize headers when we just pass them through.
(tctx, normalize)
| 555 | |
| 556 | @pytest.mark.parametrize("normalize", [True, False]) |
| 557 | def 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." |
nothing calls this directly
no test coverage detected
searching dependent graphs…