From 2275a288b961e1257cfbc4c074a5b455b4e33f16 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Tue, 26 Sep 2023 14:46:35 -0400 Subject: [PATCH] Correctly respond to application/ld+json requests, part 2 This finishes the work started in #766, ensuring that requests to canonical URLs of blogs and posts (not just at their API endpoints) respond correctly to `application/ld+json;...` requests. Fully addresses issue #564 --- collections.go | 2 +- handle.go | 2 +- posts.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/collections.go b/collections.go index e3674fa..75e0421 100644 --- a/collections.go +++ b/collections.go @@ -853,7 +853,7 @@ func handleViewCollection(app *App, w http.ResponseWriter, r *http.Request) erro } // Serve ActivityStreams data now, if requested - if strings.Contains(r.Header.Get("Accept"), "application/activity+json") { + if IsActivityPubRequest(r) { ac := c.PersonObject() ac.Context = []interface{}{activitystreams.Namespace} setCacheControl(w, apCacheTime) diff --git a/handle.go b/handle.go index 7537b61..1756be3 100644 --- a/handle.go +++ b/handle.go @@ -818,7 +818,7 @@ func (h *Handler) handleHTTPError(w http.ResponseWriter, r *http.Request, err er return } else if err.Status == http.StatusNotFound { w.WriteHeader(err.Status) - if strings.Contains(r.Header.Get("Accept"), "application/activity+json") { + if IsActivityPubRequest(r) { // This is a fediverse request; simply return the header return } diff --git a/posts.go b/posts.go index c9ac6ec..2fb23cc 100644 --- a/posts.go +++ b/posts.go @@ -1520,7 +1520,7 @@ Are you sure it was ever here?`, fmt.Fprintf(w, "# %s\n\n", p.Title.String) } fmt.Fprint(w, p.Content) - } else if strings.Contains(r.Header.Get("Accept"), "application/activity+json") { + } else if IsActivityPubRequest(r) { if !postFound { return ErrCollectionPageNotFound }