From 7313ab7d138dd8f52304f8bbfd90a4d536b91c6b Mon Sep 17 00:00:00 2001 From: Catherine Date: Fri, 5 Dec 2025 18:56:20 +0000 Subject: [PATCH] Fix several content type negotiation issues. * No `Accept:` header should be the same as `Accept: */*`. * For unresolved reference error, `text/plain` should take priority. --- src/http.go | 5 ++++- src/pages.go | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/http.go b/src/http.go index b3d833d..2effa15 100644 --- a/src/http.go +++ b/src/http.go @@ -55,6 +55,9 @@ type HTTPContentTypes struct { } func ParseAcceptHeader(headerValue string) (result HTTPContentTypes) { + if headerValue == "" { + headerValue = "*/*" + } result = HTTPContentTypes{parseGenericAcceptHeader(headerValue)} return } @@ -65,7 +68,7 @@ func (e *HTTPContentTypes) Negotiate(offers ...string) string { prefs[code] = 0 } for _, ctyp := range e.contentTypes { - if ctyp.code == "*" || ctyp.code == "*/*" { + if ctyp.code == "*/*" { for code := range prefs { prefs[code] = ctyp.qval } diff --git a/src/pages.go b/src/pages.go index 875e335..f24f188 100644 --- a/src/pages.go +++ b/src/pages.go @@ -575,7 +575,7 @@ func patchPage(w http.ResponseWriter, r *http.Request) error { func reportUpdateResult(w http.ResponseWriter, r *http.Request, result UpdateResult) error { var unresolvedRefErr UnresolvedRefError if result.outcome == UpdateError && errors.As(result.err, &unresolvedRefErr) { - offeredContentTypes := []string{"application/vnd.git-pages.unresolved", "text/plain"} + offeredContentTypes := []string{"text/plain", "application/vnd.git-pages.unresolved"} acceptedContentTypes := ParseAcceptHeader(r.Header.Get("Accept")) switch acceptedContentTypes.Negotiate(offeredContentTypes...) { default: