From 28c7c30af4f2e3f399acb7875c6e29865b2b2684 Mon Sep 17 00:00:00 2001 From: Nikolay Martynov Date: Thu, 7 Jun 2018 12:11:47 -0400 Subject: [PATCH] [HttpUrlConnection] Fix HEAD responses Explain to ratpack that sending body for HEAD requests is not up to spec [1] and seems to be confusing to clients. This resolves 'Keep-Alive' mistery and makes disabling 'keepa-live' unnecessary. [1] https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html --- .../src/test/groovy/HttpUrlConnectionTest.groovy | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/dd-java-agent/instrumentation/http-url-connection/src/test/groovy/HttpUrlConnectionTest.groovy b/dd-java-agent/instrumentation/http-url-connection/src/test/groovy/HttpUrlConnectionTest.groovy index 539df1247d..bc22900667 100644 --- a/dd-java-agent/instrumentation/http-url-connection/src/test/groovy/HttpUrlConnectionTest.groovy +++ b/dd-java-agent/instrumentation/http-url-connection/src/test/groovy/HttpUrlConnectionTest.groovy @@ -19,7 +19,6 @@ import static ratpack.http.HttpMethod.POST class HttpUrlConnectionTest extends AgentTestRunner { static { System.setProperty("dd.integration.httpurlconnection.enabled", "true") - System.setProperty("http.keepAlive", "false") } @Shared @@ -43,8 +42,14 @@ class HttpUrlConnectionTest extends AgentTestRunner { scope.close() } - request.body.then { - response.status(200).send(msg) + response.status(200) + // Ratpack seems to be sending body with HEAD requests - RFC specifically forbids this. + // This becomes a major problem with keep-alived requests - client seems to fail to parse + // such response peroperly messing up following requests. + if (request.method.isHead()) { + response.send() + } else { + response.send(msg) } } }