Skip to content

Instantly share code, notes, and snippets.

@ncw
Created June 7, 2022 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ncw/016e5ccdc69000225b03db43e00f8c3a to your computer and use it in GitHub Desktop.
Save ncw/016e5ccdc69000225b03db43e00f8c3a to your computer and use it in GitHub Desktop.
module github.com/ncw/go-issue-53253
go 1.18
replace golang.org/x/net => /opt/go/x/net
require (
golang.org/x/net v0.0.0-20220607020251-c690dde0001d // indirect
golang.org/x/text v0.3.6 // indirect
)
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
package main
import (
"flag"
"fmt"
"io"
"log"
"net/http"
"os"
"time"
"golang.org/x/net/http2"
)
func get(url string) {
t0 := time.Now()
resp, err := http.Head(url)
dt := time.Since(t0)
if err != nil {
log.Printf("Failed to fetch %q: %v", url, err)
return
}
defer resp.Body.Close()
_, err = io.Copy(os.Stdout, resp.Body)
if err != nil && err != io.EOF {
log.Printf("Failed to read from %q: %v", url, err)
return
}
fmt.Println()
log.Printf("%q: read OK", url)
log.Printf("%q: request -> response took %v", url, dt)
}
func main() {
flag.Parse()
// Use the specific version of x/net/http2 in go.mod rather
// than the one bundled with the go compiler
t := http.DefaultTransport.(*http.Transport)
t.TLSNextProto = nil
err := http2.ConfigureTransport(t)
if err != nil {
log.Fatal(err)
}
for _, arg := range flag.Args() {
get(arg)
get(arg)
get(arg)
get(arg)
get(arg)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment