Added the AcceptHandler feature to the proxy.#321
Added the AcceptHandler feature to the proxy.#321flocunto wants to merge 1 commit intoadamfisk:masterfrom
Conversation
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.
|
@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? |
|
@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. 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). |
|
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 |
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.