Skip to content
This repository has been archived by the owner on Sep 17, 2019. It is now read-only.

Exporting Server.handleConn #69

Closed
soheilhy opened this issue Jul 29, 2015 · 7 comments
Closed

Exporting Server.handleConn #69

soheilhy opened this issue Jul 29, 2015 · 7 comments

Comments

@soheilhy
Copy link

Server.handleConn is the minimum required to implement an http2 server outside net/http, say to implement h2c:

s := &http.Server{
    Handler: &myHandler{},
}
s2 := &http2.Server{}
for {
    c, err := l.Accept()
    if err != nil {
        if terr, ok := err.(net.Error); ok && terr.Temporary() {
            continue
        }
        return
    }
    go s2.HandleConn(s, c, s.Handler)
}

I have another selfish reason for that. I've built a connection multiplexer that sniffs connections to multiplex them. Using that, I can run net/rpc, gRPC, and HTTP1.1 on the same port. However, I can't do that for HTTP2 because I have to wrap the actual connection in a cmux connection. So, the "fake" connection is not a *tls.Conn and TLSNextProto handlers would never be called for HTTP2 flows.

Would you please consider exporting this method?

Just in case, I confirm that using the snippet above I can serve h2 (i.e., chrome) and gRPC/TLS traffic on the same port.

@soheilhy soheilhy changed the title Export Server.handleConn Exporting Server.handleConn Jul 31, 2015
@kennylevinsen
Copy link

+1 - I would very much like this exposed for the very same reasons (The ability to serve h2 where TLS has already been handled by other mechanisms, and the negotiated protocol has been determined to be h2 or h2-14).

Apart from exposing the ability to start a h2 connection, it would also make it "easier" to have the HTTP server eat accepted net.Conns, rather than having to make a "fake" net.Listener.

@philips
Copy link

philips commented Aug 6, 2015

cc @xiang90

@kennylevinsen
Copy link

I have made this change in my fork https://github.com/joushou/http2 (branch "exposehandleconn").

However, the branch "exposeserve" holds what I think is a cleaner solution, if we want to do something like this for both http1 and http2. Instead of HandleConn, one could have a NewH2Conn, that sets up a serverConn and returns it. serverConn would then have Serve exposed.

One would then be able to expose Serve on HTTP/1.1 connections, allowing for a similar functionality on both protocols, depending on whether one calls NewH2Conn or NewH1Conn (probably named differently).

I'd like some feedback on the general idea before I submit a pull request, unless people would rather just see the code.

(For the record: The master branch, including import adjustments of course, include exposeserve and functions fine for me in serve2d)

@philips
Copy link

philips commented Sep 17, 2015

Any update on this @bradfitz or @bmizerany?

@bradfitz
Copy link
Owner

Sorry, I haven't done it yet.

@bradfitz
Copy link
Owner

This repo just moved into the official Go repo.

See https://github.com/bradfitz/http2/blob/master/README for the move details.

File new bugs at: https://github.com/golang/go/issues/new?title=x/net/http2:+

Closing this bug, but please copy it to the main repo if still relevant or desired. Thanks!

@kennylevinsen
Copy link

@bradfitz Will do. Thank you for your effort in providing us HTTP/2.0 support!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants