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));
}
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);
}
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);
}
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));
}
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");
}
Aggregations