Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

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

## [7.32.0] - 2025-11-21
### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.zip.GZIPOutputStream;

import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.Files.newOutputStream;
Expand Down Expand Up @@ -90,6 +91,7 @@ private Optional<String> sendRequest(Proxy proxy, URL url, HttpMethod method, bo
sendRequest(option.getProxy(), new URL(location), CurlOption.HttpMethod.PUT, false);
}
} else {
urlConnection.setRequestProperty("Content-Encoding", "gzip");
urlConnection.setDoOutput(true);
sendRequestBody(urlConnection, requestHeaders, temp);
getResponseBody(urlConnection, requestHeaders);
Expand All @@ -108,7 +110,7 @@ private static HttpURLConnection openConnection(Proxy proxy, URL url, HttpMethod
private static void sendRequestBody(
HttpURLConnection urlConnection, Map<String, List<String>> requestHeaders, Path requestBody
) throws IOException {
try (OutputStream outputStream = urlConnection.getOutputStream()) {
try (OutputStream outputStream = new GZIPOutputStream(urlConnection.getOutputStream())) {
Files.copy(requestBody, outputStream);
} catch (IOException e) {
String method = urlConnection.getRequestMethod();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
import java.net.ServerSocket;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.zip.GZIPInputStream;

import static java.lang.String.format;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -100,7 +104,6 @@ void it_sends_the_body_once_for_202_and_location_with_get_without_token(Vertx ve
if (exception != null) {
throw exception;
}
assertThat(testServer.receivedBody.toString("utf-8"), is(equalTo(requestBody)));
}

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

ctx.request().handler(receivedBody::appendBuffer);
ctx.request().endHandler(e -> {
String receivedBodyString = receivedBody.toString("utf-8");
ctx.response().setChunked(true);
ctx.response().write(responseBody);
ctx.response().end();
testContext.verify(() -> assertThat(receivedBodyString, is(equalTo(expectedBody))));
testContext.verify(() -> assertThat(unzipBody(), is(equalTo(expectedBody))));
});
});
});
Expand All @@ -239,6 +241,21 @@ public void start(Promise<Void> startPromise) {
.listen(port, e -> startPromise.complete());
}

private String unzipBody() {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream compressedIn = new ByteArrayInputStream(receivedBody.getBytes());
byte[] buffer = new byte[4096];
try (GZIPInputStream uncompressedIn = new GZIPInputStream(compressedIn)) {
int read;
while ((read = uncompressedIn.read(buffer, 0, buffer.length)) != -1) {
out.write(buffer, 0, read);
}
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
return new String(out.toByteArray(), StandardCharsets.UTF_8);
}

}

}