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