Test HTTP request streaming This is a bit more contrived as we may receive server data while we are still sending the request.
(tctx, why, transfer_encoding, response)
| 539 | "response", ["normal response", "early response", "early close", "early kill"] |
| 540 | ) |
| 541 | def test_request_streaming(tctx, why, transfer_encoding, response): |
| 542 | """ |
| 543 | Test HTTP request streaming |
| 544 | |
| 545 | This is a bit more contrived as we may receive server data while we are still sending the request. |
| 546 | """ |
| 547 | server = Placeholder(Server) |
| 548 | flow = Placeholder(HTTPFlow) |
| 549 | playbook = Playbook(http.HttpLayer(tctx, HTTPMode.regular)) |
| 550 | |
| 551 | if why.startswith("body_size"): |
| 552 | tctx.options.stream_large_bodies = why.replace("body_size=", "") |
| 553 | |
| 554 | def enable_streaming(flow: HTTPFlow): |
| 555 | if why == "addon": |
| 556 | flow.request.stream = True |
| 557 | |
| 558 | playbook >> DataReceived( |
| 559 | tctx.client, b"POST http://example.com/ HTTP/1.1\r\nHost: example.com\r\n" |
| 560 | ) |
| 561 | if transfer_encoding == "identity": |
| 562 | playbook >> DataReceived(tctx.client, b"Content-Length: 9\r\n\r\nabc") |
| 563 | else: |
| 564 | playbook >> DataReceived( |
| 565 | tctx.client, b"Transfer-Encoding: chunked\r\n\r\n3\r\nabc\r\n" |
| 566 | ) |
| 567 | |
| 568 | playbook << http.HttpRequestHeadersHook(flow) |
| 569 | playbook >> reply(side_effect=enable_streaming) |
| 570 | |
| 571 | needs_more_data_before_open = ( |
| 572 | why == "body_size=3" and transfer_encoding == "chunked" |
| 573 | ) |
| 574 | if needs_more_data_before_open: |
| 575 | playbook >> DataReceived(tctx.client, b"3\r\ndef\r\n") |
| 576 | |
| 577 | playbook << OpenConnection(server) |
| 578 | playbook >> reply(None) |
| 579 | playbook << SendData(server, b"POST / HTTP/1.1\r\nHost: example.com\r\n") |
| 580 | |
| 581 | if transfer_encoding == "identity": |
| 582 | playbook << SendData(server, b"Content-Length: 9\r\n\r\nabc") |
| 583 | playbook >> DataReceived(tctx.client, b"def") |
| 584 | playbook << SendData(server, b"def") |
| 585 | else: |
| 586 | if needs_more_data_before_open: |
| 587 | playbook << SendData( |
| 588 | server, b"Transfer-Encoding: chunked\r\n\r\n6\r\nabcdef\r\n" |
| 589 | ) |
| 590 | else: |
| 591 | playbook << SendData( |
| 592 | server, b"Transfer-Encoding: chunked\r\n\r\n3\r\nabc\r\n" |
| 593 | ) |
| 594 | playbook >> DataReceived(tctx.client, b"3\r\ndef\r\n") |
| 595 | playbook << SendData(server, b"3\r\ndef\r\n") |
| 596 | |
| 597 | if response == "normal response": |
| 598 | if transfer_encoding == "identity": |
nothing calls this directly
no test coverage detected
searching dependent graphs…