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

Updates activator to support h2c #1260

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions cmd/activator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import (
"github.com/knative/serving/pkg/activator"
clientset "github.com/knative/serving/pkg/client/clientset/versioned"
"github.com/knative/serving/pkg/controller"
h2cutil "github.com/knative/serving/pkg/h2c"
"github.com/knative/serving/pkg/signals"
"github.com/knative/serving/third_party/h2c"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
Expand All @@ -45,7 +47,13 @@ type activationHandler struct {
type retryRoundTripper struct{}

func (rrt retryRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
transport := http.DefaultTransport
var transport http.RoundTripper

transport = http.DefaultTransport
if r.ProtoMajor == 2 {
transport = h2cutil.NewTransport()
}

resp, err := transport.RoundTrip(r)
// TODO: Activator should retry with backoff.
// https://github.com/knative/serving/issues/1229
Expand Down Expand Up @@ -79,9 +87,11 @@ func (a *activationHandler) handler(w http.ResponseWriter, r *http.Request) {
}
proxy := httputil.NewSingleHostReverseProxy(target)
proxy.Transport = retryRoundTripper{}

// TODO: Clear the host to avoid 404's.
// https://github.com/elafros/elafros/issues/964
r.Host = ""

proxy.ServeHTTP(w, r)
}

Expand Down Expand Up @@ -114,5 +124,5 @@ func main() {
}()

http.HandleFunc("/", ah.handler)
http.ListenAndServe(":8080", nil)
}
h2c.ListenAndServe(":8080", nil)
}
21 changes: 21 additions & 0 deletions pkg/h2c/transport.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package h2c

import (
"crypto/tls"
"net"
"net/http"

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

// NewTransport will reroute all https traffic to http. This is
// to explicitly allow h2c (http2 without TLS) transport.
// See https://github.com/golang/go/issues/14141 for more details.
func NewTransport() http.RoundTripper {
return &http2.Transport{
AllowHTTP: true,
DialTLS: func(netw, addr string, cfg *tls.Config) (net.Conn, error) {
return net.Dial(netw, addr)
},
}
}
Loading