Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add text/plain fallback response #85

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Phillip9587
Copy link
Contributor

Based on the work in #56.

Adds a fallback text/plain response when the client does not accept html.

Co-authored-by: Douglas Wilson <doug@somethingdoug.com>
Copy link

socket-security bot commented Mar 5, 2025

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/negotiator@1.0.0 None 0 28.7 kB wesleytodd

View full report↗︎

Copy link
Member

@wesleytodd wesleytodd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good feature! I just pushed a release though, so we probably want to wait just a little before pushing another. Doesn't mean we shouldn't merge it, but I hate to leave work un-included in express for too long if we dont have to.

@Phillip9587
Copy link
Contributor Author

@wesleytodd We maybe should use negotiator not accepts because negotiator is more lightweight compared to accepts and we don't need the mime types support from accepts.

@wesleytodd
Copy link
Member

Yeah, probably true. Frankly I dislike all the content type negotiation packages we have, they could use some consolidation and cleanup to make it more clear when to use which.

@Phillip9587
Copy link
Contributor Author

I don’t think we can include this in a 2.x release since it introduces a breaking change. Currently, finalhandler always returns a text/html response, and even though changing this might be more correct, it could still potentially break existing users relying on the current behavior.

@Phillip9587 Phillip9587 added the v3 label Mar 5, 2025
Comment on lines +148 to +160
var negotiator = new Negotiator(req)
var type = negotiator.mediaType(['text/html'])

// construct body
switch (type) {
case 'text/html':
body = createHtmlBody(msg)
break
default:
// default to plain text
body = createTextBody(msg)
break
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this as a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants