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

Added the AcceptHandler feature to the proxy. #321

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

flocunto
Copy link

Using the withAcceptHandler() method on the proxy bootstrap is now
possible to get access to the byte stream of the first read performed
on the underlying channel after a connection has been accepted and
before the message is http-parsed inside the channel pipeline.

An implementation of the interface AcceptHandler can be able to read
and/or modify the first bytes sent by a client before they are parsed,
as well as close the connection if some requirements are not met
and so on.

Using the withAcceptHandler() method on the proxy bootstrap is now
possible to get access to the byte stream of the first read performed
on the underlying channel after a connection has been accepted and
before the message is http-parsed inside the channel pipeline.

An implementation of the interface AcceptHandler can be able to read
and/or modify the first bytes sent by a client before they are parsed,
as well as close the connection if some requirements are not met
and so on.
@jekh
Copy link
Collaborator

jekh commented Dec 10, 2016

@flocunto The code change looks fine, but what's the use case? Why not use a filter and simply respond with a 4xx if the request from the client doesn't meet your requirements?

@flocunto
Copy link
Author

@jekh Because accessing the raw bytestream before http parsing is perfomed could be neeed: e.g. in my case I have a "midway" network proxy which prepends a bunch of data to the first http packet sent by a client (special auth data, network config etc.), so I need to parse (and remove it) from the stream before http parsing is done by littleproxy/netty.
It's not possible to parse it using a filter because inside it the http parsing already happened (and in a case like mine an http parsing error occurs of course).

I think the feature is useful whenever we need to access data before they are http parsed. For sure we could extend the feature to all the packets but imho is not needed (such "midway" proxies usually prepend non-http data only to the first packet).

@jekh
Copy link
Collaborator

jekh commented Dec 19, 2016

This use case is pretty unique. In general, I'm not sure we want to encourage registering arbitrary handlers in the ChannelPipeline. That said, you should be able to access the ChannelPipeline already through a filter, and add your handler there. The proxyToServerConnectionSucceeded(ChannelHandlerContext) exposes the context, which gives access to the pipeline. I don't recommend clients modifying the pipeline, but it seems like it would solve your problem.

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

Successfully merging this pull request may close these issues.

2 participants