forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
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 <matteo.collina@gmail.com> Co-Authored-By: Livia Medeiros <livia@cirno.name> PR-URL: nodejs#44180 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name>
- Loading branch information
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.