use of io.netty.handler.codec.http.HttpResponseStatus in project netty by netty.
the class SpdyHttpDecoder method createHttpResponse.
private static FullHttpResponse createHttpResponse(SpdyHeadersFrame responseFrame, ByteBufAllocator alloc, boolean validateHeaders) throws Exception {
// Create the first line of the response from the name/value pairs
SpdyHeaders headers = responseFrame.headers();
HttpResponseStatus status = HttpResponseStatus.parseLine(headers.get(STATUS));
HttpVersion version = HttpVersion.valueOf(headers.getAsString(VERSION));
headers.remove(STATUS);
headers.remove(VERSION);
boolean release = true;
ByteBuf buffer = alloc.buffer();
try {
FullHttpResponse res = new DefaultFullHttpResponse(version, status, buffer, validateHeaders);
for (Map.Entry<CharSequence, CharSequence> e : responseFrame.headers()) {
res.headers().add(e.getKey(), e.getValue());
}
// The Connection and Keep-Alive headers are no longer valid
HttpUtil.setKeepAlive(res, true);
// Transfer-Encoding header is not valid
res.headers().remove(HttpHeaderNames.TRANSFER_ENCODING);
res.headers().remove(HttpHeaderNames.TRAILER);
release = false;
return res;
} finally {
if (release) {
buffer.release();
}
}
}
use of io.netty.handler.codec.http.HttpResponseStatus in project ribbon by Netflix.
the class RxMovieServerTest method testMovieRegistration.
@Test
public void testMovieRegistration() {
String movieFormatted = ORANGE_IS_THE_NEW_BLACK.toString();
HttpResponseStatus statusCode = RxNetty.createHttpPost(baseURL + "/movies", Observable.just(movieFormatted), new StringTransformer()).flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<HttpResponseStatus>>() {
@Override
public Observable<HttpResponseStatus> call(HttpClientResponse<ByteBuf> httpClientResponse) {
return Observable.just(httpClientResponse.getStatus());
}
}).toBlocking().first();
assertEquals(HttpResponseStatus.CREATED, statusCode);
assertEquals(ORANGE_IS_THE_NEW_BLACK, movieServer.movies.get(ORANGE_IS_THE_NEW_BLACK.getId()));
}
use of io.netty.handler.codec.http.HttpResponseStatus in project ribbon by Netflix.
the class RxMovieServerTest method testUpateRecommendations.
@Test
public void testUpateRecommendations() {
movieServer.movies.put(ORANGE_IS_THE_NEW_BLACK.getId(), ORANGE_IS_THE_NEW_BLACK);
HttpResponseStatus statusCode = RxNetty.createHttpPost(baseURL + "/users/" + TEST_USER_ID + "/recommendations", Observable.just(ORANGE_IS_THE_NEW_BLACK.getId()), new StringTransformer()).flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<HttpResponseStatus>>() {
@Override
public Observable<HttpResponseStatus> call(HttpClientResponse<ByteBuf> httpClientResponse) {
return Observable.just(httpClientResponse.getStatus());
}
}).toBlocking().first();
assertEquals(HttpResponseStatus.OK, statusCode);
assertTrue(movieServer.userRecommendations.get(TEST_USER_ID).contains(ORANGE_IS_THE_NEW_BLACK.getId()));
}
use of io.netty.handler.codec.http.HttpResponseStatus in project vert.x by eclipse.
the class Http1xServerResponse method setStatusMessage.
@Override
public HttpServerResponse setStatusMessage(String statusMessage) {
synchronized (conn) {
checkHeadWritten();
this.statusMessage = statusMessage;
this.status = new HttpResponseStatus(status.code(), statusMessage);
return this;
}
}
use of io.netty.handler.codec.http.HttpResponseStatus in project crate by crate.
the class HttpBlobHandler method exceptionCaught.
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (cause instanceof ClosedChannelException) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("channel closed: {}", cause.toString());
}
return;
} else if (cause instanceof IOException) {
String message = cause.getMessage();
if (message != null && message.contains("Connection reset by peer")) {
LOGGER.debug(message);
} else if (cause instanceof NotSslRecordException) {
// Raised when clients try to send unencrypted data over an encrypted channel
// This can happen when old instances of the Admin UI are running because the
// ports of HTTP/HTTPS are the same.
LOGGER.debug("Received unencrypted message from '{}'", ctx.channel().remoteAddress());
} else {
LOGGER.warn(message, cause);
}
return;
}
HttpResponseStatus status;
String body = null;
if (cause instanceof DigestMismatchException || cause instanceof BlobsDisabledException || cause instanceof IllegalArgumentException) {
status = HttpResponseStatus.BAD_REQUEST;
body = String.format(Locale.ENGLISH, "Invalid request sent: %s", cause.getMessage());
} else if (cause instanceof DigestNotFoundException || cause instanceof IndexNotFoundException) {
status = HttpResponseStatus.NOT_FOUND;
} else if (cause instanceof EsRejectedExecutionException) {
status = HttpResponseStatus.TOO_MANY_REQUESTS;
body = String.format(Locale.ENGLISH, "Rejected execution: %s", cause.getMessage());
} else {
status = HttpResponseStatus.INTERNAL_SERVER_ERROR;
body = String.format(Locale.ENGLISH, "Unhandled exception: %s", cause);
}
if (body != null) {
LOGGER.debug(body);
}
simpleResponse(null, status, body);
}
Aggregations