Merge pull request #249 from writeas/fix-activitypub-client

Improve resource use for federation
pull/240/head^2
Matt Baer 5 years ago committed by GitHub
commit ab2b8dff7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      activitypub.go

@ -65,6 +65,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 { func handleFetchCollectionActivities(app *App, w http.ResponseWriter, r *http.Request) error {
w.Header().Set("Server", serverSoftware) w.Header().Set("Server", serverSoftware)
@ -389,6 +395,11 @@ func handleFetchCollectionInbox(app *App, w http.ResponseWriter, r *http.Request
} }
go func() { go func() {
if to == nil {
log.Error("No to! %v", err)
return
}
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
am, err := a.Serialize() am, err := a.Serialize()
if err != nil { if err != nil {
@ -397,10 +408,6 @@ func handleFetchCollectionInbox(app *App, w http.ResponseWriter, r *http.Request
} }
am["@context"] = []string{activitystreams.Namespace} am["@context"] = []string{activitystreams.Namespace}
if to == nil {
log.Error("No to! %v", err)
return
}
err = makeActivityPost(app.cfg.App.Host, p, fullActor.Inbox, am) err = makeActivityPost(app.cfg.App.Host, p, fullActor.Inbox, am)
if err != nil { if err != nil {
log.Error("Unable to make activity POST: %v", err) log.Error("Unable to make activity POST: %v", err)
@ -509,7 +516,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 { if err != nil {
return err return err
} }
@ -545,7 +552,7 @@ func resolveIRI(hostName, url string) ([]byte, error) {
} }
} }
resp, err := http.DefaultClient.Do(r) resp, err := activityPubClient().Do(r)
if err != nil { if err != nil {
return nil, err return nil, err
} }

Loading…
Cancel
Save