Permit hooks to return the modified context

This commit is contained in:
Cory Slep 2019-06-17 21:11:51 +02:00
parent c365730b4e
commit f655c76e91
8 changed files with 26 additions and 20 deletions

View file

@ -208,7 +208,8 @@ func (b *baseActor) PostInbox(c context.Context, w http.ResponseWriter, r *http.
return true, nil
}
// Allow server implementations to set context data with a hook.
if err = b.delegate.PostInboxRequestBodyHook(c, r, activity); err != nil {
c, err = b.delegate.PostInboxRequestBodyHook(c, r, activity)
if err != nil {
return true, err
}
// Check authorization of the activity.
@ -336,7 +337,8 @@ func (b *baseActor) PostOutbox(c context.Context, w http.ResponseWriter, r *http
return true, nil
}
// Allow server implementations to set context data with a hook.
if err = b.delegate.PostOutboxRequestBodyHook(c, r, asValue); err != nil {
c, err = b.delegate.PostOutboxRequestBodyHook(c, r, asValue)
if err != nil {
return true, err
}
// The HTTP request steps are complete, complete the rest of the outbox

View file

@ -39,7 +39,7 @@ type DelegateActor interface {
// PostInbox. In this case, the DelegateActor implementation must not
// write a response to the ResponseWriter as is expected that the caller
// to PostInbox will do so when handling the error.
PostInboxRequestBodyHook(c context.Context, r *http.Request, activity Activity) error
PostInboxRequestBodyHook(c context.Context, r *http.Request, activity Activity) (context.Context, error)
// Hook callback after parsing the request body for a client request
// to the Actor's outbox.
//
@ -56,7 +56,7 @@ type DelegateActor interface {
// PostOutbox. In this case, the DelegateActor implementation must not
// write a response to the ResponseWriter as is expected that the caller
// to PostOutbox will do so when handling the error.
PostOutboxRequestBodyHook(c context.Context, r *http.Request, data vocab.Type) error
PostOutboxRequestBodyHook(c context.Context, r *http.Request, data vocab.Type) (context.Context, error)
// AuthenticatePostInbox delegates the authentication of a POST to an
// inbox.
//

View file

@ -32,7 +32,7 @@ type FederatingProtocol interface {
// PostInbox. In this case, the DelegateActor implementation must not
// write a response to the ResponseWriter as is expected that the caller
// to PostInbox will do so when handling the error.
PostInboxRequestBodyHook(c context.Context, r *http.Request, activity Activity) error
PostInboxRequestBodyHook(c context.Context, r *http.Request, activity Activity) (context.Context, error)
// AuthenticatePostInbox delegates the authentication of a POST to an
// inbox.
//

View file

@ -37,11 +37,12 @@ func (m *MockDelegateActor) EXPECT() *MockDelegateActorMockRecorder {
}
// PostInboxRequestBodyHook mocks base method
func (m *MockDelegateActor) PostInboxRequestBodyHook(c context.Context, r *http.Request, activity Activity) error {
func (m *MockDelegateActor) PostInboxRequestBodyHook(c context.Context, r *http.Request, activity Activity) (context.Context, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "PostInboxRequestBodyHook", c, r, activity)
ret0, _ := ret[0].(error)
return ret0
ret0, _ := ret[0].(context.Context)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// PostInboxRequestBodyHook indicates an expected call of PostInboxRequestBodyHook
@ -51,11 +52,12 @@ func (mr *MockDelegateActorMockRecorder) PostInboxRequestBodyHook(c, r, activity
}
// PostOutboxRequestBodyHook mocks base method
func (m *MockDelegateActor) PostOutboxRequestBodyHook(c context.Context, r *http.Request, data vocab.Type) error {
func (m *MockDelegateActor) PostOutboxRequestBodyHook(c context.Context, r *http.Request, data vocab.Type) (context.Context, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "PostOutboxRequestBodyHook", c, r, data)
ret0, _ := ret[0].(error)
return ret0
ret0, _ := ret[0].(context.Context)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// PostOutboxRequestBodyHook indicates an expected call of PostOutboxRequestBodyHook

View file

@ -37,11 +37,12 @@ func (m *MockFederatingProtocol) EXPECT() *MockFederatingProtocolMockRecorder {
}
// PostInboxRequestBodyHook mocks base method
func (m *MockFederatingProtocol) PostInboxRequestBodyHook(c context.Context, r *http.Request, activity Activity) error {
func (m *MockFederatingProtocol) PostInboxRequestBodyHook(c context.Context, r *http.Request, activity Activity) (context.Context, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "PostInboxRequestBodyHook", c, r, activity)
ret0, _ := ret[0].(error)
return ret0
ret0, _ := ret[0].(context.Context)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// PostInboxRequestBodyHook indicates an expected call of PostInboxRequestBodyHook

View file

@ -36,11 +36,12 @@ func (m *MockSocialProtocol) EXPECT() *MockSocialProtocolMockRecorder {
}
// PostOutboxRequestBodyHook mocks base method
func (m *MockSocialProtocol) PostOutboxRequestBodyHook(c context.Context, r *http.Request, data vocab.Type) error {
func (m *MockSocialProtocol) PostOutboxRequestBodyHook(c context.Context, r *http.Request, data vocab.Type) (context.Context, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "PostOutboxRequestBodyHook", c, r, data)
ret0, _ := ret[0].(error)
return ret0
ret0, _ := ret[0].(context.Context)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// PostOutboxRequestBodyHook indicates an expected call of PostOutboxRequestBodyHook

View file

@ -29,12 +29,12 @@ type sideEffectActor struct {
}
// PostInboxRequestBodyHook defers to the delegate.
func (a *sideEffectActor) PostInboxRequestBodyHook(c context.Context, r *http.Request, activity Activity) error {
func (a *sideEffectActor) PostInboxRequestBodyHook(c context.Context, r *http.Request, activity Activity) (context.Context, error) {
return a.s2s.PostInboxRequestBodyHook(c, r, activity)
}
// PostOutboxRequestBodyHook defers to the delegate.
func (a *sideEffectActor) PostOutboxRequestBodyHook(c context.Context, r *http.Request, data vocab.Type) error {
func (a *sideEffectActor) PostOutboxRequestBodyHook(c context.Context, r *http.Request, data vocab.Type) (context.Context, error) {
return a.c2s.PostOutboxRequestBodyHook(c, r, data)
}

View file

@ -31,7 +31,7 @@ type SocialProtocol interface {
// PostOutbox. In this case, the DelegateActor implementation must not
// write a response to the ResponseWriter as is expected that the caller
// to PostOutbox will do so when handling the error.
PostOutboxRequestBodyHook(c context.Context, r *http.Request, data vocab.Type) error
PostOutboxRequestBodyHook(c context.Context, r *http.Request, data vocab.Type) (context.Context, error)
// AuthenticatePostOutbox delegates the authentication of a POST to an
// outbox.
//