Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caught an exception on ClientToProxyConnection #427

Open
p0po opened this issue Dec 24, 2018 · 0 comments
Open

Caught an exception on ClientToProxyConnection #427

p0po opened this issue Dec 24, 2018 · 0 comments

Comments

@p0po
Copy link

p0po commented Dec 24, 2018

we use littleproxy as http gateway in our website and set MaximumRequestBufferSize 4 * 1024 * 1024 bytes,it works well.

                    @Override
                    public int getMaximumRequestBufferSizeInBytes() {
                        return 4 * 1024 * 1024;
                    }

my server will log exception if a request bigger than 4 * 1024 * 1024:

[LittleProxy-0-ClientToProxyWorker-6] ERROR 
org.littleshoot.proxy.impl.ClientToProxyConnection -
 (AWAITING_INITIAL) [id: 0x61f4380b, L:/127.0.0.1:1802 - R:/127.0.0.1:37259]: 
Caught an exception on ClientToProxyConnection
io.netty.handler.codec.TooLongFrameException: HTTP content length exceeded 4194304 bytes.

and it will return bad request tips(http code:500) to the user, it will make the user confused.
how can i set specific tips response my user,such as:your request is too big?

I find these code in class org.littleshoot.proxy.impl.DefaultHttpProxyServer:

ChannelInitializer<Channel> initializer = new ChannelInitializer<Channel>() {
            protected void initChannel(Channel ch) throws Exception {
                new ClientToProxyConnection(
                        DefaultHttpProxyServer.this,
                        sslEngineSource,
                        authenticateSslClients,
                        ch.pipeline(),
                        globalTrafficShapingHandler);
            };
        };

in class io.netty.handler.codec.http.HttpObjectAggregator

if (content.readableBytes() > maxContentLength - chunk.content().readableBytes()) {
                // release current message to prevent leaks
                currentMessage.release();
                currentMessage = null;

                throw new TooLongFrameException(
                        "HTTP content length exceeded " + maxContentLength +
                        " bytes.");
            }

in class org.littleshoot.proxy.impl.ClientToProxyConnection

@Override
    protected void exceptionCaught(Throwable cause) {
        try {
            if (cause instanceof IOException) {
                // IOExceptions are expected errors, for example when a browser is killed and aborts a connection.
                // rather than flood the logs with stack traces for these expected exceptions, we log the message at the
                // INFO level and the stack trace at the DEBUG level.
                LOG.info("An IOException occurred on ClientToProxyConnection: " + cause.getMessage());
                LOG.debug("An IOException occurred on ClientToProxyConnection", cause);
            } else if (cause instanceof RejectedExecutionException) {
                LOG.info("An executor rejected a read or write operation on the ClientToProxyConnection (this is normal if the proxy is shutting down). Message: " + cause.getMessage());
                LOG.debug("A RejectedExecutionException occurred on ClientToProxyConnection", cause);
            } else {
                LOG.error("Caught an exception on ClientToProxyConnection", cause);
            }
        } finally {
            // always disconnect the client when an exception occurs on the channel
            disconnect();
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant