Search in sources :

Example 1 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) {
    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);
    }
}
Also used : HttpHeaders(org.jboss.netty.handler.codec.http.HttpHeaders) Function(com.google.common.base.Function) IOException(java.io.IOException)

Example 2 with HttpHeaders

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

the class HttpTransportHandlerTest method messageReceivedSuccessfullyProcessesPOSTRequest.

@Test
public void messageReceivedSuccessfullyProcessesPOSTRequest() throws Exception {
    final HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/gelf");
    httpRequest.headers().add("Host", "localhost");
    httpRequest.headers().add("Origin", "http://example.com");
    httpRequest.headers().add("Connection", "close");
    final String gelfMessage = "{\"version\":\"1.1\",\"short_message\":\"Foo\",\"host\":\"localhost\"}";
    httpRequest.setContent(ChannelBuffers.copiedBuffer(gelfMessage.toCharArray(), StandardCharsets.UTF_8));
    channel.offer(httpRequest);
    channel.finish();
    final HttpResponse httpResponse = channel.poll();
    assertThat(httpResponse.getStatus()).isEqualTo(HttpResponseStatus.ACCEPTED);
    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 3 with HttpHeaders

use of org.jboss.netty.handler.codec.http.HttpHeaders in project hive by apache.

the class ResponseCookieHandler method handleResponse.

@Override
public ClientResponse<Intermediate> handleResponse(HttpResponse httpResponse) {
    try {
        final HttpHeaders headers = httpResponse.headers();
        manager.put(uri, Maps.asMap(headers.names(), input -> headers.getAll(input)));
    } catch (IOException e) {
        log.error("Error while processing Cookies from header", e);
    } finally {
        return delegate.handleResponse(httpResponse);
    }
}
Also used : HttpHeaders(org.jboss.netty.handler.codec.http.HttpHeaders) ClientResponse(com.metamx.http.client.response.ClientResponse) Logger(org.slf4j.Logger) HttpResponseHandler(com.metamx.http.client.response.HttpResponseHandler) CookieManager(java.net.CookieManager) HttpChunk(org.jboss.netty.handler.codec.http.HttpChunk) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) URI(java.net.URI) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) Maps(com.google.common.collect.Maps) HttpHeaders(org.jboss.netty.handler.codec.http.HttpHeaders) IOException(java.io.IOException)

Example 4 with HttpHeaders

use of org.jboss.netty.handler.codec.http.HttpHeaders in project hive by apache.

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(), headers::getAll));
        return delegate.handleResponse(httpResponse, trafficCop);
    } catch (IOException e) {
        LOG.error("Error while processing Cookies from header", e);
        throw new RuntimeException(e);
    }
}
Also used : HttpHeaders(org.jboss.netty.handler.codec.http.HttpHeaders) IOException(java.io.IOException)

Example 5 with HttpHeaders

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

the class HttpTransportHandlerTest method messageReceivedReturns404ForWrongPath.

@Test
public void messageReceivedReturns404ForWrongPath() throws Exception {
    final HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
    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.NOT_FOUND);
    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)

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