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);
}
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;
}
Aggregations