File tree 4 files changed +45
-3
lines changed
4 files changed +45
-3
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,8 @@ import (
59
59
"github.com/labstack/gommon/log"
60
60
"golang.org/x/crypto/acme"
61
61
"golang.org/x/crypto/acme/autocert"
62
+ "golang.org/x/net/http2"
63
+ "golang.org/x/net/http2/h2c"
62
64
)
63
65
64
66
type (
@@ -723,6 +725,34 @@ func (e *Echo) StartServer(s *http.Server) (err error) {
723
725
return s .Serve (e .TLSListener )
724
726
}
725
727
728
+ // StartH2CServer starts a custom http/2 server with h2c (HTTP/2 Cleartext).
729
+ func (e * Echo ) StartH2CServer (address string , h2s * http2.Server ) (err error ) {
730
+ // Setup
731
+ s := e .Server
732
+ s .Addr = address
733
+ e .colorer .SetOutput (e .Logger .Output ())
734
+ s .ErrorLog = e .StdLogger
735
+ s .Handler = h2c .NewHandler (e , h2s )
736
+ if e .Debug {
737
+ e .Logger .SetLevel (log .DEBUG )
738
+ }
739
+
740
+ if ! e .HideBanner {
741
+ e .colorer .Printf (banner , e .colorer .Red ("v" + Version ), e .colorer .Blue (website ))
742
+ }
743
+
744
+ if e .Listener == nil {
745
+ e .Listener , err = newListener (s .Addr )
746
+ if err != nil {
747
+ return err
748
+ }
749
+ }
750
+ if ! e .HidePort {
751
+ e .colorer .Printf ("⇨ http server started on %s\n " , e .colorer .Green (e .Listener .Addr ()))
752
+ }
753
+ return s .Serve (e .Listener )
754
+ }
755
+
726
756
// Close immediately stops the server.
727
757
// It internally calls `http.Server#Close()`.
728
758
func (e * Echo ) Close () error {
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import (
14
14
15
15
"github.com/stretchr/testify/assert"
16
16
"github.com/stretchr/testify/require"
17
+ "golang.org/x/net/http2"
17
18
)
18
19
19
20
type (
@@ -512,6 +513,17 @@ func TestEchoStartAutoTLS(t *testing.T) {
512
513
}
513
514
}
514
515
516
+ func TestEchoStartH2CServer (t * testing.T ) {
517
+ e := New ()
518
+ e .Debug = true
519
+ h2s := & http2.Server {}
520
+
521
+ go func () {
522
+ assert .NoError (t , e .StartH2CServer (":0" , h2s ))
523
+ }()
524
+ time .Sleep (200 * time .Millisecond )
525
+ }
526
+
515
527
func testMethod (t * testing.T , method , path string , e * Echo ) {
516
528
p := reflect .ValueOf (path )
517
529
h := reflect .ValueOf (func (c Context ) error {
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ require (
10
10
github.com/stretchr/testify v1.4.0
11
11
github.com/valyala/fasttemplate v1.1.0
12
12
golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876
13
- golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect
13
+ golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa
14
14
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8 // indirect
15
15
golang.org/x/text v0.3.2 // indirect
16
16
)
Original file line number Diff line number Diff line change @@ -29,8 +29,8 @@ golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876 h1:sKJQZMuxjOAR/Uo2LBfU90
29
29
golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876 /go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto =
30
30
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ =
31
31
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 /go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg =
32
- golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8 =
33
- golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 /go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s =
32
+ golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA =
33
+ golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa /go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s =
34
34
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a /go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY =
35
35
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 /go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY =
36
36
golang.org/x/sys v0.0.0-20190412213103-97732733099d /go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs =
You can’t perform that action at this time.
0 commit comments