use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder in project apollo by spotify.
the class ApolloRequestHandlerTest method mockRequest.
private MockHttpServletRequest mockRequest(String method, String requestURI, Map<String, String> headers) {
QueryStringDecoder decoder = new QueryStringDecoder(requestURI);
final MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(method, decoder.path());
mockHttpServletRequest.setParameters(decoder.parameters().entrySet().stream().collect(toMap(Map.Entry::getKey, e -> {
List<String> value = e.getValue();
return value.toArray(new String[value.size()]);
})));
mockHttpServletRequest.setQueryString(requestURI.replace(decoder.path() + "?", ""));
headers.forEach(mockHttpServletRequest::addHeader);
mockHttpServletRequest.setProtocol("HTTP/1.1");
mockHttpServletRequest.setRemoteHost("123.45.67.89");
mockHttpServletRequest.setRemoteAddr("123.45.67.89");
mockHttpServletRequest.setRemotePort(8734);
return mockHttpServletRequest;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder in project flink by apache.
the class HttpRequestHandler method channelRead0.
@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) {
try {
if (msg instanceof HttpRequest) {
currentRequest = (HttpRequest) msg;
currentRequestPath = null;
if (currentDecoder != null) {
currentDecoder.destroy();
currentDecoder = null;
}
if (currentRequest.getMethod() == HttpMethod.GET || currentRequest.getMethod() == HttpMethod.DELETE) {
// directly delegate to the router
ctx.fireChannelRead(currentRequest);
} else if (currentRequest.getMethod() == HttpMethod.POST) {
// POST comes in multiple objects. First the request, then the contents
// keep the request and path for the remaining objects of the POST request
currentRequestPath = new QueryStringDecoder(currentRequest.getUri(), ENCODING).path();
currentDecoder = new HttpPostRequestDecoder(DATA_FACTORY, currentRequest, ENCODING);
} else {
throw new IOException("Unsupported HTTP method: " + currentRequest.getMethod().name());
}
} else if (currentDecoder != null && msg instanceof HttpContent) {
// received new chunk, give it to the current decoder
HttpContent chunk = (HttpContent) msg;
currentDecoder.offer(chunk);
try {
while (currentDecoder.hasNext()) {
InterfaceHttpData data = currentDecoder.next();
if (data.getHttpDataType() == HttpDataType.FileUpload && tmpDir != null) {
DiskFileUpload file = (DiskFileUpload) data;
if (file.isCompleted()) {
String name = file.getFilename();
File target = new File(tmpDir, UUID.randomUUID() + "_" + name);
if (!tmpDir.exists()) {
logExternalUploadDirDeletion(tmpDir);
checkAndCreateUploadDir(tmpDir);
}
file.renameTo(target);
QueryStringEncoder encoder = new QueryStringEncoder(currentRequestPath);
encoder.addParam("filepath", target.getAbsolutePath());
encoder.addParam("filename", name);
currentRequest.setUri(encoder.toString());
}
}
}
} catch (EndOfDataDecoderException ignored) {
}
if (chunk instanceof LastHttpContent) {
HttpRequest request = currentRequest;
currentRequest = null;
currentRequestPath = null;
currentDecoder.destroy();
currentDecoder = null;
// fire next channel handler
ctx.fireChannelRead(request);
}
} else {
ctx.fireChannelRead(ReferenceCountUtil.retain(msg));
}
} catch (Throwable t) {
currentRequest = null;
currentRequestPath = null;
if (currentDecoder != null) {
currentDecoder.destroy();
currentDecoder = null;
}
if (ctx.channel().isActive()) {
byte[] bytes = ExceptionUtils.stringifyException(t).getBytes(ENCODING);
DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR, Unpooled.wrappedBuffer(bytes));
response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/plain");
response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, response.content().readableBytes());
ctx.writeAndFlush(response);
}
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder in project netty by netty.
the class Http2RequestHandler method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
QueryStringDecoder queryString = new QueryStringDecoder(request.uri());
String streamId = streamId(request);
int latency = toInt(firstValue(queryString, LATENCY_FIELD_NAME), 0);
if (latency < MIN_LATENCY || latency > MAX_LATENCY) {
sendBadRequest(ctx, streamId);
return;
}
String x = firstValue(queryString, IMAGE_COORDINATE_X);
String y = firstValue(queryString, IMAGE_COORDINATE_Y);
if (x == null || y == null) {
handlePage(ctx, streamId, latency, request);
} else {
handleImage(x, y, ctx, streamId, latency, request);
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder in project moco by dreamhead.
the class DefaultHttpRequest method newRequest.
public static HttpRequest newRequest(final FullHttpRequest request) {
QueryStringDecoder decoder = new QueryStringDecoder(request.uri());
ImmutableMap<String, String[]> queries = toQueries(decoder);
return builder().withVersion(HttpProtocolVersion.versionOf(request.protocolVersion().text())).withHeaders(toHeaders(request)).withMethod(HttpMethod.valueOf(request.method().toString().toUpperCase())).withUri(decoder.path()).withQueries(queries).withContent(toMessageContent(request)).build();
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder in project crate by crate.
the class SqlHttpHandler method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) {
if (request.uri().startsWith("/_sql")) {
Session session = ensureSession(request);
Map<String, List<String>> parameters = new QueryStringDecoder(request.uri()).parameters();
ByteBuf content = request.content();
handleSQLRequest(session, content, paramContainFlag(parameters, "types")).whenComplete((result, t) -> {
try {
sendResponse(session, ctx, request, parameters, result, t);
} catch (Throwable ex) {
LOGGER.error("Error sending response", ex);
throw ex;
} finally {
request.release();
}
});
} else {
ctx.fireChannelRead(request);
}
}
Aggregations