Search in sources :

Example 56 with DefaultHttpRequest

use of io.netty.handler.codec.http.DefaultHttpRequest in project rest.li by linkedin.

the class NettyRequestAdapter method toNettyRequest.

/**
   * Adapts a StreamRequest to Netty's HttpRequest
   * @param request  R2 stream request
   * @return Adapted HttpRequest.
   */
static HttpRequest toNettyRequest(StreamRequest request) throws Exception {
    HttpMethod nettyMethod = HttpMethod.valueOf(request.getMethod());
    URL url = new URL(request.getURI().toString());
    String path = url.getFile();
    //   it MUST be given as "/" (the server root).
    if (path.isEmpty()) {
        path = "/";
    }
    HttpRequest nettyRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, nettyMethod, path);
    nettyRequest.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
    for (Map.Entry<String, String> entry : request.getHeaders().entrySet()) {
        //   that contains a Transfer-Encoding header field.
        if (entry.getKey().equalsIgnoreCase(HttpHeaderNames.CONTENT_LENGTH.toString())) {
            continue;
        }
        nettyRequest.headers().set(entry.getKey(), entry.getValue());
    }
    nettyRequest.headers().set(HttpHeaderNames.HOST, url.getAuthority());
    nettyRequest.headers().set(HttpConstants.REQUEST_COOKIE_HEADER_NAME, request.getCookies());
    return nettyRequest;
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) AsciiString(io.netty.util.AsciiString) Map(java.util.Map) HttpMethod(io.netty.handler.codec.http.HttpMethod) URL(java.net.URL)

Example 57 with DefaultHttpRequest

use of io.netty.handler.codec.http.DefaultHttpRequest in project tesla by linking12.

the class ClientToProxyConnection method copy.

private HttpRequest copy(HttpRequest original) {
    if (original instanceof FullHttpRequest) {
        return ((FullHttpRequest) original).copy();
    } else {
        HttpRequest request = new DefaultHttpRequest(original.protocolVersion(), original.method(), original.uri());
        request.headers().set(original.headers());
        return request;
    }
}
Also used : DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest)

Example 58 with DefaultHttpRequest

use of io.netty.handler.codec.http.DefaultHttpRequest in project cdap by caskdata.

the class RouterPathTest method testRouterFlowletInstancesLookUp.

@Test
public void testRouterFlowletInstancesLookUp() throws Exception {
    String path = "/v3/namespaces/default//apps/WordCount/flows/WordCountFlow/flowlets/StreamSource/instances";
    HttpRequest httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("PUT"), path);
    RouteDestination result = pathLookup.getRoutingService(FALLBACKSERVICE, path, httpRequest);
    Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
}
Also used : DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpMethod(io.netty.handler.codec.http.HttpMethod) Test(org.junit.Test)

Example 59 with DefaultHttpRequest

use of io.netty.handler.codec.http.DefaultHttpRequest in project cdap by caskdata.

the class RouterPathTest method testRouterV3PathLookup.

@Test
public void testRouterV3PathLookup() {
    final String namespacePath = "/v3////namespace/////";
    HttpRequest httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), namespacePath);
    RouteDestination result = pathLookup.getRoutingService(FALLBACKSERVICE, namespacePath, httpRequest);
    Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
}
Also used : DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpMethod(io.netty.handler.codec.http.HttpMethod) Test(org.junit.Test)

Example 60 with DefaultHttpRequest

use of io.netty.handler.codec.http.DefaultHttpRequest in project cdap by caskdata.

the class RouterPathTest method testRouterWorkFlowPathLookUp.

@Test
public void testRouterWorkFlowPathLookUp() throws Exception {
    String path = "/v3/namespaces/default/apps///PurchaseHistory///workflows/PurchaseHistoryWorkflow/status";
    HttpRequest httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), path);
    RouteDestination result = pathLookup.getRoutingService(FALLBACKSERVICE, path, httpRequest);
    Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
}
Also used : DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpMethod(io.netty.handler.codec.http.HttpMethod) Test(org.junit.Test)

Aggregations

DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)115 HttpRequest (io.netty.handler.codec.http.HttpRequest)81 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)53 Test (org.junit.Test)51 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)44 HttpMethod (io.netty.handler.codec.http.HttpMethod)23 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)20 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)18 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)16 HttpContent (io.netty.handler.codec.http.HttpContent)13 HttpObject (io.netty.handler.codec.http.HttpObject)13 DefaultHttpContent (io.netty.handler.codec.http.DefaultHttpContent)12 ByteBuf (io.netty.buffer.ByteBuf)11 HttpTrade (org.jocean.http.server.HttpServerBuilder.HttpTrade)11 Test (org.junit.jupiter.api.Test)10 Channel (io.netty.channel.Channel)9 ArrayList (java.util.ArrayList)9 Nettys4Test (org.jocean.http.util.Nettys4Test)9 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)8 DisposableWrapper (org.jocean.idiom.DisposableWrapper)6