Skip to content

Commit

Permalink
add simple logging about HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kortemik authored May 6, 2024
1 parent c9de197 commit 2d588a2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/teragrep/lsh_01/HttpInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
package com.teragrep.lsh_01;

import com.teragrep.lsh_01.config.InternalEndpointUrlConfig;
import com.teragrep.lsh_01.util.LoggingHttpObjectAggregator;
import com.teragrep.lsh_01.util.SslHandlerProvider;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpContentDecompressor;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.ssl.SslHandler;
Expand Down Expand Up @@ -67,7 +67,7 @@ protected void initChannel(SocketChannel socketChannel) throws Exception {
}
pipeline.addLast(new HttpServerCodec());
pipeline.addLast(new HttpContentDecompressor());
pipeline.addLast(new HttpObjectAggregator(maxContentLength));
pipeline.addLast(new LoggingHttpObjectAggregator(maxContentLength));
pipeline
.addLast(
new HttpServerHandler(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
logstash-http-input to syslog bridge
Copyright 2024 Suomen Kanuuna Oy
Derivative Work of Elasticsearch
Copyright 2012-2015 Elasticsearch
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.teragrep.lsh_01.util;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.HttpMessage;
import io.netty.handler.codec.http.HttpObjectAggregator;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class LoggingHttpObjectAggregator extends HttpObjectAggregator {

private static final Logger LOGGER = LogManager.getLogger(LoggingHttpObjectAggregator.class);

public LoggingHttpObjectAggregator(int maxContentLength) {
super(maxContentLength);
}

public LoggingHttpObjectAggregator(int maxContentLength, boolean closeOnExpectationFailed) {
super(maxContentLength, closeOnExpectationFailed);
}

@Override
protected void handleOversizedMessage(ChannelHandlerContext ctx, HttpMessage oversized) throws Exception {
LOGGER.warn("Oversized HTTP message received, exceeds maxContentLength <{}>", maxContentLength());
super.handleOversizedMessage(ctx, oversized);
}

}

0 comments on commit 2d588a2

Please sign in to comment.