Skip to content

Commit 33d26d0

Browse files
authored
Upload Cucumber Reports with Gzip encoding (#3115)
1 parent 5c4bac9 commit 33d26d0

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
1010
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1111

1212
## [Unreleased]
13+
### Added
14+
- [Core] Upload Cucumber Reports with Gzip encoding ([#3115](https://github.com/cucumber/cucumber-jvm/pull/3115))
1315

1416
## [7.32.0] - 2025-11-21
1517
### Changed

cucumber-core/src/main/java/io/cucumber/core/plugin/UrlOutputStream.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Map.Entry;
2020
import java.util.Optional;
2121
import java.util.stream.Collectors;
22+
import java.util.zip.GZIPOutputStream;
2223

2324
import static java.nio.charset.StandardCharsets.UTF_8;
2425
import static java.nio.file.Files.newOutputStream;
@@ -90,6 +91,7 @@ private Optional<String> sendRequest(Proxy proxy, URL url, HttpMethod method, bo
9091
sendRequest(option.getProxy(), new URL(location), CurlOption.HttpMethod.PUT, false);
9192
}
9293
} else {
94+
urlConnection.setRequestProperty("Content-Encoding", "gzip");
9395
urlConnection.setDoOutput(true);
9496
sendRequestBody(urlConnection, requestHeaders, temp);
9597
getResponseBody(urlConnection, requestHeaders);
@@ -108,7 +110,7 @@ private static HttpURLConnection openConnection(Proxy proxy, URL url, HttpMethod
108110
private static void sendRequestBody(
109111
HttpURLConnection urlConnection, Map<String, List<String>> requestHeaders, Path requestBody
110112
) throws IOException {
111-
try (OutputStream outputStream = urlConnection.getOutputStream()) {
113+
try (OutputStream outputStream = new GZIPOutputStream(urlConnection.getOutputStream())) {
112114
Files.copy(requestBody, outputStream);
113115
} catch (IOException e) {
114116
String method = urlConnection.getRequestMethod();

cucumber-core/src/test/java/io/cucumber/core/plugin/UrlOutputStreamTest.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@
1414
import org.junit.jupiter.api.Test;
1515
import org.junit.jupiter.api.extension.ExtendWith;
1616

17+
import java.io.ByteArrayInputStream;
18+
import java.io.ByteArrayOutputStream;
1719
import java.io.IOException;
1820
import java.io.OutputStream;
1921
import java.io.Writer;
2022
import java.net.ServerSocket;
23+
import java.nio.charset.StandardCharsets;
2124
import java.util.concurrent.TimeUnit;
2225
import java.util.stream.Collectors;
2326
import java.util.stream.IntStream;
27+
import java.util.zip.GZIPInputStream;
2428

2529
import static java.lang.String.format;
2630
import static org.hamcrest.MatcherAssert.assertThat;
@@ -100,7 +104,6 @@ void it_sends_the_body_once_for_202_and_location_with_get_without_token(Vertx ve
100104
if (exception != null) {
101105
throw exception;
102106
}
103-
assertThat(testServer.receivedBody.toString("utf-8"), is(equalTo(requestBody)));
104107
}
105108

106109
@Test
@@ -225,11 +228,10 @@ public void start(Promise<Void> startPromise) {
225228

226229
ctx.request().handler(receivedBody::appendBuffer);
227230
ctx.request().endHandler(e -> {
228-
String receivedBodyString = receivedBody.toString("utf-8");
229231
ctx.response().setChunked(true);
230232
ctx.response().write(responseBody);
231233
ctx.response().end();
232-
testContext.verify(() -> assertThat(receivedBodyString, is(equalTo(expectedBody))));
234+
testContext.verify(() -> assertThat(unzipBody(), is(equalTo(expectedBody))));
233235
});
234236
});
235237
});
@@ -239,6 +241,21 @@ public void start(Promise<Void> startPromise) {
239241
.listen(port, e -> startPromise.complete());
240242
}
241243

244+
private String unzipBody() {
245+
ByteArrayOutputStream out = new ByteArrayOutputStream();
246+
ByteArrayInputStream compressedIn = new ByteArrayInputStream(receivedBody.getBytes());
247+
byte[] buffer = new byte[4096];
248+
try (GZIPInputStream uncompressedIn = new GZIPInputStream(compressedIn)) {
249+
int read;
250+
while ((read = uncompressedIn.read(buffer, 0, buffer.length)) != -1) {
251+
out.write(buffer, 0, read);
252+
}
253+
} catch (IOException ex) {
254+
throw new IllegalStateException(ex);
255+
}
256+
return new String(out.toByteArray(), StandardCharsets.UTF_8);
257+
}
258+
242259
}
243260

244261
}

0 commit comments

Comments
 (0)