|
|
@ -7,6 +7,7 @@ package nghttp2
|
|
|
|
import "C"
|
|
|
|
import "C"
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"bytes"
|
|
|
|
|
|
|
|
"crypto/tls"
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io"
|
|
|
@ -80,6 +81,27 @@ func Client(c net.Conn) (*Conn, error) {
|
|
|
|
return conn, nil
|
|
|
|
return conn, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// HTTP2Handler is the http2 server handler that can co-work with standard net/http.
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// usage example:
|
|
|
|
|
|
|
|
// l, err := net.Listen("tcp", ":1222")
|
|
|
|
|
|
|
|
// srv := &http.Server{
|
|
|
|
|
|
|
|
// TLSConfig: &tls.Config{
|
|
|
|
|
|
|
|
// NextProtos:[]string{"h2", "http/1.1"},
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// TLSNextProto: map[string]func(*http.Server, *tls.Conn, http.Handler){
|
|
|
|
|
|
|
|
// "h2": nghttp2.Http2Handler
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// srv.ServeTLS(l, "server.crt", "server.key")
|
|
|
|
|
|
|
|
func HTTP2Handler(srv *http.Server, conn *tls.Conn, handler http.Handler) {
|
|
|
|
|
|
|
|
h2conn, err := Server(conn, handler)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
panic(err.Error())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
h2conn.Run()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Error return conn error
|
|
|
|
// Error return conn error
|
|
|
|
func (c *Conn) Error() error {
|
|
|
|
func (c *Conn) Error() error {
|
|
|
|
c.lock.Lock()
|
|
|
|
c.lock.Lock()
|
|
|
|