test: stop using chunked encoding for responses (#617)
This commit is contained in:
@@ -201,23 +201,30 @@ public class Server implements HttpHandler {
|
||||
return;
|
||||
}
|
||||
exchange.getResponseHeaders().add("Content-Type", mimeType(file));
|
||||
OutputStream output = exchange.getResponseBody();
|
||||
ByteArrayOutputStream body = new ByteArrayOutputStream();
|
||||
OutputStream output = body;
|
||||
if (gzipRoutes.contains(path)) {
|
||||
exchange.getResponseHeaders().add("Content-Encoding", "gzip");
|
||||
}
|
||||
try (FileInputStream input = new FileInputStream(file)) {
|
||||
exchange.sendResponseHeaders(200, 0);
|
||||
if (gzipRoutes.contains(path)) {
|
||||
output = new GZIPOutputStream(output);
|
||||
}
|
||||
copy(input, output);
|
||||
output.close();
|
||||
} catch (IOException e) {
|
||||
try (Writer writer = new OutputStreamWriter(exchange.getResponseBody())) {
|
||||
body.reset();
|
||||
try (Writer writer = new OutputStreamWriter(output)) {
|
||||
writer.write("Exception: " + e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
output.close();
|
||||
long contentLength = body.size();
|
||||
// -1 means no body, 0 means chunked encoding.
|
||||
exchange.sendResponseHeaders(200, contentLength == 0 ? -1 : contentLength);
|
||||
if (contentLength > 0) {
|
||||
exchange.getResponseBody().write(body.toByteArray());
|
||||
}
|
||||
exchange.getResponseBody().close();
|
||||
}
|
||||
|
||||
private static String mimeType(File file) {
|
||||
|
||||
@@ -74,7 +74,6 @@ public class TestPageNetworkSizes extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled("responseBodySize == 5")
|
||||
void shouldSetBodySizeTo0WhenThereWasNoResponseBody() {
|
||||
Response response = page.navigate(server.EMPTY_PAGE);
|
||||
Sizes sizes = response.request().sizes();
|
||||
@@ -83,7 +82,6 @@ public class TestPageNetworkSizes extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled("responseBodySize == 0")
|
||||
void shouldHaveTheCorrectResponseBodySize() throws IOException {
|
||||
Response response = page.navigate(server.PREFIX + "/simplezip.json");
|
||||
Sizes sizes = response.request().sizes();
|
||||
|
||||
Reference in New Issue
Block a user