use of io.netty.handler.codec.http.HttpResponseStatus in project knotx by Cognifide.
the class ResponseProviderKnotProxyImpl method processError.
@Override
protected KnotContext processError(KnotContext knotContext, Throwable error) {
HttpResponseStatus statusCode;
if (error instanceof NoSuchElementException) {
statusCode = HttpResponseStatus.NOT_FOUND;
} else {
statusCode = HttpResponseStatus.INTERNAL_SERVER_ERROR;
}
knotContext.getClientResponse().setStatusCode(statusCode.code());
return knotContext;
}
use of io.netty.handler.codec.http.HttpResponseStatus in project knotx by Cognifide.
the class FragmentSplitterKnotProxyImpl method processError.
@Override
protected KnotContext processError(KnotContext knotContext, Throwable error) {
HttpResponseStatus statusCode;
if (error instanceof NoSuchElementException) {
statusCode = HttpResponseStatus.NOT_FOUND;
} else {
statusCode = HttpResponseStatus.INTERNAL_SERVER_ERROR;
}
knotContext.getClientResponse().setStatusCode(statusCode.code());
return knotContext;
}
use of io.netty.handler.codec.http.HttpResponseStatus in project xipki by xipki.
the class HealthCheckServlet method service0.
private FullHttpResponse service0(FullHttpRequest request, ServletURI servletUri, SSLSession sslSession) {
HttpVersion version = request.protocolVersion();
HttpMethod method = request.method();
if (method != HttpMethod.GET) {
return createErrorResponse(version, HttpResponseStatus.METHOD_NOT_ALLOWED);
}
try {
if (server == null) {
LOG.error("server in servlet not configured");
return createErrorResponse(version, HttpResponseStatus.INTERNAL_SERVER_ERROR);
}
ResponderAndPath responderAndPath = server.getResponderForPath(servletUri.getPath());
if (responderAndPath == null) {
return createErrorResponse(version, HttpResponseStatus.NOT_FOUND);
}
HealthCheckResult healthResult = server.healthCheck(responderAndPath.getResponder());
HttpResponseStatus status = healthResult.isHealthy() ? HttpResponseStatus.OK : HttpResponseStatus.INTERNAL_SERVER_ERROR;
byte[] respBytes = healthResult.toJsonMessage(true).getBytes();
return createResponse(version, status, HealthCheckServlet.CT_RESPONSE, respBytes);
} catch (Throwable th) {
if (th instanceof EOFException) {
LogUtil.warn(LOG, th, "connection reset by peer");
} else {
LOG.error("Throwable thrown, this should not happen", th);
}
return createErrorResponse(version, HttpResponseStatus.INTERNAL_SERVER_ERROR);
}
}
use of io.netty.handler.codec.http.HttpResponseStatus in project apollo by apollo-rsps.
the class HttpRequestWorker method service.
@Override
protected void service(ResourceProvider provider, Channel channel, HttpRequest request) throws IOException {
String path = request.getUri();
Optional<ByteBuffer> buf = provider.get(path);
HttpResponseStatus status = HttpResponseStatus.OK;
String mime = getMimeType(request.getUri());
if (!buf.isPresent()) {
status = HttpResponseStatus.NOT_FOUND;
mime = "text/html";
}
ByteBuf wrapped = buf.isPresent() ? Unpooled.wrappedBuffer(buf.get()) : createErrorPage(status, "The page you requested could not be found.");
HttpResponse response = new DefaultHttpResponse(request.getProtocolVersion(), status);
response.headers().set("Date", new Date());
response.headers().set("Server", SERVER_IDENTIFIER);
response.headers().set("Content-type", mime + ", charset=" + CHARACTER_SET.name());
response.headers().set("Cache-control", "no-cache");
response.headers().set("Pragma", "no-cache");
response.headers().set("Expires", new Date(0));
response.headers().set("Connection", "close");
response.headers().set("Content-length", wrapped.readableBytes());
channel.write(response);
channel.writeAndFlush(wrapped).addListener(ChannelFutureListener.CLOSE);
}
use of io.netty.handler.codec.http.HttpResponseStatus in project reactor-netty by reactor.
the class HttpServerTests method doTestIssue309.
private void doTestIssue309(String path, Consumer<? super HttpServerOptions.Builder> ops) {
NettyContext server = HttpServer.create(ops).newHandler((req, res) -> res.sendString(Mono.just("Should not be reached"))).block();
Mono<HttpResponseStatus> status = HttpClient.create(server.address().getPort()).get(path, req -> req.failOnClientError(false)).flatMap(res -> {
res.dispose();
HttpResponseStatus code = res.status();
return Mono.just(code);
});
StepVerifier.create(status).expectNextMatches(HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE::equals).expectComplete().verify();
server.dispose();
}
Aggregations