@@ -58,3 +58,57 @@ def multi_values_handler(_request: WerkzeugRequest) -> Response:
5858 with SimpleRequestsClient () as client :
5959 response = client .request (request , url )
6060 assert response .headers .getlist ("Set-Cookie" ) == ["value1" , "value2" ]
61+
62+ def test_chunked_encoded_request (self , httpserver : HTTPServer ):
63+ # because SimpleRequestsClient mostly forwards an existing incoming request, and it uses `restore_payload`
64+ # this means that any `Transfer-Encoding` headers must be stripped before sending
65+
66+ def transfer_encoded_handler (_request : WerkzeugRequest ) -> Response :
67+ return Response (response = _request .data )
68+
69+ httpserver .expect_request ("/" ).respond_with_handler (transfer_encoded_handler )
70+
71+ url = httpserver .url_for ("/" )
72+ body = b"hello world"
73+ request = Request (
74+ path = "/" ,
75+ method = "POST" ,
76+ body = body ,
77+ headers = {
78+ "Transfer-Encoding" : "chunked" ,
79+ "Content-Length" : str (len (body )),
80+ },
81+ )
82+
83+ with SimpleRequestsClient () as client :
84+ response = client .request (request , url )
85+
86+ assert response .data == body
87+
88+ def test_gzip_encoded_request (self , httpserver : HTTPServer ):
89+ def transfer_encoded_handler (_request : WerkzeugRequest ) -> Response :
90+ return Response (response = _request .data )
91+
92+ httpserver .expect_request ("/" ).respond_with_handler (transfer_encoded_handler )
93+
94+ url = httpserver .url_for ("/" )
95+ raw_body = b"hello world"
96+ request = Request (
97+ path = "/" ,
98+ method = "POST" ,
99+ # we need to use the raw body here, because in real world use case, the webserver would have read and
100+ # decoded the payload
101+ body = raw_body ,
102+ headers = {
103+ "Transfer-Encoding" : "gzip" ,
104+ "Content-Length" : str (len (raw_body )),
105+ },
106+ )
107+
108+ with SimpleRequestsClient () as client :
109+ response = client .request (request , url )
110+
111+ assert response .data == raw_body
112+ # we're making sure we're not passing the `Transfer-Encoding` gzip along, as we're read the body and sent it
113+ # decoded over the wire
114+ assert "Transfer-Encoding" not in httpserver .log [0 ][0 ].headers
0 commit comments