summaryrefslogtreecommitdiff
path: root/vendor/github.com
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com')
-rw-r--r--vendor/github.com/superseriousbusiness/activity/pub/side_effect_actor.go8
-rw-r--r--vendor/github.com/superseriousbusiness/activity/pub/transport.go67
2 files changed, 41 insertions, 34 deletions
diff --git a/vendor/github.com/superseriousbusiness/activity/pub/side_effect_actor.go b/vendor/github.com/superseriousbusiness/activity/pub/side_effect_actor.go
index 4062cf507..0c1da9e91 100644
--- a/vendor/github.com/superseriousbusiness/activity/pub/side_effect_actor.go
+++ b/vendor/github.com/superseriousbusiness/activity/pub/side_effect_actor.go
@@ -2,7 +2,6 @@ package pub
import (
"context"
- "encoding/json"
"fmt"
"net/http"
"net/url"
@@ -477,17 +476,12 @@ func (a *SideEffectActor) deliverToRecipients(c context.Context, boxIRI *url.URL
return err
}
- b, err := json.Marshal(m)
- if err != nil {
- return err
- }
-
tp, err := a.common.NewTransport(c, boxIRI, goFedUserAgent())
if err != nil {
return err
}
- return tp.BatchDeliver(c, b, recipients)
+ return tp.BatchDeliver(c, m, recipients)
}
// addToOutbox adds the activity to the outbox and creates the activity in the
diff --git a/vendor/github.com/superseriousbusiness/activity/pub/transport.go b/vendor/github.com/superseriousbusiness/activity/pub/transport.go
index a770b8b46..101ff5c07 100644
--- a/vendor/github.com/superseriousbusiness/activity/pub/transport.go
+++ b/vendor/github.com/superseriousbusiness/activity/pub/transport.go
@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"crypto"
+ "encoding/json"
"fmt"
"net/http"
"net/url"
@@ -44,10 +45,10 @@ type Transport interface {
Dereference(c context.Context, iri *url.URL) (*http.Response, error)
// Deliver sends an ActivityStreams object.
- Deliver(c context.Context, b []byte, to *url.URL) error
+ Deliver(c context.Context, obj map[string]interface{}, to *url.URL) error
// BatchDeliver sends an ActivityStreams object to multiple recipients.
- BatchDeliver(c context.Context, b []byte, recipients []*url.URL) error
+ BatchDeliver(c context.Context, obj map[string]interface{}, recipients []*url.URL) error
}
// Transport must be implemented by HttpSigTransport.
@@ -138,43 +139,27 @@ func (h HttpSigTransport) Dereference(c context.Context, iri *url.URL) (*http.Re
}
// Deliver sends a POST request with an HTTP Signature.
-func (h HttpSigTransport) Deliver(c context.Context, b []byte, to *url.URL) error {
- req, err := http.NewRequest("POST", to.String(), bytes.NewReader(b))
- if err != nil {
- return err
- }
- req = req.WithContext(c)
- req.Header.Add(contentTypeHeader, contentTypeHeaderValue)
- req.Header.Add("Accept-Charset", "utf-8")
- req.Header.Add("Date", h.clock.Now().UTC().Format("Mon, 02 Jan 2006 15:04:05")+" GMT")
- req.Header.Add("User-Agent", fmt.Sprintf("%s %s", h.appAgent, h.gofedAgent))
- req.Header.Set("Host", to.Host)
- h.postSignerMu.Lock()
- err = h.postSigner.SignRequest(h.privKey, h.pubKeyId, req, b)
- h.postSignerMu.Unlock()
+func (h HttpSigTransport) Deliver(c context.Context, data map[string]interface{}, to *url.URL) error {
+ b, err := json.Marshal(data)
if err != nil {
return err
}
- resp, err := h.client.Do(req)
- if err != nil {
- return err
- }
- defer resp.Body.Close()
- if !isSuccess(resp.StatusCode) {
- return fmt.Errorf("POST request to %s failed (%d): %s", to.String(), resp.StatusCode, resp.Status)
- }
- return nil
+ return h.deliver(c, b, to)
}
// BatchDeliver sends concurrent POST requests. Returns an error if any of the requests had an error.
-func (h HttpSigTransport) BatchDeliver(c context.Context, b []byte, recipients []*url.URL) error {
+func (h HttpSigTransport) BatchDeliver(c context.Context, data map[string]interface{}, recipients []*url.URL) error {
+ b, err := json.Marshal(data)
+ if err != nil {
+ return err
+ }
var wg sync.WaitGroup
errCh := make(chan error, len(recipients))
for _, recipient := range recipients {
wg.Add(1)
go func(r *url.URL) {
defer wg.Done()
- if err := h.Deliver(c, b, r); err != nil {
+ if err := h.deliver(c, b, r); err != nil {
errCh <- err
}
}(recipient)
@@ -196,6 +181,34 @@ outer:
return nil
}
+func (h HttpSigTransport) deliver(c context.Context, b []byte, to *url.URL) error {
+ req, err := http.NewRequest("POST", to.String(), bytes.NewReader(b))
+ if err != nil {
+ return err
+ }
+ req = req.WithContext(c)
+ req.Header.Add(contentTypeHeader, contentTypeHeaderValue)
+ req.Header.Add("Accept-Charset", "utf-8")
+ req.Header.Add("Date", h.clock.Now().UTC().Format("Mon, 02 Jan 2006 15:04:05")+" GMT")
+ req.Header.Add("User-Agent", fmt.Sprintf("%s %s", h.appAgent, h.gofedAgent))
+ req.Header.Set("Host", to.Host)
+ h.postSignerMu.Lock()
+ err = h.postSigner.SignRequest(h.privKey, h.pubKeyId, req, b)
+ h.postSignerMu.Unlock()
+ if err != nil {
+ return err
+ }
+ resp, err := h.client.Do(req)
+ if err != nil {
+ return err
+ }
+ defer resp.Body.Close()
+ if !isSuccess(resp.StatusCode) {
+ return fmt.Errorf("POST request to %s failed (%d): %s", to.String(), resp.StatusCode, resp.Status)
+ }
+ return nil
+}
+
// HttpClient sends http requests, and is an abstraction only needed by the
// HttpSigTransport. The standard library's Client satisfies this interface.
type HttpClient interface {