Created
May 24, 2020 15:38
-
-
Save marten-seemann/1cb0d87a43935c377c9e59a49c3dbc71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/tls" | |
"flag" | |
"fmt" | |
"io" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"os" | |
"github.com/lucas-clemente/quic-go" | |
"github.com/lucas-clemente/quic-go/http3" | |
) | |
func main() { | |
useQUIC := flag.Bool("quic", false, "use QUIC") | |
flag.Parse() | |
url := flag.Arg(0) | |
if flag.NArg() < 1 { | |
flag.Usage() | |
os.Exit(1) | |
} | |
if err := run(url, *useQUIC); err != nil { | |
log.Fatal(err) | |
} | |
} | |
func run(url string, useQUIC bool) error { | |
cl := http.Client{} | |
if useQUIC { | |
cl.Transport = &http3.RoundTripper{ | |
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, | |
QuicConfig: &quic.Config{ | |
GetLogWriter: func(connID []byte) io.WriteCloser { | |
filename := fmt.Sprintf("%x.qlog", connID) | |
f, err := os.Create(filename) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println("Created", filename) | |
return f | |
}, | |
}, | |
} | |
} else { | |
cl.Transport = &http.Transport{ | |
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, | |
} | |
} | |
resp, err := cl.PostForm(url, map[string][]string{ | |
"foo": []string{"bar"}, | |
"key": []string{"val1", "val2"}, | |
}) | |
if err != nil { | |
return err | |
} | |
fmt.Printf("Received response: %#v\n", resp) | |
body, err := ioutil.ReadAll(resp.Body) | |
if err != nil { | |
return err | |
} | |
fmt.Println("Body:", string(body)) | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment