Skip to content

Commit

Permalink
TT-968 enabled h2c by default (TykTechnologies#3380)
Browse files Browse the repository at this point in the history
* fix grpc proxy connection

* clean and format code

* clean code

* remove h2c config from gateway config

* replace h2c protocol from url and set it as http

* removed config enable_h2c at api level and infer it from the target url which should contains h2c://

* update grpc test

* gofmt gw file

* enabled h2c by default to http servers

* remove duplicated registeering of healthcheck

Co-authored-by: tbuchaillot <[email protected]>
  • Loading branch information
sredxny and tbuchaillot authored Feb 17, 2021
1 parent 17b0f15 commit 5c8870a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions gateway/api_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func processSpec(spec *APISpec, apisByListen map[string]int,
"prefix": "coprocess",
})


if strings.Contains(spec.Proxy.TargetURL, "h2c://") {
spec.Proxy.TargetURL = strings.Replace(spec.Proxy.TargetURL, "h2c://", "http://", 1)
}
Expand Down
12 changes: 6 additions & 6 deletions gateway/proxy_muxer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import (
"sync/atomic"
"time"

"golang.org/x/net/http2/h2c"

"github.com/TykTechnologies/again"
"github.com/TykTechnologies/tyk/config"
"github.com/TykTechnologies/tyk/tcp"
proxyproto "github.com/pires/go-proxyproto"
cache "github.com/pmylund/go-cache"

"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"

"github.com/gorilla/mux"
"github.com/sirupsen/logrus"
"golang.org/x/net/http2"
)

// handleWrapper's only purpose is to allow router to be dynamically replaced
Expand Down Expand Up @@ -126,6 +126,7 @@ func (m *proxyMux) router(port int, protocol string) *mux.Router {
}

func (m *proxyMux) setRouter(port int, protocol string, router *mux.Router) {

if port == 0 {
port = config.Global().ListenPort
}
Expand Down Expand Up @@ -401,6 +402,7 @@ func (m *proxyMux) serve() {
}
var h http.Handler
h = &handleWrapper{p.router}

if p.protocol == "h2c" {
// wrapping handler in h2c. This ensures all features including tracing work
// in h2c services.
Expand All @@ -410,6 +412,7 @@ func (m *proxyMux) serve() {
h: h2c.NewHandler(p.router, h2s),
}
}

addr := config.Global().ListenAddress + ":" + strconv.Itoa(p.port)
p.httpServer = &http.Server{
Addr: addr,
Expand All @@ -421,11 +424,8 @@ func (m *proxyMux) serve() {
if config.Global().CloseConnections {
p.httpServer.SetKeepAlivesEnabled(false)
}

go p.httpServer.Serve(p.listener)

}

p.started = true
}
}
Expand Down

0 comments on commit 5c8870a

Please sign in to comment.