Search in sources :

Example 56 with HttpHeaders

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

the class HttpFiltersRunner method createResponse.

private HttpResponse createResponse(HttpResponseStatus httpResponseStatus, HttpRequest originalRequest) {
    HttpHeaders httpHeaders = new DefaultHttpHeaders();
    httpHeaders.add("Transfer-Encoding", "chunked");
    HttpResponse httpResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, httpResponseStatus);
    httpResponse.headers().add(httpHeaders);
    return httpResponse;
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse)

Example 57 with HttpHeaders

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

the class ClientToProxyConnection method modifyRequestHeadersToReflectProxying.

private void modifyRequestHeadersToReflectProxying(HttpRequest httpRequest) {
    LOG.debug("Modifying request headers for proxying");
    HttpHeaders headers = httpRequest.headers();
    ProxyUtils.removeSdchEncoding(headers);
    switchProxyConnectionHeader(headers);
    stripConnectionTokens(headers);
    stripHopByHopHeaders(headers);
    ProxyUtils.addVia(httpRequest, proxyServer.getProxyAlias());
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders)

Example 58 with HttpHeaders

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

the class ClientToProxyConnection method modifyResponseHeadersToReflectProxying.

private void modifyResponseHeadersToReflectProxying(HttpResponse httpResponse) {
    if (!proxyServer.isTransparent()) {
        HttpHeaders headers = httpResponse.headers();
        stripConnectionTokens(headers);
        stripHopByHopHeaders(headers);
        ProxyUtils.addVia(httpResponse, proxyServer.getProxyAlias());
        if (!headers.contains(HttpHeaderNames.DATE)) {
            headers.set(HttpHeaderNames.DATE, new Date());
        }
    }
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) Date(java.util.Date)

Example 59 with HttpHeaders

use of io.netty.handler.codec.http.HttpHeaders in project janusgraph by JanusGraph.

the class SaslAndHMACAuthenticationHandlerTest method testHttpChannelReadWhenAuthenticatorHasBeenAdded.

@Test
public void testHttpChannelReadWhenAuthenticatorHasBeenAdded() throws Exception {
    final SaslAndHMACAuthenticator authenticator = createMock(SaslAndHMACAuthenticator.class);
    final HMACAuthenticator hmacAuth = createMock(HMACAuthenticator.class);
    final ChannelHandlerContext ctx = createMock(ChannelHandlerContext.class);
    final ChannelHandler mockHandler = createMock(ChannelHandler.class);
    final ChannelPipeline pipeline = createMock(ChannelPipeline.class);
    final HttpMessage msg = createMock(HttpMessage.class);
    final HttpHeaders headers = createMock(HttpHeaders.class);
    expect(authenticator.getHMACAuthenticator()).andReturn(hmacAuth);
    expect(authenticator.getSimpleAuthenticator()).andReturn(createMock(JanusGraphSimpleAuthenticator.class));
    expect(ctx.pipeline()).andReturn(pipeline);
    expect(pipeline.get("hmac_authenticator")).andReturn(mockHandler);
    expect(msg.headers()).andReturn(headers).times(2);
    expect(headers.get(isA(String.class))).andReturn(null).times(2);
    expect(ctx.fireChannelRead(eq(msg))).andReturn(ctx);
    replayAll();
    final SaslAndHMACAuthenticationHandler handler = new SaslAndHMACAuthenticationHandler(authenticator, null);
    handler.channelRead(ctx, msg);
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) JanusGraphSimpleAuthenticator(org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.JanusGraphSimpleAuthenticator) SaslAndHMACAuthenticator(org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.SaslAndHMACAuthenticator) HMACAuthenticator(org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.HMACAuthenticator) SaslAndHMACAuthenticator(org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.SaslAndHMACAuthenticator) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelHandler(io.netty.channel.ChannelHandler) HttpMessage(io.netty.handler.codec.http.HttpMessage) ChannelPipeline(io.netty.channel.ChannelPipeline) Test(org.junit.Test)

Example 60 with HttpHeaders

use of io.netty.handler.codec.http.HttpHeaders in project janusgraph by JanusGraph.

the class HttpHMACAuthenticationHandlerTest method testChannelReadBasicAuthIncorrectScheme.

@Test
public void testChannelReadBasicAuthIncorrectScheme() {
    final ChannelHandlerContext ctx = createMock(ChannelHandlerContext.class);
    final FullHttpRequest msg = createMock(FullHttpRequest.class);
    final HttpHeaders headers = createMock(HttpHeaders.class);
    final Authenticator authenticator = createMock(Authenticator.class);
    final ChannelFuture cf = createMock(ChannelFuture.class);
    expect(msg.getMethod()).andReturn(HttpMethod.POST);
    expect(msg.headers()).andReturn(headers).anyTimes();
    expect(headers.get("Authorization")).andReturn("bogus");
    expect(ctx.writeAndFlush(eqHttpStatus(UNAUTHORIZED))).andReturn(cf);
    expect(cf.addListener(ChannelFutureListener.CLOSE)).andReturn(null);
    expect(msg.release()).andReturn(false);
    final HttpHMACAuthenticationHandler handler = new HttpHMACAuthenticationHandler(authenticator);
    replayAll();
    handler.channelRead(ctx, (Object) msg);
    verifyAll();
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Authenticator(org.apache.tinkerpop.gremlin.server.auth.Authenticator) Test(org.junit.Test)

Aggregations

HttpHeaders (io.netty.handler.codec.http.HttpHeaders)128 Test (org.junit.Test)61 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)49 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)42 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)34 AsciiString (io.netty.util.AsciiString)27 Test (org.testng.annotations.Test)25 ByteBuf (io.netty.buffer.ByteBuf)22 HttpServletResponse (javax.servlet.http.HttpServletResponse)17 ChannelPromise (io.netty.channel.ChannelPromise)15 FullHttpMessage (io.netty.handler.codec.http.FullHttpMessage)12 HttpRequest (io.netty.handler.codec.http.HttpRequest)12 Cookie (io.netty.handler.codec.http.cookie.Cookie)12 DefaultCookie (io.netty.handler.codec.http.cookie.DefaultCookie)12 Map (java.util.Map)12 HttpTest (org.asynchttpclient.testserver.HttpTest)12 Http2CodecUtil.getEmbeddedHttp2Exception (io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception)11 Http2Runnable (io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable)11 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)10 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)10