-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid overriding headers set in onresponse
Currently, overriding a header from the target response in the source response requires doing it in both ondata_response (when receiving the first chunk of data) and in onend_response (for when the response doesn't contain any data), after verifying that res.headersSent is false. That's clumsy at best. By filtering the copied headers with those already present in the source response, it's possible to set them in onresponse once and for all.
- Loading branch information
Showing
3 changed files
with
35 additions
and
1 deletion.
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,17 @@ | ||
'use strict'; | ||
|
||
const TestResponseHeaderPlugin = function () { | ||
}; | ||
|
||
module.exports = function () { | ||
return new TestResponseHeaderPlugin(); | ||
}; | ||
|
||
TestResponseHeaderPlugin.prototype.init = function myPlugin1() { | ||
return { | ||
onresponse: function (sourceReq, sourceRes, targetRes, data, next) { | ||
sourceRes.setHeader('content-type', 'application/octet-stream'); | ||
next(); | ||
} | ||
}; | ||
}; |