Add http client test for chunked responses
MODIFY
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/base/HttpClientTest.groovy
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/base/HttpClientTest.groovy
@@ -51,6 +51,14 @@ abstract class HttpClientTest<DECORATOR extends HttpClientDecorator> extends Age
handleDistributedRequest()
redirect(server.address.resolve("/circular-redirect").toURL().toString())
}
+ prefix("chunked-response") {
+ handleDistributedRequest()
+ response.status(200)
+ .startChunked()
+ .sendChunk("first part")
+ .sendChunk("-second part")
+ .finishChunks()
+ }
}
}
@@ -139,6 +147,26 @@ abstract class HttpClientTest<DECORATOR extends HttpClientDecorator> extends Age
method = "HEAD"
}
+ def "handle chunked response"() {
+ when:
+ def status = runUnderTrace("parent") {
+ doRequest(method, server.address.resolve("/chunked-response"))
+ }
+
+ then:
+ status == 200
+ assertTraces(2) {
+ server.distributedRequestTrace(it, 0, trace(1).last())
+ trace(1, size(2)) {
+ basicSpan(it, 0, "parent")
+ clientSpan(it, 1, span(0), method, false, false, server.address.resolve("/chunked-response"))
+ }
+ }
+
+ where:
+ method << BODY_METHODS
+ }
+
def "trace request without propagation"() {
when:
def status = withConfigOverride(Config.HTTP_CLIENT_HOST_SPLIT_BY_DOMAIN, "$renameService") {

MODIFY
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/server/http/TestHttpServer.groovy
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/server/http/TestHttpServer.groovy
@@ -302,6 +302,29 @@ class TestHttpServer implements AutoCloseable {
resp.setContentLength(body.bytes.length)
resp.writer.print(body)
}
+
+ ResponseApi startChunked() {
+ assert !req.handled
+ resp.setHeader("Transfer-Encoding", "chunked")
+ resp.status = status
+ return this
+ }
+
+ ResponseApi sendChunk(String partial) {
+ assert !req.handled
+ resp.writer.print(Integer.toHexString(partial.length()).toUpperCase())
+ resp.writer.print("\r\n")
+ resp.writer.print(partial)
+ resp.writer.print("\r\n")
+ resp.writer.flush()
+ return this
+ }
+
+ void finishChunks() {
+ resp.writer.print("0\r\n\r\n")
+ resp.writer.flush()
+ req.handled = true
+ }
}
static class Headers {

Add http client test for chunked responses