goybley
CDCloudflare Developers
•Created by goybley on 2/13/2024 in #general-help
Golang http.Client{} blocked by cloudflare
I have a Go service behind cloudflare (backup.foo.com/push) that I have tested with CURL/chrome and I have verified that it works and is indeed accessible. However, when using Golang's http.Client{} to make a POST request to the service, it returns the following:
client.go
Server responded with status code 500 Internal Server Error
2024/02/13 08:32:19 Body bytes:
<html>
<head><title>500 Internal Server Error</title></head>
<body>
<center><h1>500 Internal Server Error</h1></center>
<hr><center>cloudflare</center>
</body>
</html>
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
Server responded with status code 500 Internal Server Error
2024/02/13 08:32:19 Body bytes:
<html>
<head><title>500 Internal Server Error</title></head>
<body>
<center><h1>500 Internal Server Error</h1></center>
<hr><center>cloudflare</center>
</body>
</html>
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
...
req, err := http.NewRequest(http.MethodPost, serverURL, tarballReader)
if err != nil {
log.Fatalf("Error creating tarball request: %v\n", err)
}
req.Header.Set("timestamp", startTime.Format(time.RFC3339))
req.Header.Set("Authorization", "MYAUTHTOKEN")
req.Header.Set("Content-Type", "application/gzip")
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_7; en-US) AppleWebKit/537.44 (KHTML, like Gecko) Chrome/48.0.2965.325 Safari/601")
log.Println("Starting serverside pg_restore request...")
httpReqStartTime := time.Now()
resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatalf("Error pushing tarball to remote server: %v\n", err)
}
defer resp.Body.Close()
log.Printf("Server responded with status code %v\n", resp.Status)
...
...
req, err := http.NewRequest(http.MethodPost, serverURL, tarballReader)
if err != nil {
log.Fatalf("Error creating tarball request: %v\n", err)
}
req.Header.Set("timestamp", startTime.Format(time.RFC3339))
req.Header.Set("Authorization", "MYAUTHTOKEN")
req.Header.Set("Content-Type", "application/gzip")
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_7; en-US) AppleWebKit/537.44 (KHTML, like Gecko) Chrome/48.0.2965.325 Safari/601")
log.Println("Starting serverside pg_restore request...")
httpReqStartTime := time.Now()
resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatalf("Error pushing tarball to remote server: %v\n", err)
}
defer resp.Body.Close()
log.Printf("Server responded with status code %v\n", resp.Status)
...
3 replies