Search in sources :

Example 96 with HttpMethod

use of io.netty.handler.codec.http.HttpMethod in project flink by apache.

the class Router method allowedMethods.

/**
 * Returns allowed methods for a specific URI.
 *
 * <p>For {@code OPTIONS *}, use {@link #allAllowedMethods()} instead of this method.
 */
public Set<HttpMethod> allowedMethods(String uri) {
    QueryStringDecoder decoder = new QueryStringDecoder(uri);
    String[] tokens = PathPattern.removeSlashesAtBothEnds(decoder.path()).split("/");
    if (anyMethodRouter.anyMatched(tokens)) {
        return allAllowedMethods();
    }
    Set<HttpMethod> ret = new HashSet<HttpMethod>(routers.size());
    for (Map.Entry<HttpMethod, MethodlessRouter<T>> entry : routers.entrySet()) {
        MethodlessRouter<T> router = entry.getValue();
        if (router.anyMatched(tokens)) {
            HttpMethod method = entry.getKey();
            ret.add(method);
        }
    }
    return ret;
}
Also used : QueryStringDecoder(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder) Map(java.util.Map) HashMap(java.util.HashMap) HttpMethod(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod) HashSet(java.util.HashSet)

Example 97 with HttpMethod

use of io.netty.handler.codec.http.HttpMethod in project flink by apache.

the class RouterHandler method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext channelHandlerContext, HttpRequest httpRequest) {
    if (HttpHeaders.is100ContinueExpected(httpRequest)) {
        channelHandlerContext.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE));
        return;
    }
    // Route
    HttpMethod method = httpRequest.getMethod();
    QueryStringDecoder qsd = new QueryStringDecoder(httpRequest.uri());
    RouteResult<?> routeResult = router.route(method, qsd.path(), qsd.parameters());
    if (routeResult == null) {
        respondNotFound(channelHandlerContext, httpRequest);
        return;
    }
    routed(channelHandlerContext, routeResult, httpRequest);
}
Also used : QueryStringDecoder(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder) DefaultFullHttpResponse(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpResponse) HttpMethod(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod)

Example 98 with HttpMethod

use of io.netty.handler.codec.http.HttpMethod in project crate by crate.

the class HttpBlobHandler method possibleRedirect.

private boolean possibleRedirect(HttpRequest request, String index, String digest) {
    HttpMethod method = request.method();
    if (method.equals(HttpMethod.GET) || method.equals(HttpMethod.HEAD) || (method.equals(HttpMethod.PUT) && HttpUtil.is100ContinueExpected(request))) {
        String redirectAddress;
        try {
            redirectAddress = blobService.getRedirectAddress(index, digest);
        } catch (MissingHTTPEndpointException ex) {
            simpleResponse(request, HttpResponseStatus.BAD_GATEWAY);
            return true;
        }
        if (redirectAddress != null) {
            LOGGER.trace("redirectAddress: {}", redirectAddress);
            sendRedirect(request, activeScheme + redirectAddress);
            return true;
        }
    }
    return false;
}
Also used : MissingHTTPEndpointException(io.crate.blob.exceptions.MissingHTTPEndpointException) HttpMethod(io.netty.handler.codec.http.HttpMethod)

Aggregations

HttpMethod (io.netty.handler.codec.http.HttpMethod)95 Test (org.junit.Test)51 HttpRequest (io.netty.handler.codec.http.HttpRequest)28 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)25 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)21 URI (java.net.URI)15 IOException (java.io.IOException)13 AtomicReference (java.util.concurrent.atomic.AtomicReference)13 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)11 HttpVersion (io.netty.handler.codec.http.HttpVersion)11 DefaultHttpClient (org.jocean.http.client.impl.DefaultHttpClient)11 TestChannelCreator (org.jocean.http.client.impl.TestChannelCreator)11 TestChannelPool (org.jocean.http.client.impl.TestChannelPool)11 DefaultSignalClient (org.jocean.http.rosa.impl.DefaultSignalClient)11 HttpTrade (org.jocean.http.server.HttpServerBuilder.HttpTrade)11 Subscription (rx.Subscription)11 Action2 (rx.functions.Action2)11 ByteBuf (io.netty.buffer.ByteBuf)10 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)10 Map (java.util.Map)9