@@ -308,6 +308,66 @@ public void getJson()
308
308
}
309
309
}
310
310
311
+ @ Test
312
+ public void getGzipResponse ()
313
+ throws IOException , TimeoutException , InterruptedException , ExecutionException {
314
+
315
+ Response response = doGetRequest ("http://httpbin.org/gzip" , headers );
316
+
317
+ Assertions .assertEquals (200 , response .statusCode );
318
+
319
+ // Verify that the response contains the expected structure received from httpbin server gzip
320
+ // response
321
+ Assertions .assertTrue (response .body .contains ("\" gzipped\" : true" ));
322
+ Assertions .assertTrue (response .body .contains ("\" method\" : \" GET\" " ));
323
+ Assertions .assertTrue (response .body .contains ("\" Host\" : \" httpbin.org\" " ));
324
+
325
+ TEST_WRITER .waitForTraces (1 );
326
+ List <List <Span >> traces ;
327
+ if (hasResponseBodySpan ) {
328
+ traces =
329
+ TEST_WRITER .waitForSpans (
330
+ 2 , span -> span .getKind ().equals (Span .SpanKind .SPAN_KIND_SERVER ));
331
+ } else {
332
+ traces =
333
+ TEST_WRITER .waitForSpans (
334
+ 1 ,
335
+ span ->
336
+ !span .getKind ().equals (Span .SpanKind .SPAN_KIND_CLIENT )
337
+ || span .getAttributesList ().stream ()
338
+ .noneMatch (
339
+ keyValue ->
340
+ keyValue .getKey ().equals ("http.url" )
341
+ && keyValue .getValue ().getStringValue ().contains ("/gzip" )));
342
+ }
343
+
344
+ Assertions .assertEquals (1 , traces .size ());
345
+ Span clientSpan = traces .get (0 ).get (0 );
346
+ if (hasResponseBodySpan ) {
347
+ Assertions .assertEquals (2 , traces .get (0 ).size ());
348
+ Span responseBodySpan = traces .get (0 ).get (1 );
349
+ if (traces .get (0 ).get (1 ).getKind ().equals (Span .SpanKind .SPAN_KIND_CLIENT )) {
350
+ responseBodySpan = traces .get (0 ).get (0 );
351
+ }
352
+ Assertions .assertNull (TEST_WRITER .getAttributesMap (clientSpan ).get ("http.request.body" ));
353
+
354
+ String respBodyCapturedInSpan =
355
+ TEST_WRITER .getAttributesMap (responseBodySpan ).get ("http.response.body" ).getStringValue ();
356
+ Assertions .assertTrue (respBodyCapturedInSpan .contains ("\" gzipped\" : true" ));
357
+ Assertions .assertTrue (respBodyCapturedInSpan .contains ("\" method\" : \" GET\" " ));
358
+ Assertions .assertTrue (respBodyCapturedInSpan .contains ("\" Host\" : \" httpbin.org\" " ));
359
+ } else {
360
+ Assertions .assertNull (TEST_WRITER .getAttributesMap (clientSpan ).get ("http.request.body" ));
361
+
362
+ Assertions .assertEquals (1 , traces .get (0 ).size ());
363
+ String respBodyCapturedInSpan =
364
+ TEST_WRITER .getAttributesMap (clientSpan ).get ("http.response.body" ).getStringValue ();
365
+ Assertions .assertTrue (respBodyCapturedInSpan .contains ("\" gzipped\" : true" ));
366
+ Assertions .assertTrue (respBodyCapturedInSpan .contains ("\" method\" : \" GET\" " ));
367
+ Assertions .assertTrue (respBodyCapturedInSpan .contains ("\" Host\" : \" httpbin.org\" " ));
368
+ }
369
+ }
370
+
311
371
private void assertHeaders (Span span ) {
312
372
Assertions .assertEquals (
313
373
TestHttpServer .RESPONSE_HEADER_VALUE ,
0 commit comments