Repository navigation
Conversation
There was a problem hiding this comment.
馃煛 Changes recommended
The constructor typings reject previously accepted array-valued headers.
0 open findings
What changed in this PR
Fixes Response construction to honour integer status values while retaining the default 200 for other values.
Changes:
- Handles explicit status values and adds regression tests.
- Expands constructor typings.
- Updates constructor documentation and removes the incorrect
methodparameter.
| File | Description |
|---|---|
| test/鈥媔ntegration/鈥媟esponse_test.js | Tests explicit status and function-valued status fallback. |
| lib/鈥媟esponse.js | Accepts integer status values and updates JSDoc. |
| index.d.ts | Declares constructor options explicitly. |
| docs/鈥媋pi/鈥媟esponse.md | Updates generated constructor documentation. |
馃 Review effort: Balanced
馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
0020aac to
a242162
Compare
|
While this fixes the immediate visible issue, there is one indirect consequence of this: "OAuth2 Standard not affected" is a little too broad. If someone passes status 404, a successful token response will now keep that status, even though OAuth2 expects 200. The usual behavior stays the same when no status is passed. Consider the following test case in it('returns status 200 for a successful token response even if the initial status is 404', async function () {
const response = new Response({ status: 404 });
const request = createRequest({
body: {
grant_type: 'client_credentials',
scope: enabledScope,
},
headers: {
authorization: 'Basic ' + Buffer.from(clientDoc.id + ':' + clientDoc.secret).toString('base64'),
'content-type': 'application/x-www-form-urlencoded',
},
method: 'POST',
});
const token = await oAuth2Server.token(request, response);
response.body.access_token.should.equal(token.accessToken);
response.body.token_type.should.equal('Bearer');
db.accessTokens.has(token.accessToken).should.equal(true);
// RFC 6749 section 5.1 specifies status 200 for a successful token response.
response.status.should.equal(200);
});In its current state it will fail because |
status option in Response constructor|
Thanks; that's a good point and something I had thought about. Initially I was thinking Request would be a fully abstract implementation of a HTTP response, but really it's an internal representation and there's no reason for a consumer to be constructing it with a |
2d019cf to
5cd587f
Compare
The Response constructor never accepted a `method` option; the param was copied from the Request constructor docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Response constructor always starts the `status` at 200 and does not take a `status` option. The handlers own the status they send (200 for a token, the error's code on failure, 302 for a redirect), so a status passed in by the caller would at best be overwritten and at worst leak into a successful response. Say so in the constructor JSDoc, and note that `otherOptions` never overwrite properties the response already has, such as `status` or its methods. Also fix the `otherOptions` description, which referred to the request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Check that the Response constructor ignores a `status` option, and that a successful token response is 200 (RFC 6749 section 5.1) even when the caller creates the Response with another status. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5cd587f to
c89d87f
Compare
Summary
new Response({ status: 404 })produces a response whosestatusis200. This PR originally changed the constructor to honourstatus, but review showed why it shouldn't.Responseisn't a general model of an HTTP response. It is the library's output: the handlers fill it in and the adapter copies it onto the real HTTP response. The handlers set the status themselves:200for a token;codeon failure;302throughredirect().So a status passed in by the caller has no legitimate use. @jankapunkt showed it would leak into a successful token response, against RFC 6749 搂5.1.
The status has started at
200since 2015, and that doesn't change here. This PR now documents that behaviour and pins it with tests, and makes no change to how the library behaves:Responseconstructor says thestatusalways starts as200and is set by the handlers, so it can't be passed in. TheotherOptionsdescription now says it never overwrites properties the response already has, such asstatusor its methods; it also said "request" where it meant "response". A separate commit removes amethodparam, which the constructor never accepted.docs/api/response.mdis regenerated.status: 404is ignored. @jankapunkt's compliance test checks that a successful token response is200even when theResponsewas created withstatus: 404.index.d.tsis unchanged.Linked issue(s)
None. Found while reviewing other open PRs.
Involved parts of the project
lib/response.js: constructor JSDoc onlydocs/api/response.md: regenerated from JSDoctest/integration/response_test.js,test/compliance/client-credential-workflow_test.jsAdded tests?
Yes, as above. Both pass on
masterand fail if the constructor honoursstatus. I checked that against the earlier version of this PR.biome check .is clean and the full mocha suite passes (466).OAuth2 standard
No change in behaviour. The new compliance test pins RFC 6749 搂5.1's
200 (OK)for a successful token response.Reproduction
馃 Generated with Claude Code