Search in sources :

Example 56 with HttpResponse

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

the class GELFHttpHandlerTest method testNoCorsHeadersWithoutOrigin.

@Test
public void testNoCorsHeadersWithoutOrigin() throws Exception {
    HttpTransport.Handler handler = new HttpTransport.Handler(true);
    handler.messageReceived(ctx, evt);
    ArgumentCaptor<HttpResponse> argument = ArgumentCaptor.forClass(HttpResponse.class);
    verify(channel).write(argument.capture());
    verify(ctx, atMost(1)).sendUpstream(any(ChannelEvent.class));
    HttpResponse response = argument.getValue();
    assertNull(response.headers().get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_ORIGIN));
    assertNull(response.headers().get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_CREDENTIALS));
    assertNull(response.headers().get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_HEADERS));
}
Also used : HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) ChannelEvent(org.jboss.netty.channel.ChannelEvent) Test(org.junit.Test)

Example 57 with HttpResponse

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

the class GELFHttpHandlerTest method testWithArbitraryContentType.

@Test
public void testWithArbitraryContentType() throws Exception {
    when(headers.get(HttpHeaders.Names.CONTENT_TYPE)).thenReturn("foo/bar");
    HttpTransport.Handler handler = new HttpTransport.Handler(true);
    handler.messageReceived(ctx, evt);
    ArgumentCaptor<HttpResponse> argument = ArgumentCaptor.forClass(HttpResponse.class);
    verify(channel).write(argument.capture());
    verify(ctx, atMost(1)).sendUpstream(any(ChannelEvent.class));
    HttpResponse response = argument.getValue();
    assertEquals(HttpResponseStatus.ACCEPTED, response.getStatus());
    assertEquals(response.headers().get(HttpHeaders.Names.CONNECTION), HttpHeaders.Values.CLOSE);
}
Also used : HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) ChannelEvent(org.jboss.netty.channel.ChannelEvent) Test(org.junit.Test)

Example 58 with HttpResponse

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

the class GELFHttpHandlerTest method testNotReactToNonPost.

@Test
public void testNotReactToNonPost() throws Exception {
    HttpTransport.Handler handler = new HttpTransport.Handler(true);
    when(request.getMethod()).thenReturn(HttpMethod.GET);
    handler.messageReceived(ctx, evt);
    ArgumentCaptor<HttpResponse> argument = ArgumentCaptor.forClass(HttpResponse.class);
    verify(channel).write(argument.capture());
    verify(ctx, never()).sendUpstream(any(ChannelEvent.class));
    HttpResponse response = argument.getValue();
    assertEquals(response.getStatus(), HttpResponseStatus.METHOD_NOT_ALLOWED);
}
Also used : HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) ChannelEvent(org.jboss.netty.channel.ChannelEvent) Test(org.junit.Test)

Example 59 with HttpResponse

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

the class GELFHttpHandlerTest method testNoCorsHeadersForOriginIfDisabled.

@Test
public void testNoCorsHeadersForOriginIfDisabled() throws Exception {
    HttpTransport.Handler handler = new HttpTransport.Handler(false);
    String origin = "localhost";
    when(this.headers.get(HttpHeaders.Names.ORIGIN)).thenReturn(origin);
    handler.messageReceived(ctx, evt);
    ArgumentCaptor<HttpResponse> argument = ArgumentCaptor.forClass(HttpResponse.class);
    verify(channel).write(argument.capture());
    verify(ctx, atMost(1)).sendUpstream(any(ChannelEvent.class));
    HttpResponse response = argument.getValue();
    assertNull(response.headers().get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_ORIGIN));
    assertNull(response.headers().get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_CREDENTIALS));
    assertNull(response.headers().get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_HEADERS));
}
Also used : HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) ChannelEvent(org.jboss.netty.channel.ChannelEvent) Test(org.junit.Test)

Example 60 with HttpResponse

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

the class GELFHttpHandlerTest method testAddCorsHeadersForOrigin.

@Test
public void testAddCorsHeadersForOrigin() throws Exception {
    HttpTransport.Handler handler = new HttpTransport.Handler(true);
    String origin = "localhost";
    when(this.headers.get(HttpHeaders.Names.ORIGIN)).thenReturn(origin);
    handler.messageReceived(ctx, evt);
    ArgumentCaptor<HttpResponse> argument = ArgumentCaptor.forClass(HttpResponse.class);
    verify(channel).write(argument.capture());
    verify(ctx, atMost(1)).sendUpstream(any(ChannelEvent.class));
    HttpResponse response = argument.getValue();
    assertEquals(response.headers().get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_ORIGIN), origin);
    assertEquals(response.headers().get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_CREDENTIALS), "true");
    assertEquals(response.headers().get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_HEADERS), "Authorization, Content-Type");
}
Also used : HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) ChannelEvent(org.jboss.netty.channel.ChannelEvent) Test(org.junit.Test)

Aggregations

HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)124 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)95 Test (org.testng.annotations.Test)51 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)49 HttpChunk (org.jboss.netty.handler.codec.http.HttpChunk)49 DefaultHttpChunk (org.jboss.netty.handler.codec.http.DefaultHttpChunk)45 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)36 Channel (org.jboss.netty.channel.Channel)33 DefaultHttpChunkTrailer (org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer)30 HttpChunkTrailer (org.jboss.netty.handler.codec.http.HttpChunkTrailer)27 BootstrapDatabaseTooOldException (com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException)25 DefaultHttpRequest (org.jboss.netty.handler.codec.http.DefaultHttpRequest)25 Checkpoint (com.linkedin.databus.core.Checkpoint)24 InetSocketAddress (java.net.InetSocketAddress)24 SocketAddress (java.net.SocketAddress)23 ConditionCheck (com.linkedin.databus2.test.ConditionCheck)20 Test (org.junit.Test)20 Logger (org.apache.log4j.Logger)16 Map (java.util.Map)15 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)15