Skip to content

Commit 8b2d06a

Browse files
authored
Merge pull request #2 from fortio/h2c_working
h2c now workin Thx to fix for golang/go#52882
2 parents 2d520e4 + 9288d13 commit 8b2d06a

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ test:
55
go run -race . -config sampleConfig/ -redirect-port :8080 -https-port :8443
66

77
dev-grpc:
8-
go run -race . -http-port 8001 -https-port disabled -redirect-port disabled\
9-
-routes.json '[{"host":"*", "destination":"h2c://localhost:8079/"}]'
8+
go run -race . -h2 -http-port 8001 -https-port disabled -redirect-port disabled\
9+
-routes.json '[{"host":"*", "destination":"http://localhost:8079/"}]'
1010

1111
dev-h2c:
12-
go run -race . -http-port 8001 -https-port disabled -redirect-port disabled\
13-
-routes.json '[{"host":"*", "destination":"h2c://localhost:8080/"}]'
12+
go run -race . -h2 -http-port 8001 -https-port disabled -redirect-port disabled\
13+
-routes.json '[{"host":"*", "destination":"http://localhost:8080/"}]'
1414

1515
dev:
1616
go run -race . -http-port 8001 -https-port disabled -redirect-port disabled\

go.mod

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ go 1.18
55
require (
66
fortio.org/fortio v1.31.0
77
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
8+
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2
89
)
910

1011
require (
1112
github.com/fsnotify/fsnotify v1.5.4 // indirect
1213
github.com/google/uuid v1.3.0 // indirect
13-
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
1414
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
1515
golang.org/x/text v0.3.7 // indirect
1616

1717
)
18+
19+
replace golang.org/x/net => github.com/fortio/golang-net v0.0.0-20220519234753-9259fd44fa73 // Has https://go.dev/cl/407454

go.sum

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
fortio.org/fortio v1.31.0 h1:5pwFhai6GNFTKiacKlWF3oRjoveFdMCCoqGoSDyFmIA=
22
fortio.org/fortio v1.31.0/go.mod h1:bubI7klquaD4ypIby16LHMvoH+7lp20NvzALgN4/xlM=
33
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
4+
github.com/fortio/golang-net v0.0.0-20220519234753-9259fd44fa73 h1:Be4/PrR/2GBcLx+lMwu0vo+hH6vq8KcUW1kNCgtcyz0=
5+
github.com/fortio/golang-net v0.0.0-20220519234753-9259fd44fa73/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
46
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
57
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
68
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
79
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
810
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
911
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
10-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
1112
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
1213
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
13-
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
14-
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA=
15-
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
16-
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
1714
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
15+
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
16+
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1817
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
1918
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
20-
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
19+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
2120
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
2221
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
22+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
2323
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=

proxy_main.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import (
1010
"crypto/tls"
1111
"flag"
1212
"fmt"
13+
"net"
1314
"net/http"
1415
"net/http/httputil"
1516
"net/url"
1617
"os"
1718
"time"
1819

1920
"golang.org/x/crypto/acme/autocert"
21+
"golang.org/x/net/http2"
2022

2123
"fortio.org/fortio/dflag"
2224
"fortio.org/fortio/dflag/configmap"
@@ -62,6 +64,7 @@ func main() {
6264
configDir := flag.String("config", "",
6365
"Config directory `path` to watch for changes of dynamic flags (empty for no watch)")
6466
httpPort := flag.String("http-port", "disabled", "`port` to listen on for non tls traffic (or 'disabled')")
67+
h2Target := flag.Bool("h2", false, "Whether destinations support h2c prior knowledge")
6568
flag.Parse()
6669
_, longV, fullV := version.FromBuildInfo()
6770
log.Infof("Fortio Proxy %s starting", longV)
@@ -91,7 +94,16 @@ func main() {
9194
}
9295
rp := httputil.ReverseProxy{
9396
Director: Director,
94-
// doesn't work: Transport: &http2.Transport{}, // otherwise grpc doesn't work
97+
}
98+
// TODO: make h2c vs regular client more dynamic based on route config instead of all or nothing
99+
// (or maybe some day it will just ge the default behavior of the base http client)
100+
if *h2Target {
101+
rp.Transport = &http2.Transport{
102+
AllowHTTP: true,
103+
DialTLS: func(network, addr string, cfg *tls.Config) (net.Conn, error) {
104+
return net.Dial(network, addr)
105+
},
106+
}
95107
}
96108
s := &http.Server{
97109
// TODO: make these timeouts configurable

0 commit comments

Comments
 (0)