@@ -83,7 +83,32 @@ run_client network port/int -> none:
8383 expect_json response :
8484 expect_equals 123 it [ "foo" ]
8585
86- response := client .get --uri = "http://localhost:$ port /redirect_back"
86+ // Try to buffer the whole response.
87+ response := client .get --host = "localhost" --port = port --path = "/foo.json"
88+ expect_equals 200 response .status_code
89+ response .body .buffer-all
90+ bytes := response .body .read-all
91+ decoded := json .decode bytes
92+ expect_equals 123 decoded [ "foo" ]
93+
94+ response = client .get --uri = "http://localhost:$ port /content-length.json"
95+ expect_equals 200 response .status_code
96+ expect_equals "application/json"
97+ response .headers .single "Content-Type"
98+ content-length := response .headers .single "Content-Length"
99+ expect_not_null content-length
100+ expect_json response :
101+ expect_equals 123 it [ "foo" ]
102+
103+ // Try to buffer the whole response.
104+ response = client .get --uri = "http://localhost:$ port /content-length.json"
105+ expect_equals 200 response .status_code
106+ response .body .buffer-all
107+ bytes = response .body .read-all
108+ decoded = json .decode bytes
109+ expect_equals 123 decoded [ "foo" ]
110+
111+ response = client .get --uri = "http://localhost:$ port /redirect_back"
87112 expect connection != client .connection_ // Because of the redirect we had to make a new connection.
88113 expect_equals "application/json"
89114 response .headers .single "Content-Type"
@@ -256,6 +281,11 @@ listen server server_socket my_port other_port:
256281 response_writer .headers .set "Content-Type" "application/json"
257282 writer .write
258283 json .encode { "foo" : 123 , "bar" : 1.0 / 3 , "fizz" : [ 1 , 42 , 103 ] }
284+ else if resource == "/content-length.json" :
285+ data := json .encode { "foo" : 123 , "bar" : 1.0 / 3 , "fizz" : [ 1 , 42 , 103 ] }
286+ response_writer .headers .set "Content-Type" "application/json"
287+ response_writer .headers .set "Content-Length" "$ data.size "
288+ writer .write data
259289 else if resource == "/cat.png" :
260290 response_writer .headers .set "Content-Type" "image/png"
261291 writer .write CAT
0 commit comments