Search in sources :

Example 76 with QueryStringDecoder

use of io.netty.handler.codec.http.QueryStringDecoder in project vertx-web by vert-x3.

the class ValidationHandlerImpl method validateCookieParams.

private Future<Map<String, RequestParameter>> validateCookieParams(RoutingContext routingContext) {
    // Validation process validate only params that are registered in the validation -> extra params are allowed
    Map<String, List<String>> cookies = new HashMap<>();
    if (routingContext.request().headers().contains("Cookie")) {
        // Some hack to reuse QueryStringDecoder
        QueryStringDecoder decoder = new QueryStringDecoder("/?" + routingContext.request().getHeader("Cookie"));
        for (Map.Entry<String, List<String>> entry : decoder.parameters().entrySet()) {
            cookies.merge(entry.getKey().trim(), entry.getValue(), (oldValue, newValue) -> {
                oldValue.addAll(newValue);
                return oldValue;
            });
        }
    }
    Map<String, RequestParameter> parsedParams = new HashMap<>();
    return processParams(parsedParams, cookies, cookieParameters, false);
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder)

Example 77 with QueryStringDecoder

use of io.netty.handler.codec.http.QueryStringDecoder in project vertx-web by vert-x3.

the class RoutingContextImpl method getQueryParams.

private MultiMap getQueryParams(Charset charset) {
    // Check if query params are already parsed
    if (charset != null || queryParams == null) {
        try {
            // Decode query parameters and put inside context.queryParams
            if (charset == null) {
                queryParams = MultiMap.caseInsensitiveMultiMap();
                Map<String, List<String>> decodedParams = new QueryStringDecoder(request.uri()).parameters();
                for (Map.Entry<String, List<String>> entry : decodedParams.entrySet()) {
                    queryParams.add(entry.getKey(), entry.getValue());
                }
            } else {
                MultiMap queryParams = MultiMap.caseInsensitiveMultiMap();
                Map<String, List<String>> decodedParams = new QueryStringDecoder(request.uri(), charset).parameters();
                for (Map.Entry<String, List<String>> entry : decodedParams.entrySet()) {
                    queryParams.add(entry.getKey(), entry.getValue());
                }
                return queryParams;
            }
        } catch (IllegalArgumentException e) {
            throw new HttpException(400, "Error while decoding query params", e);
        }
    }
    return queryParams;
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) HttpException(io.vertx.ext.web.handler.HttpException)

Aggregations

QueryStringDecoder (io.netty.handler.codec.http.QueryStringDecoder)74 List (java.util.List)30 Test (org.junit.Test)15 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)14 Map (java.util.Map)11 HashMap (java.util.HashMap)9 IOException (java.io.IOException)8 URI (java.net.URI)7 ByteBuf (io.netty.buffer.ByteBuf)6 HttpContent (io.netty.handler.codec.http.HttpContent)6 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)6 HttpPostRequestDecoder (io.netty.handler.codec.http.multipart.HttpPostRequestDecoder)6 ArrayList (java.util.ArrayList)6 HttpMethod (io.netty.handler.codec.http.HttpMethod)5 HttpRequest (io.netty.handler.codec.http.HttpRequest)5 DeviceSession (org.traccar.DeviceSession)5 Position (org.traccar.model.Position)5 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)4 Channel (io.netty.channel.Channel)3 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)3