Skip to content

Commit 08eebff

Browse files
author
Anthony Wang
committed
Make sure HTTP request Date in GMT
1 parent d749f8f commit 08eebff

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

modules/activitypub/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"encoding/pem"
1212
"fmt"
1313
"net/http"
14+
"strings"
1415
"time"
1516

1617
user_model "code.gitea.io/gitea/models/user"
@@ -106,7 +107,7 @@ func (c *Client) NewRequest(b []byte, to string) (req *http.Request, err error)
106107
}
107108
req.Header.Add("Content-Type", ActivityStreamsContentType)
108109
req.Header.Add("Accept-Charset", "utf-8")
109-
req.Header.Add("Date", fmt.Sprintf("%s UTC", time.Now().UTC().Format(time.RFC1123)))
110+
req.Header.Add("Date", strings.ReplaceAll(time.Now().UTC().Format(time.RFC1123), "UTC", "GMT"))
110111

111112
signer, _, err := httpsig.NewSigner(c.algs, c.digestAlg, c.postHeaders, httpsig.Signature, httpsigExpirationTime)
112113
if err != nil {

routers/api/v1/activitypub/person.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ func Person(ctx *context.APIContext) {
5656
ctx.Error(http.StatusInternalServerError, "Set PreferredUsername", err)
5757
return
5858
}
59-
59+
6060
person.URL = ap.IRI(setting.AppURL + username)
6161

6262
person.Icon = ap.Image{
63-
Type: ap.ImageType,
63+
Type: ap.ImageType,
6464
MediaType: "image/png",
65-
URL: ap.IRI(user.AvatarLink()),
65+
URL: ap.IRI(user.AvatarLink()),
6666
}
6767

6868
person.Inbox = nil
@@ -91,12 +91,12 @@ func Person(ctx *context.APIContext) {
9191
ctx.Error(http.StatusInternalServerError, "Unmarshall", err)
9292
}
9393

94-
jsonmap["@context"] = []string{"https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"}
94+
jsonmap["@context"] = []string{"https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"}
9595

9696
ctx.Resp.Header().Add("Content-Type", "application/activity+json")
9797
ctx.Resp.WriteHeader(http.StatusOK)
9898
binary, _ = json.Marshal(jsonmap)
99-
ctx.Resp.Write(binary)
99+
_, _ = ctx.Resp.Write(binary)
100100
}
101101

102102
// PersonInbox function

routers/api/v1/activitypub/reqsignature.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"io"
1414
"net/http"
1515
"net/url"
16+
"strings"
1617
"time"
1718

1819
"code.gitea.io/gitea/modules/activitypub"
@@ -50,7 +51,7 @@ func fetch(iri *url.URL) (b []byte, err error) {
5051
req := httplib.NewRequest(iri.String(), http.MethodGet)
5152
req.Header("Accept", activitypub.ActivityStreamsContentType)
5253
req.Header("Accept-Charset", "utf-8")
53-
req.Header("Date", fmt.Sprintf("%s UTC", time.Now().UTC().Format(time.RFC1123)))
54+
req.Header("Date", strings.ReplaceAll(time.Now().UTC().Format(time.RFC1123), "UTC", "GMT"))
5455
resp, err := req.Response()
5556
if err != nil {
5657
return

0 commit comments

Comments
 (0)