Merge pull request #766 from writefreely/fix-ld-json-response
Correctly respond to application/ld+json requests
This commit is contained in:
commit
94bb566e4f
|
@ -496,8 +496,7 @@ func apiCheckCollectionPermissions(app *App, r *http.Request, c *Collection) (in
|
||||||
|
|
||||||
// fetchCollection handles the API endpoint for retrieving collection data.
|
// fetchCollection handles the API endpoint for retrieving collection data.
|
||||||
func fetchCollection(app *App, w http.ResponseWriter, r *http.Request) error {
|
func fetchCollection(app *App, w http.ResponseWriter, r *http.Request) error {
|
||||||
accept := r.Header.Get("Accept")
|
if IsActivityPubRequest(r) {
|
||||||
if strings.Contains(accept, "application/activity+json") {
|
|
||||||
return handleFetchCollectionActivities(app, w, r)
|
return handleFetchCollectionActivities(app, w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
posts.go
3
posts.go
|
@ -1119,8 +1119,7 @@ func fetchPost(app *App, w http.ResponseWriter, r *http.Request) error {
|
||||||
|
|
||||||
p.extractData()
|
p.extractData()
|
||||||
|
|
||||||
accept := r.Header.Get("Accept")
|
if IsActivityPubRequest(r) {
|
||||||
if strings.Contains(accept, "application/activity+json") {
|
|
||||||
if coll == nil {
|
if coll == nil {
|
||||||
// This is a draft post; 404 for now
|
// This is a draft post; 404 for now
|
||||||
// TODO: return ActivityObject
|
// TODO: return ActivityObject
|
||||||
|
|
|
@ -13,6 +13,7 @@ package writefreely
|
||||||
import (
|
import (
|
||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func IsJSON(r *http.Request) bool {
|
func IsJSON(r *http.Request) bool {
|
||||||
|
@ -20,3 +21,9 @@ func IsJSON(r *http.Request) bool {
|
||||||
accept := r.Header.Get("Accept")
|
accept := r.Header.Get("Accept")
|
||||||
return ct == "application/json" || accept == "application/json"
|
return ct == "application/json" || accept == "application/json"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsActivityPubRequest(r *http.Request) bool {
|
||||||
|
accept := r.Header.Get("Accept")
|
||||||
|
return strings.Contains(accept, "application/activity+json") ||
|
||||||
|
accept == "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue