1
0
mirror of https://github.com/taigrr/wasm-experiments synced 2025-01-18 04:03:21 -08:00

Add context test to fetch

This commit is contained in:
Johan Brandhorst 2018-05-28 22:29:06 +01:00
parent b31231ab0a
commit d8c7440fdb
No known key found for this signature in database
GPG Key ID: 266C7D9B44EAA057

View File

@ -15,15 +15,25 @@ func main() {
c := http.Client{ c := http.Client{
Transport: &fetch.Transport{}, Transport: &fetch.Transport{},
} }
resp, err := c.Post( req, err := http.NewRequest(
"POST",
"https://httpbin.org/anything", "https://httpbin.org/anything",
"application/json",
strings.NewReader(`{"test":"test"}`), strings.NewReader(`{"test":"test"}`),
) )
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return return
} }
/*
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*200)
defer cancel()
req = req.WithContext(ctx)
*/
resp, err := c.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer resp.Body.Close() defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body) b, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {