Fix ID construction from requests

This commit is contained in:
Cory Slep 2019-04-13 00:00:35 +02:00
parent d20d97a526
commit 06954abe84
3 changed files with 15 additions and 4 deletions

View file

@ -217,7 +217,8 @@ func (b *baseActor) PostInbox(c context.Context, w http.ResponseWriter, r *http.
// Post the activity to the actor's inbox and trigger side effects for
// that particular Activity type. It is up to the delegate to resolve
// the given map.
err = b.delegate.PostInbox(c, r.URL, activity)
inboxId := requestId(r)
err = b.delegate.PostInbox(c, inboxId, activity)
if err != nil {
// Special case: We know it is a bad request if the object or
// target properties needed to be populated, but weren't.
@ -231,7 +232,7 @@ func (b *baseActor) PostInbox(c context.Context, w http.ResponseWriter, r *http.
}
// Our side effects are complete, now delegate determining whether to
// do inbox forwarding, as well as the action to do it.
if err := b.delegate.InboxForwarding(c, r.URL, activity); err != nil {
if err := b.delegate.InboxForwarding(c, inboxId, activity); err != nil {
return true, err
}
// Request has been processed. Begin responding to the request.
@ -332,7 +333,8 @@ func (b *baseActor) PostOutbox(c context.Context, w http.ResponseWriter, r *http
}
// The HTTP request steps are complete, complete the rest of the outbox
// and delivery process.
activity, err := b.deliver(c, r.URL, asValue, m)
outboxId := requestId(r)
activity, err := b.deliver(c, outboxId, asValue, m)
// Special case: We know it is a bad request if the object or
// target properties needed to be populated, but weren't.
//

View file

@ -58,7 +58,7 @@ func NewActivityStreamsHandler(authFn AuthenticateFunc, db Database, clock Clock
} else if shouldReturn {
return
}
id := r.URL
id := requestId(r)
// Lock and obtain a copy of the requested ActivityStreams value
err = db.Lock(c, id)
if err != nil {

View file

@ -1033,3 +1033,12 @@ func clearSensitiveFields(obj vocab.Type) {
}
}
}
// requestId forms an ActivityPub id based on the HTTP request. Always assumes
// that the id is HTTPS.
func requestId(r *http.Request) *url.URL {
id := r.URL
id.Host = r.Host
id.Scheme = "https"
return id
}