List of usage examples for io.netty.handler.codec.http QueryStringDecoder decodeComponent
public static String decodeComponent(final String s, final Charset charset)
From source file:io.advantageous.conekt.http.impl.HttpServerRequestImpl.java
License:Open Source License
private static String urlDecode(String str) { return QueryStringDecoder.decodeComponent(str, CharsetUtil.UTF_8); }
From source file:io.gravitee.gateway.handlers.api.path.impl.AbstractPathResolver.java
License:Apache License
@Override public Path resolve(final String path) { if (registeredPaths.size() == 1) { return registeredPaths.get(0); }//from w w w.j a v a 2s .c o m String decodedPath; try { decodedPath = QueryStringDecoder.decodeComponent(path, Charset.defaultCharset()); } catch (IllegalArgumentException iae) { decodedPath = path; } int pieces = -1; Path bestPath = null; // TODO PERF: We must navigate from the longest path to the shortest to avoid counting pieces. for (Path registerPath : registeredPaths) { if (registerPath.getPattern().matcher(decodedPath).lookingAt()) { int split = registerPath.getPath().split(URL_PATH_SEPARATOR).length; if (split > pieces) { pieces = split; bestPath = registerPath; } } } return bestPath; }
From source file:nikoladasm.aspark.server.ServerHandler.java
License:Open Source License
private void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest nettyRequest) throws Exception { boolean decoderResult = nettyRequest.getDecoderResult().isSuccess(); HttpVersion version = nettyRequest.getProtocolVersion(); boolean keepAlive = isKeepAlive(nettyRequest); if (decoderResult) { String uri = QueryStringDecoder.decodeComponent(nettyRequest.getUri(), CharsetUtil.UTF_8); QueryStringDecoder queryStringDecoder = new QueryStringDecoder(uri); String path = sanitizePath(queryStringDecoder.path()); String httpMethodOverrideName = nettyRequest.headers().get("X-HTTP-Method-Override"); String httpMethodName = (httpMethodOverrideName == null) ? nettyRequest.getMethod().name() : httpMethodOverrideName; HttpMethod httpMethod = HttpMethod.valueOf(httpMethodName.toUpperCase()); HttpMethod originalHttpMethod = HttpMethod.valueOf(nettyRequest.getMethod().name().toUpperCase()); Map<String, List<String>> postAttr = getPostAttributes(originalHttpMethod, nettyRequest); RequestImpl request = new RequestImpl(nettyRequest, queryStringDecoder, originalHttpMethod, httpMethod, postAttr, path, port, ipAddress, version); ResponseImpl response = new ResponseImpl(ctx, version, keepAlive, httpMethod, serverName); pool.execute(() -> {// w ww. j av a 2s . c om try { boolean processed = WebSocketHandshake(originalHttpMethod, path, nettyRequest, ctx); if (processed) return; dispatcher.process(request, response); response.send(); } catch (Exception e) { LOG.warn("Exception ", e); if (e instanceof HaltException) { sendResponse(ctx, version, HttpResponseStatus.valueOf(((HaltException) e).status()), keepAlive, ((HaltException) e).body()); return; } ExceptionHandler handler = exceptionMap.get(e.getClass()); if (handler != null) { handler.handle(e, request, response); try { if (response.inputStream() != null) { response.inputStream().close(); response.inputStream(null); if (response.transformer() == null) response.transformer(DEFAULT_RESPONSE_TRANSFORMER); } response.send(); } catch (Exception exc) { sendResponse(ctx, version, INTERNAL_SERVER_ERROR, keepAlive, null); } return; } sendResponse(ctx, version, INTERNAL_SERVER_ERROR, keepAlive, null); } }); } else { sendResponse(ctx, version, BAD_REQUEST, keepAlive, null); } }