aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2022-06-16 11:17:05 -0500
committerAnthony Wang2022-06-16 11:17:05 -0500
commitc118dacde73bd1e8a10e9bc171001e5b4d3a59e2 (patch)
treea601ccd02747b8b681d4731935f956c96d2e0449
parent2a013b8fe449ad5e73a259822b8092c980da1c59 (diff)
Move getting the RFC 2616 time to a separate function
-rw-r--r--modules/activitypub/client.go8
-rw-r--r--routers/api/v1/activitypub/reqsignature.go4
2 files changed, 7 insertions, 5 deletions
diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go
index b04706dd0..8c2854f71 100644
--- a/modules/activitypub/client.go
+++ b/modules/activitypub/client.go
@@ -27,6 +27,11 @@ const (
httpsigExpirationTime = 60
)
+// Gets the current time as an RFC 2616 formatted string
+func CurrentTime() string {
+ return strings.ReplaceAll(time.Now().UTC().Format(time.RFC1123), "UTC", "GMT")
+}
+
func containsRequiredHTTPHeaders(method string, headers []string) error {
var hasRequestTarget, hasDate, hasDigest bool
for _, header := range headers {
@@ -98,8 +103,7 @@ func (c *Client) NewRequest(b []byte, to string) (req *http.Request, err error)
}
req.Header.Add("Content-Type", ActivityStreamsContentType)
req.Header.Add("Accept-Charset", "utf-8")
- req.Header.Add("Date", strings.ReplaceAll(time.Now().UTC().Format(time.RFC1123), "UTC", "GMT"))
-
+ req.Header.Add("Date", CurrentTime())
signer, _, err := httpsig.NewSigner(c.algs, c.digestAlg, c.postHeaders, httpsig.Signature, httpsigExpirationTime)
if err != nil {
return
diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go
index c90ed6d4b..316d66cd8 100644
--- a/routers/api/v1/activitypub/reqsignature.go
+++ b/routers/api/v1/activitypub/reqsignature.go
@@ -12,8 +12,6 @@ import (
"io"
"net/http"
"net/url"
- "strings"
- "time"
"code.gitea.io/gitea/modules/activitypub"
gitea_context "code.gitea.io/gitea/modules/context"
@@ -50,7 +48,7 @@ func fetch(iri *url.URL) (b []byte, err error) {
req := httplib.NewRequest(iri.String(), http.MethodGet)
req.Header("Accept", activitypub.ActivityStreamsContentType)
req.Header("Accept-Charset", "utf-8")
- req.Header("Date", strings.ReplaceAll(time.Now().UTC().Format(time.RFC1123), "UTC", "GMT"))
+ req.Header("Date", activitypub.CurrentTime())
resp, err := req.Response()
if err != nil {
return