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