Skip to content

Commit

Permalink
getUri() return path with query strings (#329)
Browse files Browse the repository at this point in the history
Fixes #298
  • Loading branch information
n0tl3ss authored May 18, 2022
1 parent 57dce09 commit 4b3e4a2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import io.micronaut.http.HttpResponse
import io.micronaut.http.HttpStatus
import io.micronaut.http.annotation.Body
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.micronaut.http.annotation.Post
import io.micronaut.http.client.HttpClient
import io.micronaut.http.client.annotation.Client
Expand All @@ -33,6 +34,16 @@ class TomcatResponseSpec extends Specification {
response.body() == null
}

@Issue("https://github.com/micronaut-projects/micronaut-servlet/issues/298")
void 'verify that controller\'s HttpRequest object contains valid URI'() {
when:
def response = client.toBlocking().exchange(HttpRequest.GET("/response/test/hello?a=1&b=2"), String)

then:
response.status() == HttpStatus.OK
response.body() == "/response/test/hello?a=1&b=2"
}

@Requires(property = 'spec.name', value = 'TomcatResponseSpec')
@Controller("/response/test")
static class FooController {
Expand All @@ -41,5 +52,10 @@ class TomcatResponseSpec extends Specification {
HttpResponse bar(@Body String json) {
HttpResponse.ok()
}

@Get("/hello")
String hello(HttpRequest<?> httpRequest) {
return httpRequest.getUri().toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ protected DefaultServletHttpRequest(
requestURI = requestURI.substring(contextPath.length());
}

String queryString = delegate.getQueryString();
if (StringUtils.isNotEmpty(queryString)) {
requestURI = requestURI + "?" + queryString;
}

this.uri = URI.create(requestURI);
HttpMethod method;
try {
Expand Down

0 comments on commit 4b3e4a2

Please sign in to comment.