Skip to content

Commit 3eb8893

Browse files
authored
test: stop using chunked encoding for responses (#617)
1 parent 948dd15 commit 3eb8893

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

playwright/src/test/java/com/microsoft/playwright/Server.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,23 +201,30 @@ public void handle(HttpExchange exchange) throws IOException {
201201
return;
202202
}
203203
exchange.getResponseHeaders().add("Content-Type", mimeType(file));
204-
OutputStream output = exchange.getResponseBody();
204+
ByteArrayOutputStream body = new ByteArrayOutputStream();
205+
OutputStream output = body;
205206
if (gzipRoutes.contains(path)) {
206207
exchange.getResponseHeaders().add("Content-Encoding", "gzip");
207208
}
208209
try (FileInputStream input = new FileInputStream(file)) {
209-
exchange.sendResponseHeaders(200, 0);
210210
if (gzipRoutes.contains(path)) {
211211
output = new GZIPOutputStream(output);
212212
}
213213
copy(input, output);
214+
output.close();
214215
} catch (IOException e) {
215-
try (Writer writer = new OutputStreamWriter(exchange.getResponseBody())) {
216+
body.reset();
217+
try (Writer writer = new OutputStreamWriter(output)) {
216218
writer.write("Exception: " + e);
217219
}
218-
return;
219220
}
220-
output.close();
221+
long contentLength = body.size();
222+
// -1 means no body, 0 means chunked encoding.
223+
exchange.sendResponseHeaders(200, contentLength == 0 ? -1 : contentLength);
224+
if (contentLength > 0) {
225+
exchange.getResponseBody().write(body.toByteArray());
226+
}
227+
exchange.getResponseBody().close();
221228
}
222229

223230
private static String mimeType(File file) {

playwright/src/test/java/com/microsoft/playwright/TestPageNetworkSizes.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ void shouldSetBodySizeHeadersSizeAndTransferSize() throws ExecutionException, In
7474
}
7575

7676
@Test
77-
@Disabled("responseBodySize == 5")
7877
void shouldSetBodySizeTo0WhenThereWasNoResponseBody() {
7978
Response response = page.navigate(server.EMPTY_PAGE);
8079
Sizes sizes = response.request().sizes();
@@ -83,7 +82,6 @@ void shouldSetBodySizeTo0WhenThereWasNoResponseBody() {
8382
}
8483

8584
@Test
86-
@Disabled("responseBodySize == 0")
8785
void shouldHaveTheCorrectResponseBodySize() throws IOException {
8886
Response response = page.navigate(server.PREFIX + "/simplezip.json");
8987
Sizes sizes = response.request().sizes();

0 commit comments

Comments
 (0)