-
-
Notifications
You must be signed in to change notification settings - Fork 735
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 compatibility with node-http-proxy header altering #1484
Changes from 1 commit
0d540d1
acc9399
0c0838a
d6e5184
18b153b
072eb99
0242f69
9d9405c
89c3751
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ const restify = require('restify-clients') | |
const hyperquest = require('hyperquest') | ||
const got = require('got') | ||
const nock = require('..') | ||
const httpProxy = require('http-proxy') | ||
|
||
require('./cleanup_after_each')() | ||
|
||
|
@@ -1711,3 +1712,43 @@ test('teardown', t => { | |
t.deepEqual(leaks, [], 'No leaks') | ||
t.end() | ||
}) | ||
|
||
test('works when headers removed by http-proxy', t => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're in the process of changing the way we test nock–client integration issues. These issues are important, though it's unwieldy to include large-bracket tests in this repo because it doesn't tell nock developers what the problem is. In addition, the internals of client libraries can change. While this is a decent regression test for the integration, it doesn't prevent against regression of the specific behaviors we want to ensure. The idea is to build nock–client integration tests in separate repositories, which test the latest development version of nock against. We'd really welcome help getting that started! See a discussion in #1427 which goes into more detail about it. What we need here is a unit test, probably using the In general we want to do the standard thing, not implement workarounds for libraries, so writing the test using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough - I think I can probably pull out what http-proxy is doing into the test itself and remove the dependency :). |
||
const serviceScope = nock('http://service', { | ||
badheaders: ['authorization'], | ||
}) | ||
.get('/endpoint') | ||
.reply(200) | ||
|
||
const proxy = httpProxy.createProxyServer({ | ||
prependUrl: false, | ||
}) | ||
|
||
proxy.on('proxyReq', (proxyReq, req, res) => { | ||
proxyReq.removeHeader('authorization') | ||
}) | ||
|
||
const server = http.createServer((request, response) => { | ||
proxy.web(request, response, { target: 'http://service' }) | ||
}) | ||
|
||
server.listen(() => { | ||
const options = { | ||
uri: `http://localhost:${server.address().port}/endpoint`, | ||
method: 'GET', | ||
headers: { | ||
authorization: 'blah', | ||
}, | ||
} | ||
|
||
mikealRequest(options, (err, resp, body) => { | ||
if (err) { | ||
t.error(err) | ||
} else { | ||
t.equal(200, resp.statusCode) | ||
serviceScope.done() | ||
server.close(t.end) | ||
} | ||
}) | ||
}) | ||
}) |
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.
Can this be replaced with
options.headers = req.getHeaders()
? Thereq.getHeaders
truthiness check is unnecessary in the Node versions we support. That would also fix the coverage issue you mentioned.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.
Yep sounds simpler - the only problem is that is causes some of the other tests that are expecting
headers: undefined
to fail because they now getheaders: {}
, but that's easy enough to change in the test if you're happy with it :).