TCP Proxy with Tokio futures

Hi! This is my first post here. I'm trying to write a simple TCP proxy using Tokio and its async features.
I followed the example from the documentation and it works correctly.
I'm now trying to modify it so that it stores the content of both the request and the response in a buffer so I can read/change the content more easily, but that brakes the chain.

In particular the initial synchronisation step works correctly but once the request has to be sent to the server it stops until the client sends the timeout FIN-ACK, then the request is sent correctly to the server and the response gets back to the client HalfWriter, but since the client already disconnected I receive an error.

I already tried changing the position of the shutdown calls; having both the shutdown calls at the very end or building a chain in the order of execution; calling flush after the write; ...

Can anybody point out what the problem on my code is?

Here is the complete code:
Thank you in advance!

I'll answer my own question in case someone else gets the same issue.

The simplest solution is probably to use a Sink and a Stream pair from the two TCP connections. You can use the Framed structure to easily build one. You'll need a codec, I'm using a custom one since I need to change the contents of the messages, but a simple one like the LinesCodec is good enough for testing.

To concatenate a stream to a sink you can call the method forward of the stream.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.