-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from nstdio/use-inflater
fix: Use InflaterInputStream when compression is deflate.
- Loading branch information
Showing
5 changed files
with
35 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 18 additions & 11 deletions
29
src/test/java/com/github/nstdio/http/ext/DecompressingBodyHandlerIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
package com.github.nstdio.http.ext; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static com.github.nstdio.http.ext.BodyHandlers.ofDecompressing; | ||
import static com.jayway.jsonpath.matchers.JsonPathMatchers.*; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import java.net.URI; | ||
import java.net.http.HttpClient; | ||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpResponse; | ||
import java.time.Duration; | ||
|
||
class DecompressingBodyHandlerIntegrationTest { | ||
|
||
private final HttpClient httpClient = HttpClient.newBuilder() | ||
.connectTimeout(Duration.ofSeconds(2)) | ||
.build(); | ||
private final HttpClient httpClient = HttpClient.newHttpClient(); | ||
private final URI baseUri = URI.create("https://httpbin.org/"); | ||
|
||
@Test | ||
void shouldCreate() throws Exception { | ||
@ParameterizedTest | ||
@ValueSource(strings = {"gzip", "deflate"}) | ||
void shouldCreate(String compression) throws Exception { | ||
//given | ||
var request = HttpRequest.newBuilder(baseUri.resolve("gzip")) | ||
var request = HttpRequest.newBuilder(baseUri.resolve(compression)) | ||
.build(); | ||
|
||
var body = httpClient.send(request, HttpResponse.BodyHandlers.ofString()).body(); | ||
var body2 = httpClient.send(request, BodyHandlers.ofDecompressing()).body(); | ||
//when | ||
var body = httpClient.send(request, ofDecompressing()).body(); | ||
var json = IOUtils.toString(body); | ||
|
||
//then | ||
assertThat(json, isJson()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters