Skip to content

Commit 1997326

Browse files
author
Adrian Cole
committed
Fixes error accepting gzipped spans
The following test case was failing due to hidden invalid header errors: ```bash $ cat test_spans | gzip -c | curl -X POST -v --data-binary @- -H"Content-Encoding: gzip" -H"Content-Type: application/json" localhost:9411/api/v1/spans ``` Fixes openzipkin#1197
1 parent 56db806 commit 1997326

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

zipkin-server/src/main/java/zipkin/server/ZipkinHttpCollector.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
*/
1414
package zipkin.server;
1515

16+
import java.io.ByteArrayInputStream;
1617
import java.io.ByteArrayOutputStream;
1718
import java.io.IOException;
18-
import java.util.zip.DataFormatException;
19-
import java.util.zip.Inflater;
19+
import java.util.zip.GZIPInputStream;
2020
import org.springframework.beans.factory.annotation.Autowired;
2121
import org.springframework.http.HttpStatus;
2222
import org.springframework.http.ResponseEntity;
@@ -47,8 +47,8 @@ public class ZipkinHttpCollector {
4747
final CollectorMetrics metrics;
4848
final Collector collector;
4949

50-
@Autowired
51-
ZipkinHttpCollector(StorageComponent storage, CollectorSampler sampler, CollectorMetrics metrics) {
50+
@Autowired ZipkinHttpCollector(StorageComponent storage, CollectorSampler sampler,
51+
CollectorMetrics metrics) {
5252
this.metrics = metrics.forTransport("http");
5353
this.collector = Collector.builder(getClass())
5454
.storage(storage).sampler(sampler).metrics(this.metrics).build();
@@ -81,7 +81,8 @@ DeferredResult<ResponseEntity<?>> validateAndStoreSpans(String encoding, Codec c
8181
body = gunzip(body);
8282
} catch (IOException e) {
8383
metrics.incrementMessagesDropped();
84-
result.setResult(ResponseEntity.badRequest().body("Cannot gunzip spans\n"));
84+
result.setResult(
85+
ResponseEntity.badRequest().body("Cannot gunzip spans: " + e.getMessage() + "\n"));
8586
return result;
8687
}
8788
}
@@ -107,16 +108,14 @@ DeferredResult<ResponseEntity<?>> validateAndStoreSpans(String encoding, Codec c
107108
};
108109

109110
static byte[] gunzip(byte[] input) throws IOException {
110-
Inflater inflater = new Inflater();
111-
inflater.setInput(input);
111+
GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(input));
112112
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(input.length)) {
113-
while (!inflater.finished()) {
114-
int count = inflater.inflate(GZIP_BUFFER.get());
115-
outputStream.write(GZIP_BUFFER.get(), 0, count);
113+
byte[] buf = GZIP_BUFFER.get();
114+
int len;
115+
while ((len = in.read(buf)) > 0) {
116+
outputStream.write(buf, 0, len);
116117
}
117118
return outputStream.toByteArray();
118-
} catch (DataFormatException e) {
119-
throw new IOException(e.getMessage(), e);
120119
}
121120
}
122121
}

0 commit comments

Comments
 (0)