Search in sources :

Example 6 with HttpHeaders

use of org.jboss.netty.handler.codec.http.HttpHeaders in project graylog2-server by Graylog2.

the class HttpTransportHandlerTest method messageReceivedReturns405ForInvalidMethod.

@Test
public void messageReceivedReturns405ForInvalidMethod() throws Exception {
    final HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
    httpRequest.headers().add("Host", "localhost");
    httpRequest.headers().add("Origin", "http://example.com");
    httpRequest.headers().add("Connection", "close");
    channel.offer(httpRequest);
    channel.finish();
    final HttpResponse httpResponse = channel.poll();
    assertThat(httpResponse.getStatus()).isEqualTo(HttpResponseStatus.METHOD_NOT_ALLOWED);
    final HttpHeaders headers = httpResponse.headers();
    assertThat(headers.get(HttpHeaders.Names.CONTENT_LENGTH)).isEqualTo("0");
    assertThat(headers.get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_ORIGIN)).isEqualTo("http://example.com");
    assertThat(headers.get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_CREDENTIALS)).isEqualTo("true");
    assertThat(headers.get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_HEADERS)).isEqualTo("Authorization, Content-Type");
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) HttpHeaders(org.jboss.netty.handler.codec.http.HttpHeaders) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) Test(org.junit.Test)

Example 7 with HttpHeaders

use of org.jboss.netty.handler.codec.http.HttpHeaders in project graylog2-server by Graylog2.

the class HttpTransportHandlerTest method messageReceivedSuccessfullyProcessesOPTIONSRequest.

@Test
public void messageReceivedSuccessfullyProcessesOPTIONSRequest() throws Exception {
    final HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.OPTIONS, "/gelf");
    httpRequest.headers().add("Host", "localhost");
    httpRequest.headers().add("Origin", "http://example.com");
    httpRequest.headers().add("Connection", "close");
    channel.offer(httpRequest);
    channel.finish();
    final HttpResponse httpResponse = channel.poll();
    assertThat(httpResponse.getStatus()).isEqualTo(HttpResponseStatus.OK);
    final HttpHeaders headers = httpResponse.headers();
    assertThat(headers.get(HttpHeaders.Names.CONTENT_LENGTH)).isEqualTo("0");
    assertThat(headers.get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_ORIGIN)).isEqualTo("http://example.com");
    assertThat(headers.get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_CREDENTIALS)).isEqualTo("true");
    assertThat(headers.get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_HEADERS)).isEqualTo("Authorization, Content-Type");
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) HttpHeaders(org.jboss.netty.handler.codec.http.HttpHeaders) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) Test(org.junit.Test)

Example 8 with HttpHeaders

use of org.jboss.netty.handler.codec.http.HttpHeaders in project druid by druid-io.

the class ResponseCookieHandler method handleResponse.

@Override
public ClientResponse<Intermediate> handleResponse(HttpResponse httpResponse, TrafficCop trafficCop) {
    try {
        final HttpHeaders headers = httpResponse.headers();
        manager.put(uri, Maps.asMap(headers.names(), new Function<String, List<String>>() {

            @Override
            public List<String> apply(String input) {
                return headers.getAll(input);
            }
        }));
    } catch (IOException e) {
        log.error(e, "Error while processing Cookies from header");
    } finally {
        return delegate.handleResponse(httpResponse, trafficCop);
    }
}
Also used : HttpHeaders(org.jboss.netty.handler.codec.http.HttpHeaders) Function(com.google.common.base.Function) IOException(java.io.IOException)

Aggregations

HttpHeaders (org.jboss.netty.handler.codec.http.HttpHeaders)8 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)5 IOException (java.io.IOException)4 DefaultHttpRequest (org.jboss.netty.handler.codec.http.DefaultHttpRequest)4 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)4 Test (org.junit.Test)4 Function (com.google.common.base.Function)2 Maps (com.google.common.collect.Maps)1 ClientResponse (com.metamx.http.client.response.ClientResponse)1 HttpResponseHandler (com.metamx.http.client.response.HttpResponseHandler)1 CookieManager (java.net.CookieManager)1 URI (java.net.URI)1 HttpChunk (org.jboss.netty.handler.codec.http.HttpChunk)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1