Add HttpServerTest for redirects
MODIFY
dd-java-agent/instrumentation/netty-4.0/src/test/groovy/Netty40ServerTest.groovy
dd-java-agent/instrumentation/netty-4.0/src/test/groovy/Netty40ServerTest.groovy
@@ -62,7 +62,7 @@ class Netty40ServerTest extends HttpServerTest<NettyHttpServerDecorator> {
break
case REDIRECT:
response = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(endpoint.status))
- response.headers().set(HttpHeaderNames.LOCATION, endpoint.body)
+ response.headers().set(HttpHeaders.Names.LOCATION, endpoint.body)
break
case EXCEPTION:
throw new Exception(endpoint.body)

MODIFY
dd-java-agent/instrumentation/servlet-2/src/main/java/datadog/trace/instrumentation/servlet2/StatusSavingHttpServletResponseWrapper.java
dd-java-agent/instrumentation/servlet-2/src/main/java/datadog/trace/instrumentation/servlet2/StatusSavingHttpServletResponseWrapper.java
@@ -23,6 +23,12 @@ public class StatusSavingHttpServletResponseWrapper extends HttpServletResponseW
super.sendError(status, message);
}
+ @Override
+ public void sendRedirect(final String location) throws IOException {
+ status = 302;
+ super.sendRedirect(location);
+ }
+
@Override
public void setStatus(final int status) {
this.status = status;

MODIFY
dd-java-agent/instrumentation/vertx/src/test/groovy/server/VertxHttpServerTest.groovy
dd-java-agent/instrumentation/vertx/src/test/groovy/server/VertxHttpServerTest.groovy
@@ -85,7 +85,7 @@ class VertxHttpServerTest extends HttpServerTest<NettyHttpServerDecorator> {
}
router.route(REDIRECT.path).handler { ctx ->
controller(REDIRECT) {
- ctx.response().setStatusCode(REDIRECT.status).putHeader("location", REDIRECT.body)
+ ctx.response().setStatusCode(REDIRECT.status).putHeader("location", REDIRECT.body).end()
}
}
router.route(ERROR.path).handler { ctx ->

MODIFY
dd-java-agent/instrumentation/vertx/src/test/groovy/server/VertxRxCircuitBreakerHttpServerTest.groovy
dd-java-agent/instrumentation/vertx/src/test/groovy/server/VertxRxCircuitBreakerHttpServerTest.groovy
@@ -56,7 +56,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxHttpServerTest {
}
HttpServerTest.ServerEndpoint endpoint = it.result()
controller(endpoint) {
- ctx.response().setStatusCode(endpoint.status).putHeader("location", endpoint.body)
+ ctx.response().setStatusCode(endpoint.status).putHeader("location", endpoint.body).end()
}
}
}

MODIFY
dd-java-agent/instrumentation/vertx/src/test/groovy/server/VertxRxHttpServerTest.groovy
dd-java-agent/instrumentation/vertx/src/test/groovy/server/VertxRxHttpServerTest.groovy
@@ -31,7 +31,7 @@ class VertxRxHttpServerTest extends VertxHttpServerTest {
}
router.route(REDIRECT.path).handler { ctx ->
controller(REDIRECT) {
- ctx.response().setStatusCode(REDIRECT.status).putHeader("location", REDIRECT.body)
+ ctx.response().setStatusCode(REDIRECT.status).putHeader("location", REDIRECT.body).end()
}
}
router.route(ERROR.path).handler { ctx ->

MODIFY
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy
@@ -78,7 +78,7 @@ abstract class HttpServerTest<DECORATOR extends HttpServerDecorator> extends Age
enum ServerEndpoint {
SUCCESS("success", 200, "success"),
- REDIRECT("redirect", 302, null),
+ REDIRECT("redirect", 302, "/redirected"),
ERROR("error", 500, "controller error"),
EXCEPTION("exception", 500, "controller exception"),
NOT_FOUND("notFound", 404, "not found"),
@@ -184,6 +184,30 @@ abstract class HttpServerTest<DECORATOR extends HttpServerDecorator> extends Age
body = null
}
+ def "test redirect"() {
+ setup:
+ def request = request(REDIRECT, method, body).build()
+ def response = client.newCall(request).execute()
+
+ expect:
+ response.code() == REDIRECT.status
+ response.header("location") == REDIRECT.body ||
+ response.header("location") == "${address.resolve(REDIRECT.body)}"
+ response.body().contentLength() < 1
+
+ and:
+ cleanAndAssertTraces(1) {
+ trace(0, 2) {
+ serverSpan(it, 0, null, null, method, REDIRECT)
+ controllerSpan(it, 1, span(0))
+ }
+ }
+
+ where:
+ method = "GET"
+ body = null
+ }
+
def "test error"() {
setup:
def request = request(ERROR, method, body).build()

MODIFY
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/utils/OkHttpUtils.groovy
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/utils/OkHttpUtils.groovy
@@ -15,6 +15,6 @@ class OkHttpUtils {
}
static client() {
- clientBuilder().build()
+ clientBuilder().followRedirects(false).build()
}
}

Add HttpServerTest for redirects