-
Notifications
You must be signed in to change notification settings - Fork 113
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
Make HTTP/1 transports a behaviour #10
Conversation
\cc @fishcakez @josevalim, would love your take as well :) |
👎 on a behaviour. We can always add it later. |
One example where a custom transport is useful in practice is when dealing with the PROXY protocol http://www.haproxy.org/download/1.8/doc/proxy-protocol.txt The ranch architecture allows defining a separate transport wrapping |
@josevalim those are good points, but they don't really take some kind of mocking for testing into consideration. I think if we want to mock properly in tests, this might be the way to go but I am not sure. |
I am 👎 on adding a behavior too, with the added reason that I think the behavior becomes outdated at OTP 21 and we will want to use a different function calls for tcp ( I don't think the ability to mock a socket in tests is an issue because it is trivial to create a pair of connected sockets and send/recv data from the peer - easier than setting up a custom transport. |
A possible problem with using sockets for tests is that we don't control what kind of buffering happens in the TCP stack. We have tests where we specifically want to send specific chunks of bytes and I'm not sure if we can get those guarantees when go through the whole stack. https://github.com/ericmj/xhttp/blob/master/test/xhttp1/conn_properties_test.exs#L33-L54 |
We could use packet: 4 to force chunking |
Yeah that can work as well. @ericmj if you're on board, I'll kill this PR then and move tests to use a socket instead of a mock. I hope there won't be a performance hit for tests. |
Go ahead! 👍 |
@ericmj this is how a behaviour for transports would look like I think. IMO it looks really good, and the changes are quite contained. The ugliest change is in the
Conn.stream/2
function which now has to find the message tags for the given transport and dispatch based on that as well, but I think keeping the pattern matching and everything it's still very readable.I also had to go with
XHTTP1.Transport
instead of a transport shared byXHTTP1
andXHTTP2
becauseXHTTP2
requires stuff like:ssl.negotiated_protocol/2
. We could go ahead and make those calls optional so that we can share transports. We can see later on though. :)