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

New feature: Acceptable #791

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

New feature: Acceptable #791

wants to merge 5 commits into from

Conversation

c960657
Copy link
Contributor

@c960657 c960657 commented Oct 4, 2024

Some servers ignore the Accept header. It usually works fine for static files, but not dynamically generated responses.

This PR adds a new feature which compares the response Content-Type header to the request Accept header and generates a synthetic 406 Not Acceptable response if they don't match.

@ixti
Copy link
Member

ixti commented Nov 22, 2024

IMO in this case it's better raise UnacceptableError. Or even make that logic configurable:

HTTP.use(acceptable: { mime_type: "...", on_mismatch: :raise })
  • mime_type - if request does not have Accept header - it will inject one
  • on_mismatch
    • :raise - fails with UnacceptableError
      • UnacceptableError#response - will contain original response
    • :rewrite_status - rewrites response with new status

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