Created
April 26, 2016 01:06
-
-
Save nemosupremo/4edf9c5ded1e17d335e1d959718e93e8 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" | |
"io" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"os" | |
"strings" | |
"github.com/nemothekid/net/http2" | |
) | |
func main() { | |
serverURL := "https://localhost:1333" | |
if envServURL := os.Getenv("SERVER_URL"); envServURL != "" { | |
serverURL = envServURL | |
} | |
/* | |
I commented the keypair code as I using a real SSL/TLS cert. | |
certs, err := tls.LoadX509KeyPair("key.crt", "key.key") | |
if err != nil { | |
log.Fatal(err) | |
} | |
tr := &http.Transport{ | |
TLSClientConfig: &tls.Config{ | |
Certificates: []tls.Certificate{certs}, | |
InsecureSkipVerify: true, | |
}, | |
} | |
*/ | |
tr := &http.Transport{} | |
http2.ConfigureTransport(tr) | |
client := &http.Client{ | |
Transport: tr, | |
} | |
// Make a GigaByte of data | |
raw := strings.Repeat("A", 1024*1024*1024) | |
log.Printf("len(data)=%v\n", len(raw)) | |
sr := strings.NewReader(raw) | |
req, err := http.NewRequest("POST", serverURL, sr) | |
if err != nil { | |
log.Fatal(err) | |
} | |
log.Printf("client.Do next\n") | |
res, err := client.Do(req) | |
log.Printf("client.Do done\n") | |
if err != nil { | |
log.Fatal(err) | |
} | |
n, err := io.Copy(ioutil.Discard, res.Body) | |
log.Printf("done Reading the server response's body n=(%v) err=%v\nres.headers: %v\n", n, err, res.Header) | |
_ = res.Body.Close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment