add timeout to last remaining http get
This commit is contained in:
parent
03720a9aa4
commit
4944996253
16
activity.go
16
activity.go
|
@ -19,7 +19,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"html"
|
"html"
|
||||||
"io"
|
"io"
|
||||||
|
@ -70,7 +69,7 @@ func PostMsg(keyname string, key httpsig.PrivateKey, url string, msg []byte) err
|
||||||
req.Header.Set("User-Agent", "honksnonk/5.0; "+serverName)
|
req.Header.Set("User-Agent", "honksnonk/5.0; "+serverName)
|
||||||
req.Header.Set("Content-Type", theonetruename)
|
req.Header.Set("Content-Type", theonetruename)
|
||||||
httpsig.SignRequest(keyname, key, req, msg)
|
httpsig.SignRequest(keyname, key, req, msg)
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 1 * time.Minute)
|
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
req = req.WithContext(ctx)
|
req = req.WithContext(ctx)
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
|
@ -146,14 +145,23 @@ func GetJunkTimeout(url string, timeout time.Duration) (junk.Junk, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchsome(url string) ([]byte, error) {
|
func fetchsome(url string) ([]byte, error) {
|
||||||
resp, err := http.Get(url)
|
client := http.DefaultClient
|
||||||
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error fetching %s: %s", url, err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
|
||||||
|
defer cancel()
|
||||||
|
req = req.WithContext(ctx)
|
||||||
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error fetching %s: %s", url, err)
|
log.Printf("error fetching %s: %s", url, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
return nil, errors.New("not 200")
|
return nil, fmt.Errorf("not 200: %d %s", resp.StatusCode, url)
|
||||||
}
|
}
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
limiter := io.LimitReader(resp.Body, 10*1024*1024)
|
limiter := io.LimitReader(resp.Body, 10*1024*1024)
|
||||||
|
|
Loading…
Reference in New Issue