|
13 | 13 | import org.springframework.stereotype.Component;
|
14 | 14 |
|
15 | 15 | import javax.annotation.PreDestroy;
|
16 |
| -import java.io.InputStream; |
17 | 16 | import java.io.IOException;
|
| 17 | +import java.io.InputStream; |
18 | 18 | import java.io.UncheckedIOException;
|
19 | 19 | import java.lang.reflect.InvocationTargetException;
|
20 | 20 | import java.net.URI;
|
@@ -81,7 +81,6 @@ public void destroy() {
|
81 | 81 |
|
82 | 82 | public Response request(String path, Object message, Map<String, String> headers) throws IOException, InterruptedException {
|
83 | 83 | headers.putAll(HEADERS.get());
|
84 |
| - headers.remove("accept-encoding"); |
85 | 84 | LOG.info("Grpc request {}:\nHeaders: {}\nMessage:\n{}", path, headers, message);
|
86 | 85 | return new Response(
|
87 | 86 | httpClient.send(
|
@@ -118,16 +117,16 @@ public int streamSize() {
|
118 | 117 | }
|
119 | 118 |
|
120 | 119 | private String getBody() {
|
121 |
| - try { |
122 |
| - InputStream bodyStream = httpResponse.body(); |
123 |
| - if (httpResponse.headers().firstValue("Content-Encoding").orElse("").equals("gzip")) { |
124 |
| - bodyStream = new GZIPInputStream(bodyStream); |
125 |
| - } |
126 |
| - return new String(bodyStream.readAllBytes()); |
| 120 | + try (InputStream is = isGzip() ? new GZIPInputStream(httpResponse.body()) : httpResponse.body()) { |
| 121 | + return new String(is.readAllBytes()); |
127 | 122 | } catch (IOException e) {
|
128 | 123 | throw new UncheckedIOException(e);
|
129 | 124 | }
|
130 | 125 | }
|
| 126 | + |
| 127 | + private boolean isGzip() { |
| 128 | + return httpResponse.headers().firstValue("Content-Encoding").orElse("").equals("gzip"); |
| 129 | + } |
131 | 130 | }
|
132 | 131 |
|
133 | 132 | private HttpRequest.BodyPublisher asJson(Object arg) throws IOException {
|
|
0 commit comments