Add func for easy double-knocking of requests

This commit is contained in:
Melody Becker 2025-05-22 17:00:39 +02:00
parent 6cc699cbbd
commit ef58b5ca9b
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI

View file

@ -29,6 +29,25 @@ Links for home:
- https://datatracker.ietf.org/doc/html/rfc9421
*/
// Perform a signed request. Tries RFC9421 first and on fail cavage.
// This double-knocking is because implementations currently use cavage (a precursor to RFC9421).
// However, Cavage is deprecated now and the RFC should be used instead. And so
// implementations have slowly begun to implement the RFC in addition to cavage
//
// Returns the unmodified response, if the request completed with RFC signing and an error, if any
func RequestSigned(
method, target string,
body []byte,
actor *models.User,
) (response *http.Response, wasRfc9421 bool, err error) {
res, err := RequestSignedRFC9421(method, target, body, actor)
if err == nil {
return res, true, nil
}
res, err = RequestSignedCavage(method, target, body, actor)
return res, false, err
}
// Perform a request, signing it as specified in RFC 9421
func RequestSignedRFC9421(
method, target string,