[2.x] Implement content negotiation for forum error handling#4677
Open
dsevillamartin wants to merge 5 commits into
Open
[2.x] Implement content negotiation for forum error handling#4677dsevillamartin wants to merge 5 commits into
dsevillamartin wants to merge 5 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3850
Changes proposed in this pull request:
text/htmlinAcceptsheader/loginroute not returning JSON from forumHighMaintenanceModeHandlernot returning JSON for requests initiated by forum (usesisApiRequest, and our requests do not set the header)Reviewers should focus on:
I added the
bitworking/mimeparsepackage (last updated end of 2025) to parse more complexAcceptsheaders (eg. with quality priority). It looks like browsers basically always (wasn't able to find concrete evidence of this) havetext/htmlin their Accepts. While our XHR requests haveAccepts: */*.However, this did make
isHtmlRequesta weaker check that could be true at the same time asisApiRequest(due to the quality priorities). I think properly parsing with this package makes sense, however, perhapsisHtmlRequestshould just be the negation of the strongerisApiRequestcheck (made this change)? Additionally,isHtmlRequestis only used inLogInControllerfor the maintenance login error validaiton.I also thought that adding this check to the forum-wide error handler made more sense than just the login route alone.
Plus, I didn't think just slapping an
Acceptsheader to our JS requests was the proper solution.Screenshot


Necessity
Confirmed
Frontend changes: tested on a local Flarum installation.composer test).