Add timeout on ActivityPub requests

This commit is contained in:
Matt Baer 2020-01-23 11:47:35 -05:00
parent b9914dd65a
commit bc9843dfa3
1 changed files with 9 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright © 2018-2019 A Bunch Tell LLC.
* Copyright © 2018-2020 A Bunch Tell LLC.
*
* This file is part of WriteFreely.
*
@ -62,6 +62,12 @@ func (ru *RemoteUser) AsPerson() *activitystreams.Person {
}
}
func activityPubClient() http.Client {
return http.Client{
Timeout: 15 * time.Second,
}
}
func handleFetchCollectionActivities(app *App, w http.ResponseWriter, r *http.Request) error {
w.Header().Set("Server", serverSoftware)
@ -502,7 +508,7 @@ func makeActivityPost(hostName string, p *activitystreams.Person, url string, m
}
}
resp, err := http.DefaultClient.Do(r)
resp, err := activityPubClient().Do(r)
if err != nil {
return err
}
@ -538,7 +544,7 @@ func resolveIRI(hostName, url string) ([]byte, error) {
}
}
resp, err := http.DefaultClient.Do(r)
resp, err := activityPubClient().Do(r)
if err != nil {
return nil, err
}