Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/mikeal/request
Browse files Browse the repository at this point in the history
Conflicts:
	README.md
  • Loading branch information
davidlehn committed Apr 13, 2013
2 parents 95a2558 + 93e7c20 commit 89d2602
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ The first argument can be either a url or an options object. The only required o
* `jar` - Set to `false` if you don't want cookies to be remembered for future use or define your custom cookie jar (see examples section)
* `aws` - object containing aws signing information, should have the properties `key` and `secret` as well as `bucket` unless you're specifying your bucket as part of the path, or you are making a request that doesn't use a bucket (i.e. GET Services)
* `httpSignature` - Options for the [HTTP Signature Scheme](https://github.com/joyent/node-http-signature/blob/master/http_signing.md) using [Joyent's library](https://github.com/joyent/node-http-signature). The `keyId` and `key` properties must be specified. See the docs for other options.
* `localAddress` - Local interface to bind for network connections.
The callback argument gets 3 arguments. The first is an error when applicable (usually from the http.Client option not the http.ClientRequest object). The second in an http.ClientResponse object. The third is the response body String or Buffer.
Expand Down
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ Request.prototype.init = function (options) {
if (!options) options = {}

self.method = options.method || 'GET'
self.localAddress = options.localAddress

debug(options)
if (!self.pool && self.pool !== false) self.pool = globalPool
Expand Down Expand Up @@ -159,6 +160,10 @@ Request.prototype.init = function (options) {
if (typeof self.uri == "string") self.uri = url.parse(self.uri)
}

if (self.strictSSL === false) {
self.rejectUnauthorized = false
}

if (self.proxy) {
if (typeof self.proxy == 'string') self.proxy = url.parse(self.proxy)

Expand All @@ -172,6 +177,7 @@ Request.prototype.init = function (options) {
, proxyAuth: self.proxy.auth
, headers: { Host: self.uri.hostname + ':' +
(self.uri.port || self.uri.protocol === 'https:' ? 443 : 80) }}
, rejectUnauthorized: self.rejectUnauthorized
, ca: this.ca }

self.agent = tunnelFn(tunnelOptions)
Expand Down Expand Up @@ -360,10 +366,6 @@ Request.prototype.init = function (options) {
}
}

if (self.strictSSL === false) {
self.rejectUnauthorized = false
}

if (self.pool === false) {
self.agent = false
} else {
Expand Down Expand Up @@ -450,6 +452,7 @@ Request.prototype._updateProtocol = function () {
var tunnelOptions = { proxy: { host: self.proxy.hostname
, port: +self.proxy.port
, proxyAuth: self.proxy.auth }
, rejectUnauthorized: self.rejectUnauthorized
, ca: self.ca }
self.agent = tunnelFn(tunnelOptions)
return
Expand Down Expand Up @@ -1002,7 +1005,7 @@ function getHeader(name, headers) {
return result
}
Request.prototype.auth = function (user, pass, sendImmediately) {
if (typeof user !== 'string' || typeof pass !== 'string') {
if (typeof user !== 'string' || (pass !== undefined && typeof pass !== 'string')) {
throw new Error('auth() received invalid user or password')
}
this._user = user
Expand Down
9 changes: 9 additions & 0 deletions tests/test-localAddress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var request = request = require('../index')
, assert = require('assert')
;

request.get({
uri: 'http://www.google.com', localAddress: '127.0.0.1'
}, function(err) {
assert.equal(err.code, 'ENETUNREACH')
})

0 comments on commit 89d2602

Please sign in to comment.