fix: return HTML for browser Accept headers on root route (#532)#546
Open
Justxd22 wants to merge 4 commits intocameri:mainfrom
Open
fix: return HTML for browser Accept headers on root route (#532)#546Justxd22 wants to merge 4 commits intocameri:mainfrom
Justxd22 wants to merge 4 commits intocameri:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes / content negotiation so NIP-11 relay information is only served when the client explicitly requests application/nostr+json, preventing typical browser Accept headers from receiving JSON.
Changes:
- Replaced
accepts-based negotiation with an explicitAccept: application/nostr+json(andq>0) check shared between router middleware androotRequestHandler. - Added unit tests for the explicit Accept header detection (including browser-style headers and
q=0). - Added an integration scenario ensuring browser-style Accept headers receive HTML on
/.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/unit/handlers/request-handlers/root-request-handler.spec.ts | Adds unit coverage for explicit NIP-11 Accept detection and related root handler behavior. |
| test/integration/features/nip-11/nip-11.feature.ts | Adds a Cucumber step that simulates a browser-like root request. |
| test/integration/features/nip-11/nip-11.feature | Adds an integration scenario asserting HTML is served for browser-style Accept headers. |
| src/routes/index.ts | Switches router middleware to use the explicit Accept-header check instead of accepts. |
| src/handlers/request-handlers/root-request-handler.ts | Introduces hasExplicitNostrJsonAcceptHeader and uses it for root handler content negotiation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Collaborator
Author
|
Ci should pass once #539 is merged |
Owner
|
Did you test the fix manually? Also does it work when the relay URL is in a path other than /? |
Collaborator
Author
|
@cameri confirmed it breaks under subpath! so We need to edit the html templates remove hardcoded root url and inject |
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.
Description
/content negotiation to serve NIP-11 only for explicitapplication/nostr+jsonrequestsAcceptheaders (e.g.text/html,...,*/*) from being treated as NIP-11 requestsrootRequestHandlerq=0Related Issue
#532
How Has This Been Tested?
npm run build:checknpm run test:unitTypes of changes
Checklist: