Files
quake-kube/internal/util/net/http/http.go
Chris Marshall 2a599bcff5 Build standalone ioq3ded, fix asset timeout (#16)
When specifying `BUILD_STANDALONE=1` for ioq3ded, the default `com_homepath`, `com_basegame`, and `com_gamename` change to foo/foobar, so this sets those explicitly to their previously default values. This can be exposed via option later to allow for custom games. This also fixes the short read timeout used by CopyAssets.
2020-09-16 17:53:51 -04:00

46 lines
767 B
Go

package http
import (
"io/ioutil"
"net/http"
"time"
"github.com/pkg/errors"
)
func GetBody(url string) ([]byte, error) {
client := http.Client{
Timeout: 5 * time.Minute,
}
resp, err := client.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, errors.Errorf("cannot get url %q: %v", url, http.StatusText(resp.StatusCode))
}
return ioutil.ReadAll(resp.Body)
}
func GetUntil(url string, stop <-chan struct{}) error {
client := http.Client{
Timeout: 1 * time.Second,
}
for {
select {
case <-stop:
return errors.Errorf("not available: %q", url)
default:
resp, err := client.Get(url)
if err != nil {
continue
}
resp.Body.Close()
return nil
}
}
}