-
Notifications
You must be signed in to change notification settings - Fork 28.9k
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
added before-flushing-head event to _http_server.ServerResponse.writeHead #2538
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2c22a16
added before-flushing-head event to _http_server.ServerResponse.write…
yoavaa 5c774e0
added docs for before-flushing-head
yoavaa a58a58e
added test for before-flush-head event of HTTP response
yoavaa ce6d849
extended the before-flushing-head event to enable customizing the res…
yoavaa 335db4c
renamed before-flushing-head to beforeFlushingHead
yoavaa 76620e4
code style issues
yoavaa df3f243
fixed broken test parallel/test-http-write-head.js
yoavaa 118a0a8
fixed bug in handling the case when _header is not set.
yoavaa 84ce98c
js lint - code formatting, etc.
yoavaa 58bd0b3
js lint - code formatting, etc.
yoavaa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict'; | ||
const common = require('../common'), | ||
assert = require('assert'), | ||
http = require('http'); | ||
|
||
var testResBody = 'other stuff!\n'; | ||
|
||
var server = http.createServer(function(req, res) { | ||
res.on('beforeFlushingHead', function(args) { | ||
args.statusCode = 201; | ||
args.statusMessage = 'changed to show we can'; | ||
args.headers['Flush-Head'] = 'event-was-called'; | ||
}); | ||
res.writeHead(200, { | ||
'Content-Type': 'text/plain' | ||
}); | ||
res.end(testResBody); | ||
}); | ||
server.listen(common.PORT); | ||
|
||
|
||
server.addListener('listening', function() { | ||
var options = { | ||
port: common.PORT, | ||
path: '/', | ||
method: 'GET' | ||
}; | ||
var req = http.request(options, function(res) { | ||
assert.ok(res.statusCode === 201, | ||
'Response status code was not overridden from 200 to 201.'); | ||
assert.ok(res.statusMessage === 'changed to show we can', | ||
'Response status message was not overridden.'); | ||
assert.ok('flush-head' in res.headers, | ||
'Response headers didn\'t contain the flush-head header, ' + | ||
'indicating the beforeFlushingHead event was not called or ' + | ||
'did not allow adding headers.'); | ||
assert.ok(res.headers['flush-head'] === 'event-was-called', | ||
'Response headers didn\'t contain the flush-head header ' + | ||
'with value event-was-called, indicating the ' + | ||
'beforeFlushingHead event was not called or did not allow ' + | ||
'adding headers.'); | ||
res.addListener('end', function() { | ||
server.close(); | ||
process.exit(); | ||
}); | ||
res.resume(); | ||
}); | ||
req.end(); | ||
}); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could possibly get away with using a template string here now...
(could but not required, of course)