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

Make HTTP/1 transports a behaviour #10

Closed
wants to merge 1 commit into from

Conversation

whatyouhide
Copy link
Contributor

@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 by XHTTP1 and XHTTP2 because XHTTP2 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. :)

@whatyouhide
Copy link
Contributor Author

\cc @fishcakez @josevalim, would love your take as well :)

@josevalim
Copy link
Contributor

  • if all we do is delegate (except for the message tags)
  • we don't plan to have any new transport for the foreseeable future

👎 on a behaviour. We can always add it later.

@michalmuskala
Copy link

michalmuskala commented Dec 27, 2017

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 gen_tcp or ssl and correctly dealing with it: https://github.com/heroku/ranch_proxy_protocol

@whatyouhide
Copy link
Contributor Author

@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.

@fishcakez
Copy link

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 (:prim_inet) and ssl (:ssl).

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.

@ericmj
Copy link
Member

ericmj commented Dec 27, 2017

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

@fishcakez
Copy link

We could use packet: 4 to force chunking

@whatyouhide
Copy link
Contributor Author

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.

@ericmj
Copy link
Member

ericmj commented Dec 27, 2017

Go ahead! 👍

@whatyouhide whatyouhide deleted the al/transport-behaviour branch December 27, 2017 21:09
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.

5 participants