-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: add writeEarlyHints function to ServerResponse
Co-Authored-By: Matteo Collina <[email protected]> Co-Authored-By: Livia Medeiros <[email protected]> PR-URL: #44180 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Paolo Insogna <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]>
- Loading branch information
1 parent
3abb607
commit 4c869c8
Showing
11 changed files
with
576 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
33 changes: 33 additions & 0 deletions
33
test/parallel/test-http-early-hints-invalid-argument-type.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('node:assert'); | ||
const http = require('node:http'); | ||
const debug = require('node:util').debuglog('test'); | ||
|
||
const testResBody = 'response content\n'; | ||
|
||
const server = http.createServer(common.mustCall((req, res) => { | ||
debug('Server sending early hints...'); | ||
res.writeEarlyHints({ links: 'bad argument object' }); | ||
|
||
debug('Server sending full response...'); | ||
res.end(testResBody); | ||
})); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const req = http.request({ | ||
port: server.address().port, path: '/' | ||
}); | ||
|
||
req.end(); | ||
debug('Client sending request...'); | ||
|
||
req.on('information', common.mustNotCall()); | ||
|
||
process.on('uncaughtException', (err) => { | ||
debug(`Caught an exception: ${JSON.stringify(err)}`); | ||
if (err.name === 'AssertionError') throw err; | ||
assert.strictEqual(err.code, 'ERR_INVALID_ARG_VALUE'); | ||
process.exit(0); | ||
}); | ||
})); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('node:assert'); | ||
const http = require('node:http'); | ||
const debug = require('node:util').debuglog('test'); | ||
|
||
const testResBody = 'response content\n'; | ||
|
||
const server = http.createServer(common.mustCall((req, res) => { | ||
debug('Server sending early hints...'); | ||
res.writeEarlyHints('bad argument value'); | ||
|
||
debug('Server sending full response...'); | ||
res.end(testResBody); | ||
})); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const req = http.request({ | ||
port: server.address().port, path: '/' | ||
}); | ||
|
||
req.end(); | ||
debug('Client sending request...'); | ||
|
||
req.on('information', common.mustNotCall()); | ||
|
||
process.on('uncaughtException', (err) => { | ||
debug(`Caught an exception: ${JSON.stringify(err)}`); | ||
if (err.name === 'AssertionError') throw err; | ||
assert.strictEqual(err.code, 'ERR_INVALID_ARG_VALUE'); | ||
process.exit(0); | ||
}); | ||
})); |
Oops, something went wrong.