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
Http proxy support #366
Merged
Merged
Http proxy support #366
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6d6dd4f
adding tests for the http/https_proxy env
bomsy 12ecbd6
add documentation for proxy support
bomsy 4773abc
support process.env.HTTP(HTTPS)_PROXY, process.env.http(https)_proxy
bomsy e14a6f8
tear down process.env.http_proxy, refactor proxy code
bomsy 74159cd
adding tests for the http/https_proxy env
bomsy 530b67e
add documentation for proxy support
bomsy feec1fc
support process.env.HTTP(HTTPS)_PROXY, process.env.http(https)_proxy
bomsy d2d8e8a
tear down process.env.http_proxy, refactor proxy code
bomsy e71c6c3
remove commented out code
bomsy 65cf8c5
use the hostname instead of host
bomsy 8adaa7f
use the parsed proxy hostname
bomsy 338a08f
fix semicolon
bomsy File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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 |
---|---|---|
|
@@ -3,12 +3,21 @@ var http = require('http'); | |
var url = require('url'); | ||
var zlib = require('zlib'); | ||
var fs = require('fs'); | ||
var server; | ||
var server, proxy; | ||
|
||
module.exports = { | ||
tearDown: function (callback) { | ||
server.close(); | ||
server = null; | ||
if (proxy) { | ||
proxy.close() | ||
proxy = null; | ||
} | ||
|
||
if (process.env.http_proxy) { | ||
process.env.http_proxy = null; | ||
} | ||
|
||
callback(); | ||
}, | ||
|
||
|
@@ -237,5 +246,79 @@ module.exports = { | |
}); | ||
}); | ||
}); | ||
}, | ||
|
||
testProxy: function(test) { | ||
server = http.createServer(function(req, res) { | ||
res.setHeader('Content-Type', 'text/html; charset=UTF-8'); | ||
res.end('12345'); | ||
}).listen(4444, function() { | ||
proxy = http.createServer(function(request, response) { | ||
var parsed = url.parse(request.url); | ||
var opts = { | ||
host: parsed.hostname, | ||
port: parsed.port, | ||
path: parsed.path | ||
}; | ||
|
||
http.get(opts, function(res) { | ||
var body = ''; | ||
res.on('data', function(data) { | ||
body += data; | ||
}); | ||
res.on('end', function() { | ||
response.setHeader('Content-Type', 'text/html; charset=UTF-8'); | ||
response.end(body + '6789'); | ||
}); | ||
}); | ||
|
||
}).listen(4000, function() { | ||
axios.get('http://localhost:4444/', { | ||
proxy: { | ||
host: 'localhost', | ||
port: 4000 | ||
} | ||
}).then(function(res) { | ||
test.equal(res.data, '123456789', 'should pass through proxy'); | ||
test.done(); | ||
}); | ||
}); | ||
}); | ||
}, | ||
|
||
testHTTPProxyEnv: function(test) { | ||
server = http.createServer(function(req, res) { | ||
res.setHeader('Content-Type', 'text/html; charset=UTF-8'); | ||
res.end('4567'); | ||
}).listen(4444, function() { | ||
proxy = http.createServer(function(request, response) { | ||
var parsed = url.parse(request.url); | ||
var opts = { | ||
host: parsed.hostname, | ||
port: parsed.port, | ||
path: parsed.path | ||
}; | ||
|
||
http.get(opts, function(res) { | ||
var body = ''; | ||
res.on('data', function(data) { | ||
body += data; | ||
}); | ||
res.on('end', function() { | ||
response.setHeader('Content-Type', 'text/html; charset=UTF-8'); | ||
response.end(body + '1234'); | ||
}); | ||
}); | ||
|
||
}).listen(4000, function() { | ||
// set the env variable | ||
process.env.http_proxy = 'http://localhost:4000/'; | ||
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. Can setting |
||
|
||
axios.get('http://localhost:4444/').then(function(res) { | ||
test.equal(res.data, '45671234', 'should use proxy set by process.env.http_proxy'); | ||
test.done(); | ||
}); | ||
}); | ||
}); | ||
} | ||
}; |
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.
can we add change this line to
var proxyUrl = process.env[proxyEnv] || process.env[proxyEnv.toUpperCase()] || process.env.all_proxy || process.env.ALL_PROXY]
so that we can support all_proxy environment variables