diff options
| author | 2024-04-02 12:12:26 +0100 | |
|---|---|---|
| committer | 2024-04-02 13:12:26 +0200 | |
| commit | d61d5c8a6ad045fe7779fe8d0efe2fd06f691fba (patch) | |
| tree | 12b1f1ed8e2cee3875c74347e0f034bbb8f57134 /internal/gtscontext/context.go | |
| parent | [chore] Try to parse public key as both Actor + bare key (#2710) (diff) | |
| download | gotosocial-d61d5c8a6ad045fe7779fe8d0efe2fd06f691fba.tar.xz | |
[bugfix] httpclient not signing subsequent redirect requests (#2798)
* move http request signing to transport
* actually hook up the http roundtripper ...
* add code comments for the new gtscontext functions
Diffstat (limited to 'internal/gtscontext/context.go')
| -rw-r--r-- | internal/gtscontext/context.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/internal/gtscontext/context.go b/internal/gtscontext/context.go index 73b82744a..80ccb6330 100644 --- a/internal/gtscontext/context.go +++ b/internal/gtscontext/context.go @@ -19,6 +19,7 @@ package gtscontext import ( "context" + "net/http" "net/url" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" @@ -42,6 +43,7 @@ const ( httpSigKey httpSigPubKeyIDKey dryRunKey + httpClientSignFnKey ) // DryRun returns whether the "dryrun" context key has been set. This can be @@ -127,6 +129,19 @@ func SetOtherIRIs(ctx context.Context, iris []*url.URL) context.Context { return context.WithValue(ctx, otherIRIsKey, iris) } +// HTTPClientSignFunc returns an httpclient signing function for the current client +// request context. This can be used to resign a request as calling transport's user. +func HTTPClientSignFunc(ctx context.Context) func(*http.Request) error { + fn, _ := ctx.Value(httpClientSignFnKey).(func(*http.Request) error) + return fn +} + +// SetHTTPClientSignFunc stores the given httpclient signing function and returns the wrapped +// context. See HTTPClientSignFunc() for further information on the signing function value. +func SetHTTPClientSignFunc(ctx context.Context, fn func(*http.Request) error) context.Context { + return context.WithValue(ctx, httpClientSignFnKey, fn) +} + // HTTPSignatureVerifier returns an http signature verifier for the current ActivityPub // request chain. This verifier can be called to authenticate the current request. func HTTPSignatureVerifier(ctx context.Context) httpsig.VerifierWithOptions { |
