Created
June 4, 2019 12:15
-
-
Save mrnugget/149331bd8fd27e4c49e47262174eb8d0 to your computer and use it in GitHub Desktop.
This can be used to reproduce EOF errors while using GitHubs API, because GitHub closes keep-alive connections after 60s.
This file contains hidden or 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 ( | |
"bytes" | |
"fmt" | |
"io" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"net/http/httptrace" | |
"net/url" | |
"time" | |
) | |
func main() { | |
bodyString := "{\"query\":\"\\nfragment RepositoryFields on Repository {\\n\\tid\\n\\tdatabaseId\\n\\tnameWithOwner\\n\\tdescription\\n\\turl\\n\\tisPrivate\\n\\tisFork\\n\\tisArchived\\n\\tviewerPermission\\n}\\n\\tquery {\\nrepo0: repository(owner: \\\"sourcegraph\\\", name: \\\"sourcegraph\\\") { ... on Repository { ...RepositoryFields } }\\n}\",\"variables\":{}}" | |
for { | |
log.Println("Sending new request ---------------------------") | |
body := ioutil.NopCloser(bytes.NewBufferString(bodyString)) | |
headers := make(http.Header) | |
headers.Add("User-Agent", "Go-http-client/1.1") | |
// REPLACE WITH YOUR TOKEN | |
headers.Add("Authorization", "bearer TOKEN") | |
headers.Add("Content-Type", "application/json; charset=utf-8") | |
req := &http.Request{ | |
Method: "POST", | |
Body: body, | |
URL: &url.URL{ | |
Scheme: "https", | |
Host: "api.github.com", | |
Path: "/graphql", | |
RawQuery: "", | |
}, | |
Header: headers, | |
} | |
trace := &httptrace.ClientTrace{ | |
GotConn: func(connInfo httptrace.GotConnInfo) { | |
fmt.Printf("Got Conn: %+v\n", connInfo) | |
}, | |
} | |
req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace)) | |
resp, err := http.DefaultClient.Do(req) | |
if err != nil { | |
fmt.Printf("err=%+v\n", err) | |
return | |
} | |
defer resp.Body.Close() | |
io.Copy(ioutil.Discard, resp.Body) | |
time.Sleep(time.Duration(60) * time.Second) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment