Skip to content

Commit

Permalink
Merge pull request #815 from msfm/master_UNDERTOW-1599
Browse files Browse the repository at this point in the history
UNDERTOW-1599 ServletRequestLineAttribute does not output the origina…
  • Loading branch information
fl4via committed Oct 15, 2019
2 parents dac98b1 + 6164d0c commit a27934e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
import io.undertow.attribute.ExchangeAttribute;
import io.undertow.attribute.ExchangeAttributeBuilder;
import io.undertow.attribute.ReadOnlyAttributeException;
import io.undertow.attribute.RequestLineAttribute;
import io.undertow.server.HttpServerExchange;
import io.undertow.servlet.handlers.ServletRequestContext;

import javax.servlet.RequestDispatcher;

/**
* The request line
Expand All @@ -41,11 +45,19 @@ private ServletRequestLineAttribute() {

@Override
public String readAttribute(final HttpServerExchange exchange) {
ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
if (src == null) {
return RequestLineAttribute.INSTANCE.readAttribute(exchange);
}
StringBuilder sb = new StringBuilder()
.append(exchange.getRequestMethod().toString())
.append(' ')
.append(ServletRequestURLAttribute.INSTANCE.readAttribute(exchange));
if (!exchange.getQueryString().isEmpty()) {
String query = (String) src.getServletRequest().getAttribute(RequestDispatcher.FORWARD_QUERY_STRING);
if (query != null && !query.isEmpty()) {
sb.append('?');
sb.append(query);
} else if (!exchange.getQueryString().isEmpty()) {
sb.append('?');
sb.append(exchange.getQueryString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,31 @@ public void testPathBasedStaticIncludePost() throws IOException {


@Test
public void testIncludeAggregatesQueryString() throws IOException {
public void testIncludeAggregatesQueryString() throws IOException, InterruptedException {
TestHttpClient client = new TestHttpClient();
String protocol = DefaultServer.isH2() ? Protocols.HTTP_2_0_STRING : Protocols.HTTP_1_1_STRING;
try {
resetLatch();
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/dispatch?a=b");
get.setHeader("forward", "/path");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("pathInfo:null queryString:a=b servletPath:/path requestUri:/servletContext/path", response);
latch.await(30, TimeUnit.SECONDS);
//UNDERTOW-327 and UNDERTOW-1599 - make sure that the access log includes the original path and query string
Assert.assertEquals("GET /servletContext/dispatch?a=b " + protocol + " /servletContext/dispatch /dispatch", message);

resetLatch();
get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/dispatch?a=b");
get.setHeader("forward", "/path?foo=bar");
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertEquals("pathInfo:null queryString:foo=bar servletPath:/path requestUri:/servletContext/path", response);
latch.await(30, TimeUnit.SECONDS);
//UNDERTOW-327 and UNDERTOW-1599 - make sure that the access log includes the original path and query string
Assert.assertEquals("GET /servletContext/dispatch?a=b " + protocol + " /servletContext/dispatch /dispatch", message);
} finally {
client.getConnectionManager().shutdown();
}
Expand Down

0 comments on commit a27934e

Please sign in to comment.