Skip to content

Middleware: Don't apply HTML transformations to non-HTML responses#101

Merged
fstrr merged 1 commit intomainfrom
kgf-fix-middleware-json
Mar 5, 2026
Merged

Middleware: Don't apply HTML transformations to non-HTML responses#101
fstrr merged 1 commit intomainfrom
kgf-fix-middleware-json

Conversation

@kfranqueiro
Copy link
Copy Markdown
Collaborator

@kfranqueiro kfranqueiro commented Mar 5, 2026

This fixes a regression I noticed this week, caused by #95, affecting the search feature.

When I added middleware, I applied it to all responses. This has the effect of mangling non-HTML responses, because the middleware passes the response body through Cheerio. Cheerio's default behavior is to expect a full document, and to wrap the content in html and body tags if it isn't already.

This PR adds a check to leave the response alone if it is not text/html. It also adds an explicit application/json type to the /api/search endpoint, though this is not critical to the fix (it reported text/plain before).

The bug was plainly visible in dev tools, as it resulted in an error in the log about failing to parse JSON.

@kfranqueiro kfranqueiro requested a review from fstrr March 5, 2026 18:46
@fstrr fstrr merged commit b091b7f into main Mar 5, 2026
1 check passed
@fstrr fstrr deleted the kgf-fix-middleware-json branch March 5, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants