tc native update to 2.0.31, more flexible acceptRequest

This commit is contained in:
Jörg Prante 2020-07-08 18:58:23 +02:00
parent 2c25413323
commit ad3fd4fcac
6 changed files with 17 additions and 11 deletions

View file

@ -1,11 +1,11 @@
group = org.xbib group = org.xbib
name = netty-http name = netty-http
version = 4.1.50.2 version = 4.1.50.3
gradle.wrapper.version = 6.4.1 gradle.wrapper.version = 6.4.1
netty.version = 4.1.50.Final netty.version = 4.1.50.Final
tcnative.version = 2.0.29.Final tcnative.version = 2.0.31.Final
tcnative-legacy-macosx.version = 2.0.26.Final tcnative-legacy-macosx.version = 2.0.31.Final
xbib.net.version = 2.1.0 xbib.net.version = 2.1.0
bouncycastle.version = 1.64 bouncycastle.version = 1.64
reactivestreams.version = 1.0.2 reactivestreams.version = 1.0.2

View file

@ -55,7 +55,9 @@ public abstract class ResourceService implements Filter {
protected abstract int getMaxAgeSeconds(); protected abstract int getMaxAgeSeconds();
private void handleCachedResource(ServerRequest serverRequest, ServerResponse serverResponse, Resource resource) { private void handleCachedResource(ServerRequest serverRequest, ServerResponse serverResponse, Resource resource) {
logger.log(Level.FINE, "resource = " + resource); if (logger.isLoggable(Level.FINER)) {
logger.log(Level.FINER, "resource = " + resource);
}
if (resource.isDirectory()) { if (resource.isDirectory()) {
if (!resource.getResourcePath().isEmpty() && !resource.getResourcePath().endsWith("/")) { if (!resource.getResourcePath().isEmpty() && !resource.getResourcePath().endsWith("/")) {
// external redirect to // external redirect to

View file

@ -93,8 +93,8 @@ public class Http1ChannelInitializer extends ChannelInitializer<Channel>
pipeline.addLast("http-server-decompressor", pipeline.addLast("http-server-decompressor",
new HttpContentDecompressor()); new HttpContentDecompressor());
} }
HttpObjectAggregator httpObjectAggregator = new HttpObjectAggregator(serverConfig.getMaxContentLength(), HttpObjectAggregator httpObjectAggregator =
false); new HttpObjectAggregator(serverConfig.getMaxContentLength());
httpObjectAggregator.setMaxCumulationBufferComponents(serverConfig.getMaxCompositeBufferComponents()); httpObjectAggregator.setMaxCumulationBufferComponents(serverConfig.getMaxCompositeBufferComponents());
pipeline.addLast("http-server-aggregator", httpObjectAggregator); pipeline.addLast("http-server-aggregator", httpObjectAggregator);
pipeline.addLast("http-server-pipelining", new HttpPipeliningHandler(serverConfig.getPipeliningCapacity())); pipeline.addLast("http-server-pipelining", new HttpPipeliningHandler(serverConfig.getPipeliningCapacity()));
@ -142,7 +142,7 @@ public class Http1ChannelInitializer extends ChannelInitializer<Channel>
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
logger.log(Level.WARNING, cause.getMessage(), cause); logger.log(Level.SEVERE, cause.getMessage(), cause);
ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
HttpResponseStatus.INTERNAL_SERVER_ERROR, HttpResponseStatus.INTERNAL_SERVER_ERROR,
Unpooled.copiedBuffer(cause.getMessage().getBytes(StandardCharsets.UTF_8)))); Unpooled.copiedBuffer(cause.getMessage().getBytes(StandardCharsets.UTF_8))));

View file

@ -6,6 +6,7 @@ import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion; import io.netty.handler.codec.http.HttpVersion;
import org.xbib.netty.http.server.Server; import org.xbib.netty.http.server.Server;
import org.xbib.netty.http.server.ServerConfig;
import org.xbib.netty.http.server.api.ServerRequest; import org.xbib.netty.http.server.api.ServerRequest;
import org.xbib.netty.http.server.api.ServerResponse; import org.xbib.netty.http.server.api.ServerResponse;
import org.xbib.netty.http.server.api.ServerTransport; import org.xbib.netty.http.server.api.ServerTransport;
@ -33,12 +34,15 @@ abstract class BaseTransport implements ServerTransport {
* and required special header handling, possibly returning an * and required special header handling, possibly returning an
* appropriate response. * appropriate response.
* *
* @param version the HTTP version of the server * @param serverConfig the server config
* @param serverRequest the request * @param serverRequest the request
* @param serverResponse the response * @param serverResponse the response
* @return whether further processing should be performed * @return whether further processing should be performed
*/ */
static boolean acceptRequest(HttpVersion version, ServerRequest serverRequest, ServerResponse serverResponse) { static boolean acceptRequest(ServerConfig serverConfig,
ServerRequest serverRequest,
ServerResponse serverResponse) {
HttpVersion version = serverConfig.getAddress().getVersion();
HttpHeaders reqHeaders = serverRequest.getHeaders(); HttpHeaders reqHeaders = serverRequest.getHeaders();
if (version.majorVersion() == 1 || version.majorVersion() == 2) { if (version.majorVersion() == 1 || version.majorVersion() == 2) {
if (!reqHeaders.contains(HttpHeaderNames.HOST)) { if (!reqHeaders.contains(HttpHeaderNames.HOST)) {

View file

@ -25,7 +25,7 @@ public class Http1Transport extends BaseTransport {
serverRequest.setSession(sslHandler.engine().getSession()); serverRequest.setSession(sslHandler.engine().getSession());
} }
HttpServerResponse serverResponse = new HttpServerResponse(server, serverRequest, ctx); HttpServerResponse serverResponse = new HttpServerResponse(server, serverRequest, ctx);
if (acceptRequest(server.getServerConfig().getAddress().getVersion(), serverRequest, serverResponse)) { if (acceptRequest(server.getServerConfig(), serverRequest, serverResponse)) {
serverRequest.handleParameters(); serverRequest.handleParameters();
server.handle(serverRequest, serverResponse); server.handle(serverRequest, serverResponse);
} else { } else {

View file

@ -27,7 +27,7 @@ public class Http2Transport extends BaseTransport {
serverRequest.setRequestId(server.getRequestCounter().incrementAndGet()); serverRequest.setRequestId(server.getRequestCounter().incrementAndGet());
serverRequest.setStreamId(fullHttpRequest.headers().getInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text())); serverRequest.setStreamId(fullHttpRequest.headers().getInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text()));
ServerResponse serverResponse = new Http2ServerResponse(server, serverRequest, ctx); ServerResponse serverResponse = new Http2ServerResponse(server, serverRequest, ctx);
if (acceptRequest(server.getServerConfig().getAddress().getVersion(), serverRequest, serverResponse)) { if (acceptRequest(server.getServerConfig(), serverRequest, serverResponse)) {
serverRequest.handleParameters(); serverRequest.handleParameters();
server.handle(serverRequest, serverResponse); server.handle(serverRequest, serverResponse);
} else { } else {