fix path parameters

This commit is contained in:
Jörg Prante 2020-09-02 13:55:36 +02:00
parent 97d6f4dc6a
commit ea640122d8
4 changed files with 42 additions and 3 deletions

View file

@ -1,6 +1,6 @@
group = org.xbib
name = netty-http
version = 4.1.51.4
version = 4.1.51.5
gradle.wrapper.version = 6.4.1
netty.version = 4.1.51.Final

View file

@ -27,7 +27,7 @@ import java.util.Map;
* being useful for message signing; it's not a general purpose collection class
* to handle request parameters.
*/
public class HttpParameters extends /*LinkedHashSetMultiMap<String, String>*/ CaseInsensitiveParameters {
public class HttpParameters extends CaseInsensitiveParameters {
private static final String EQUALS = "=";

View file

@ -92,7 +92,7 @@ public class HttpEndpoint implements Endpoint<HttpEndpointDescriptor> {
.setEndpointResolver(endpointResolver)
.setEndpoint((this))
.setContext(context);
String pattern = prefix + path;
String pattern = path;
String effectiveRequestPath = serverRequestBuilder.getEffectiveRequestPath();
if (pathMatcher.match(pattern, effectiveRequestPath)) {
QueryParameters queryParameters = pathMatcher.extractUriTemplateVariables(pattern, effectiveRequestPath);

View file

@ -30,6 +30,45 @@ class EndpointTest {
private static final Logger logger = Logger.getLogger(EndpointTest.class.getName());
@Test
void testPrefixPathParameter() throws Exception {
HttpAddress httpAddress = HttpAddress.http1("localhost", 8008);
HttpEndpointResolver httpEndpointResolver = HttpEndpointResolver.builder()
.setPrefix("/files")
.addEndpoint(HttpEndpoint.builder().setPath("/{mypath}").build())
.setDispatcher((req, resp) -> {
logger.log(Level.INFO, "dispatching endpoint = " + req.getEndpoint() +
" req = " + req +
" req context path = " + req.getContextPath() +
" effective path = " + req.getEffectiveRequestPath() +
" path params = " + req.getPathParameters());
assertEquals("test.txt", req.getPathParameters().get("mypath"));
})
.build();
HttpServerDomain domain = HttpServerDomain.builder(httpAddress)
.addEndpointResolver(httpEndpointResolver)
.build();
Server server = Server.builder(domain)
.build();
Client client = Client.builder()
.build();
final AtomicBoolean success = new AtomicBoolean(false);
try {
server.accept();
Request request = Request.get().setVersion(HttpVersion.HTTP_1_1)
.url(server.getServerConfig().getAddress().base().resolve("/files/test.txt"))
.setResponseListener(resp -> {
success.set(true);
})
.build();
client.execute(request).get();
} finally {
server.shutdownGracefully();
client.shutdownGracefully();
logger.log(Level.INFO, "server and client shut down");
}
}
@Test
void testEmptyPrefixEndpoint() throws Exception {
Path vartmp = Paths.get("/var/tmp/");