Java Code Examples for io.netty.handler.codec.http.HttpMethod#GET

The following examples show how to use io.netty.handler.codec.http.HttpMethod#GET . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Http1BackendHandlerTest.java    From nitmproxy with MIT License 6 votes vote down vote up
@Test
public void shouldPendingRequests() {
    inboundChannel.pipeline().addLast(handler);

    DefaultFullHttpRequest req = new DefaultFullHttpRequest(
            HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
    // First request
    inboundChannel.write(req.retain());

    assertEquals(1, inboundChannel.outboundMessages().size());
    assertTrue(inboundChannel.outboundMessages().poll() instanceof ByteBuf);

    // Second request
    inboundChannel.write(req);

    // Should pending second request
    assertTrue(inboundChannel.outboundMessages().isEmpty());
}
 
Example 2
Source File: Http1FilterUnitTest.java    From xio with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeniedRule() throws UnknownHostException {
  List<Http1DeterministicRuleEngineConfig.Rule> blacklist = new ArrayList<>();
  HashMultimap<String, String> headers = HashMultimap.create();
  headers.put("User-Agent", "Bad-actor: 1.0");
  Http1DeterministicRuleEngineConfig.Rule bad =
      new Http1DeterministicRuleEngineConfig.Rule(
          HttpMethod.GET, "/path/to/failure", HttpVersion.HTTP_1_0, headers);
  blacklist.add(bad);
  Http1Filter http1Filter =
      new Http1Filter(new Http1FilterConfig(ImmutableList.copyOf(blacklist)));
  EmbeddedChannel chDeny = new EmbeddedChannel(http1Filter);
  DefaultHttpRequest request =
      new DefaultHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, "/path/to/failure");
  request.headers().set("User-Agent", "Bad-actor: 1.0");
  chDeny.writeInbound(request);
  chDeny.runPendingTasks();
  assertFalse(chDeny.isActive());
  assertFalse(chDeny.isOpen());
}
 
Example 3
Source File: HandshakeHandlerTest.java    From socketio with Apache License 2.0 6 votes vote down vote up
@Test
public void testChannelRead() throws Exception {
  HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/socket.io/1/");

  LastOutboundHandler lastOutboundHandler = new LastOutboundHandler();
  EmbeddedChannel channel = new EmbeddedChannel(lastOutboundHandler, handshakeHandler);
  channel.writeInbound(request);
  Object outboundMessage = lastOutboundHandler.getOutboundMessages().poll();
  assertTrue(outboundMessage instanceof FullHttpResponse);
  FullHttpResponse res = (FullHttpResponse) outboundMessage;
  assertEquals(HttpVersion.HTTP_1_1, res.protocolVersion());
  assertEquals(HttpResponseStatus.OK, res.status());
  ByteBuf content = res.content();
  assertTrue(content.toString(CharsetUtil.UTF_8).endsWith("60:60:websocket,flashsocket,xhr-polling,jsonp-polling"));
  channel.finish();
}
 
Example 4
Source File: TestAppLaunchHandler.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Test
public void testAndroidOsQueryParam() throws Exception {
	FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "https://app.arcus.com/app/launch?os=android");
	expectGetClient();
	Capture<SessionHandoff> handoff = captureNewToken();
	replay();
	
	FullHttpResponse response = handler.respond(request, mockContext());
	assertHandoff(handoff.getValue());
	assertRedirectTo(response, "https://dev-app.arcus.com/android/run?token=token");
}
 
Example 5
Source File: ModelServerTest.java    From multi-model-server with Apache License 2.0 5 votes vote down vote up
private void testPredictionsModelNotFound() throws InterruptedException {
    Channel channel = connect(false);
    Assert.assertNotNull(channel);

    HttpRequest req =
            new DefaultFullHttpRequest(
                    HttpVersion.HTTP_1_1, HttpMethod.GET, "/predictions/InvalidModel");
    channel.writeAndFlush(req).sync();
    channel.closeFuture().sync();

    ErrorResponse resp = JsonUtils.GSON.fromJson(result, ErrorResponse.class);

    Assert.assertEquals(resp.getCode(), HttpResponseStatus.NOT_FOUND.code());
    Assert.assertEquals(resp.getMessage(), "Model not found: InvalidModel");
}
 
Example 6
Source File: InboundHttp2ToHttpAdapterTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Test
public void clientRequestOneDataFrame() throws Exception {
    boostrapEnv(1, 1, 1);
    final String text = "hello world";
    final ByteBuf content = Unpooled.copiedBuffer(text.getBytes());
    final FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
            "/some/path/resource2", content, true);
    try {
        HttpHeaders httpHeaders = request.headers();
        httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 3);
        httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length());
        httpHeaders.setShort(HttpConversionUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), (short) 16);
        final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).path(
                new AsciiString("/some/path/resource2"));
        runInChannel(clientChannel, new Http2Runnable() {
            @Override
            public void run() throws Http2Exception {
                clientHandler.encoder().writeHeaders(ctxClient(), 3, http2Headers, 0, false, newPromiseClient());
                clientHandler.encoder().writeData(ctxClient(), 3, content.retainedDuplicate(), 0, true,
                                                  newPromiseClient());
                clientChannel.flush();
            }
        });
        awaitRequests();
        ArgumentCaptor<FullHttpMessage> requestCaptor = ArgumentCaptor.forClass(FullHttpMessage.class);
        verify(serverListener).messageReceived(requestCaptor.capture());
        capturedRequests = requestCaptor.getAllValues();
        assertEquals(request, capturedRequests.get(0));
    } finally {
        request.release();
    }
}
 
Example 7
Source File: ModelServerTest.java    From multi-model-server with Apache License 2.0 5 votes vote down vote up
private void testPing(Channel channel) throws InterruptedException {
    result = null;
    latch = new CountDownLatch(1);
    HttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/ping");
    channel.writeAndFlush(req);
    latch.await();

    StatusResponse resp = JsonUtils.GSON.fromJson(result, StatusResponse.class);
    Assert.assertEquals(resp.getStatus(), "Healthy");
    Assert.assertTrue(headers.contains("x-request-id"));
}
 
Example 8
Source File: NettyHttpClient.java    From util4j with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
		NettyHttpClient client=new NettyHttpClient();
		long time=System.currentTimeMillis();
		HttpRequest request=new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/baidu?tn=monline_6_dg&ie=utf-8&wd=netty+http客户端");
		HttpResponse response=client.syncRequest("www.baidu.com", 80, request);
		System.out.println(System.currentTimeMillis()-time);
		System.out.println(response);
		FullHttpResponse rsp=(FullHttpResponse) response;
		System.out.println("content:"+rsp.content().toString(CharsetUtil.UTF_8));
//		new Scanner(System.in).nextLine();
	}
 
Example 9
Source File: InboundHttp2ToHttpAdapterTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Test
public void clientRequestSingleHeaderNoDataFrames() throws Exception {
    boostrapEnv(1, 1, 1);
    final FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
            "/some/path/resource2", true);
    try {
        HttpHeaders httpHeaders = request.headers();
        httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "https");
        httpHeaders.set(HttpHeaderNames.HOST, "example.org");
        httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 3);
        httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, 0);
        httpHeaders.setShort(HttpConversionUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), (short) 16);
        final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).
                scheme(new AsciiString("https")).authority(new AsciiString("example.org"))
                .path(new AsciiString("/some/path/resource2"));
        runInChannel(clientChannel, new Http2Runnable() {
            @Override
            public void run() throws Http2Exception {
                clientHandler.encoder().writeHeaders(ctxClient(), 3, http2Headers, 0, true, newPromiseClient());
                clientChannel.flush();
            }
        });
        awaitRequests();
        ArgumentCaptor<FullHttpMessage> requestCaptor = ArgumentCaptor.forClass(FullHttpMessage.class);
        verify(serverListener).messageReceived(requestCaptor.capture());
        capturedRequests = requestCaptor.getAllValues();
        assertEquals(request, capturedRequests.get(0));
    } finally {
        request.release();
    }
}
 
Example 10
Source File: HttpRequestDecoderTest.java    From timely with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnknownURI() throws Exception {
    decoder = new TestHttpQueryDecoder(config);
    DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
            "/api/unknown");
    decoder.decode(null, request, results);
    Assert.assertEquals(1, results.size());
    Assert.assertEquals(request, results.get(0));
}
 
Example 11
Source File: InboundHttp2ToHttpAdapterTest.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Test
public void clientRequestTrailingHeaders() throws Exception {
    boostrapEnv(1, 1, 1);
    final String text = "some data";
    final ByteBuf content = Unpooled.copiedBuffer(text.getBytes());
    final FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
            "/some/path/resource2", content, true);
    try {
        HttpHeaders httpHeaders = request.headers();
        httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 3);
        httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length());
        httpHeaders.setShort(HttpConversionUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), (short) 16);
        HttpHeaders trailingHeaders = request.trailingHeaders();
        trailingHeaders.set(of("Foo"), of("goo"));
        trailingHeaders.set(of("fOo2"), of("goo2"));
        trailingHeaders.add(of("foO2"), of("goo3"));
        final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).path(
                new AsciiString("/some/path/resource2"));
        final Http2Headers http2Headers2 = new DefaultHttp2Headers()
                .set(new AsciiString("foo"), new AsciiString("goo"))
                .set(new AsciiString("foo2"), new AsciiString("goo2"))
                .add(new AsciiString("foo2"), new AsciiString("goo3"));
        runInChannel(clientChannel, new Http2Runnable() {
            @Override
            public void run() throws Http2Exception {
                clientHandler.encoder().writeHeaders(ctxClient(), 3, http2Headers, 0, false, newPromiseClient());
                clientHandler.encoder().writeData(ctxClient(), 3, content.retainedDuplicate(), 0, false,
                                                  newPromiseClient());
                clientHandler.encoder().writeHeaders(ctxClient(), 3, http2Headers2, 0, true, newPromiseClient());
                clientChannel.flush();
            }
        });
        awaitRequests();
        ArgumentCaptor<FullHttpMessage> requestCaptor = ArgumentCaptor.forClass(FullHttpMessage.class);
        verify(serverListener).messageReceived(requestCaptor.capture());
        capturedRequests = requestCaptor.getAllValues();
        assertEquals(request, capturedRequests.get(0));
    } finally {
        request.release();
    }
}
 
Example 12
Source File: NettyHttpRequest.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
protected NettyHttpRequest(URI uri, 
      ResponseHandler handler,
      HttpMethod method,
      String json,
      Map<String, String> formParams,
      List<Map.Entry<String, Object>> headers, 
      Map<String, String> cookies) {
   this.uri = uri;
   this.handler = handler;
   
   String url = uri.getRawPath();
   if (method == HttpMethod.GET && formParams != null && formParams.size() > 0) {
      StringBuffer sb = new StringBuffer(url);
      char prefixChar = '?';
      for (String name : formParams.keySet()) {
         sb.append(prefixChar);
         if (prefixChar == '?') {
            prefixChar = '&';
         }
         try {
            sb.append(URLEncoder.encode(name, Charset.forName("UTF-8").name()))
               .append('=')
               .append(URLEncoder.encode(formParams.get(name), Charset.forName("UTF-8").name()));
         }
         catch (UnsupportedEncodingException e) {
            throw new RuntimeException("UTF-8 not supported for url encoding", e);
         }
      }
      url = sb.toString();
   }
   
   request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, method, url);
   request.setMethod(method);
   
   // Some Default Headers
   request.headers().set(HttpHeaders.Names.HOST, uri.getHost());
   request.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
   request.headers().set(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP);
   
   addHeaders(headers);
   
   addCookies(cookies);
   
   if (method == HttpMethod.POST) {
      if (json != null && !json.isEmpty()) {
         jsonPayload(json);
      }
      else {
         formPayload(formParams);
      }
   }
}
 
Example 13
Source File: ServletStyleConstraintTest.java    From karyon with Apache License 2.0 4 votes vote down vote up
protected HttpServerRequest<ByteBuf> newRequest(String uri) {
    return new HttpServerRequest<ByteBuf>(new DefaultHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, uri),
                                          UnicastContentSubject.<ByteBuf>createWithoutNoSubscriptionTimeout());
}
 
Example 14
Source File: Recipes.java    From xio with Apache License 2.0 4 votes vote down vote up
public static HttpRequest newRequestGet(String urlPath) {
  return new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, urlPath);
}
 
Example 15
Source File: BootstrapTemplate.java    From netty-cookbook with Apache License 2.0 4 votes vote down vote up
public static void newHttpClientBootstrap(String url, ChannelHandler handler) throws Exception{
	URI uri = new URI(url);
	String scheme = uri.getScheme() == null ? "http" : uri.getScheme();
	String host = uri.getHost() == null ? "127.0.0.1" : uri.getHost();
	int port = uri.getPort();
	if (port == -1) {
		if ("http".equalsIgnoreCase(scheme)) {
			port = 80;
		} else if ("https".equalsIgnoreCase(scheme)) {
			port = 443;
		}
	}

	if (!"http".equalsIgnoreCase(scheme)
			&& !"https".equalsIgnoreCase(scheme)) {
		System.err.println("Only HTTP(S) is supported.");
		return;
	}

	// Configure SSL context if necessary.
	final boolean ssl = "https".equalsIgnoreCase(scheme);
	final SslContext sslCtx;
	if (ssl) {
		sslCtx = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE);
	} else {
		sslCtx = null;
	}

	// Configure the client.
	EventLoopGroup group = new NioEventLoopGroup();
	try {
		Bootstrap b = new Bootstrap();
		b.group(group).channel(NioSocketChannel.class)
				.handler(new HttpDownloadertInitializer(sslCtx,handler));
		// Make the connection attempt.
		Channel ch = b.connect(host, port).sync().channel();
		// Prepare the HTTP request.
		HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri.getRawPath());
		HttpHeaders headers = request.headers();
		headers.set(HttpHeaders.Names.HOST, host);
		headers.set(HttpHeaders.Names.CONNECTION,HttpHeaders.Values.CLOSE);
		headers.set(HttpHeaders.Names.ACCEPT_ENCODING,HttpHeaders.Values.GZIP);
		// Set some example cookies.
		headers.set(HttpHeaders.Names.COOKIE, ClientCookieEncoder.encode(new DefaultCookie("my-cookie", "foo")));
		ch.writeAndFlush(request);
		// Wait for the server to close the connection.
		ch.closeFuture().sync();
		Thread.sleep(1000);
	} finally {
		// Shut down executor threads to exit.
		group.shutdownGracefully();
	}	
}
 
Example 16
Source File: Route.java    From Discord4J with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static Route get(String uri) {
    return new Route(HttpMethod.GET, uri);
}
 
Example 17
Source File: HttpServerTests.java    From reactor-netty with Apache License 2.0 4 votes vote down vote up
@Test
public void httpPipelining() throws Exception {

	AtomicInteger i = new AtomicInteger();

	disposableServer = HttpServer.create()
	                             .port(0)
	                             .handle((req, resp) ->
	                                     resp.header(HttpHeaderNames.CONTENT_LENGTH, "1")
	                                         .sendString(Mono.just(i.incrementAndGet())
	                                                         .flatMap(d ->
	                                                                 Mono.delay(Duration.ofSeconds(4 - d))
	                                                                     .map(x -> d + "\n"))))
	                             .wiretap(true)
	                             .bindNow();

	DefaultFullHttpRequest request =
			new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,
			                           HttpMethod.GET,
			                           "/plaintext");

	CountDownLatch latch = new CountDownLatch(6);

	Connection client =
			TcpClient.create()
			         .port(disposableServer.port())
			         .handle((in, out) -> {
			                 in.withConnection(x ->
			                         x.addHandlerFirst(new HttpClientCodec()))
			                   .receiveObject()
			                   .ofType(DefaultHttpContent.class)
			                   .as(ByteBufFlux::fromInbound)
			                   .asString()
			                   .log()
			                   .map(Integer::parseInt)
			                   .subscribe(d -> {
			                       for (int x = 0; x < d; x++) {
			                           latch.countDown();
			                       }
			                   });

			                 return out.sendObject(Flux.just(request.retain(),
			                                                 request.retain(),
			                                                 request.retain()))
			                           .neverComplete();
			         })
			         .wiretap(true)
			         .connectNow();

	assertThat(latch.await(45, TimeUnit.SECONDS)).isTrue();

	client.disposeNow();
}
 
Example 18
Source File: HttpRequestMessage.java    From nomulus with Apache License 2.0 4 votes vote down vote up
@Inject
public HttpRequestMessage() {
  this(HttpVersion.HTTP_1_1, HttpMethod.GET, "");
}
 
Example 19
Source File: WebSocketClientHandshaker08.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
/**
 * /**
 * <p>
 * Sends the opening request to the server:
 * </p>
 *
 * <pre>
 * GET /chat HTTP/1.1
 * Host: server.example.com
 * Upgrade: websocket
 * Connection: Upgrade
 * Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
 * Sec-WebSocket-Origin: http://example.com
 * Sec-WebSocket-Protocol: chat, superchat
 * Sec-WebSocket-Version: 8
 * </pre>
 *
 */
@Override
protected FullHttpRequest newHandshakeRequest() {
    // Get path
    URI wsURL = uri();
    String path = wsURL.getPath();
    if (wsURL.getQuery() != null && !wsURL.getQuery().isEmpty()) {
        path = wsURL.getPath() + '?' + wsURL.getQuery();
    }

    if (path == null || path.isEmpty()) {
        path = "/";
    }

    // Get 16 bit nonce and base 64 encode it
    byte[] nonce = WebSocketUtil.randomBytes(16);
    String key = WebSocketUtil.base64(nonce);

    String acceptSeed = key + MAGIC_GUID;
    byte[] sha1 = WebSocketUtil.sha1(acceptSeed.getBytes(CharsetUtil.US_ASCII));
    expectedChallengeResponseString = WebSocketUtil.base64(sha1);

    if (logger.isDebugEnabled()) {
        logger.debug(
                "WebSocket version 08 client handshake key: {}, expected response: {}",
                key, expectedChallengeResponseString);
    }

    // Format request
    FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, path);
    HttpHeaders headers = request.headers();

    headers.add(Names.UPGRADE, Values.WEBSOCKET.toLowerCase())
           .add(Names.CONNECTION, Values.UPGRADE)
           .add(Names.SEC_WEBSOCKET_KEY, key)
           .add(Names.HOST, wsURL.getHost());

    int wsPort = wsURL.getPort();
    String originValue = "http://" + wsURL.getHost();
    if (wsPort != 80 && wsPort != 443) {
        // if the port is not standard (80/443) its needed to add the port to the header.
        // See http://tools.ietf.org/html/rfc6454#section-6.2
        originValue = originValue + ':' + wsPort;
    }
    headers.add(Names.SEC_WEBSOCKET_ORIGIN, originValue);

    String expectedSubprotocol = expectedSubprotocol();
    if (expectedSubprotocol != null && !expectedSubprotocol.isEmpty()) {
        headers.add(Names.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol);
    }

    headers.add(Names.SEC_WEBSOCKET_VERSION, "8");

    if (customHeaders != null) {
        headers.add(customHeaders);
    }
    return request;
}
 
Example 20
Source File: BootstrapTemplate.java    From netty-cookbook with Apache License 2.0 4 votes vote down vote up
public static void newHttpClientBootstrap(String url, ChannelHandler handler) throws Exception{
	URI uri = new URI(url);
	String scheme = uri.getScheme() == null ? "http" : uri.getScheme();
	String host = uri.getHost() == null ? "127.0.0.1" : uri.getHost();
	int port = uri.getPort();
	if (port == -1) {
		if ("http".equalsIgnoreCase(scheme)) {
			port = 80;
		} else if ("https".equalsIgnoreCase(scheme)) {
			port = 443;
		}
	}

	if (!"http".equalsIgnoreCase(scheme)
			&& !"https".equalsIgnoreCase(scheme)) {
		System.err.println("Only HTTP(S) is supported.");
		return;
	}

	// Configure SSL context if necessary.
	final boolean ssl = "https".equalsIgnoreCase(scheme);
	final SslContext sslCtx;
	if (ssl) {
		sslCtx = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE);
	} else {
		sslCtx = null;
	}

	// Configure the client.
	EventLoopGroup group = new NioEventLoopGroup();
	try {
		Bootstrap b = new Bootstrap();
		b.group(group).channel(NioSocketChannel.class)
				.handler(new HttpDownloadertInitializer(sslCtx,handler));
		// Make the connection attempt.
		Channel ch = b.connect(host, port).sync().channel();
		// Prepare the HTTP request.
		HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri.getRawPath());
		HttpHeaders headers = request.headers();
		headers.set(HttpHeaders.Names.HOST, host);
		headers.set(HttpHeaders.Names.CONNECTION,HttpHeaders.Values.CLOSE);
		headers.set(HttpHeaders.Names.ACCEPT_ENCODING,HttpHeaders.Values.GZIP);
		// Set some example cookies.
		headers.set(HttpHeaders.Names.COOKIE, ClientCookieEncoder.encode(new DefaultCookie("my-cookie", "foo")));
		ch.writeAndFlush(request);
		// Wait for the server to close the connection.
		ch.closeFuture().sync();
		Thread.sleep(1000);
	} finally {
		// Shut down executor threads to exit.
		group.shutdownGracefully();
	}	
}