updated to v2
This commit is contained in:
55
node_modules/request/LICENSE
generated
vendored
Normal file
55
node_modules/request/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
Apache License
|
||||
|
||||
Version 2.0, January 2004
|
||||
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
||||
|
||||
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
||||
|
||||
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
||||
|
||||
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
||||
|
||||
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
288
node_modules/request/README.md
generated
vendored
Normal file
288
node_modules/request/README.md
generated
vendored
Normal file
@@ -0,0 +1,288 @@
|
||||
# Request -- Simplified HTTP request method
|
||||
|
||||
## Install
|
||||
|
||||
<pre>
|
||||
npm install request
|
||||
</pre>
|
||||
|
||||
Or from source:
|
||||
|
||||
<pre>
|
||||
git clone git://github.com/mikeal/request.git
|
||||
cd request
|
||||
npm link
|
||||
</pre>
|
||||
|
||||
## Super simple to use
|
||||
|
||||
Request is designed to be the simplest way possible to make http calls. It support HTTPS and follows redirects by default.
|
||||
|
||||
```javascript
|
||||
var request = require('request');
|
||||
request('http://www.google.com', function (error, response, body) {
|
||||
if (!error && response.statusCode == 200) {
|
||||
console.log(body) // Print the google web page.
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## Streaming
|
||||
|
||||
You can stream any response to a file stream.
|
||||
|
||||
```javascript
|
||||
request('http://google.com/doodle.png').pipe(fs.createWriteStream('doodle.png'))
|
||||
```
|
||||
|
||||
You can also stream a file to a PUT or POST request. This method will also check the file extension against a mapping of file extensions to content-types, in this case `application/json`, and use the proper content-type in the PUT request if one is not already provided in the headers.
|
||||
|
||||
```javascript
|
||||
fs.createReadStream('file.json').pipe(request.put('http://mysite.com/obj.json'))
|
||||
```
|
||||
|
||||
Request can also pipe to itself. When doing so the content-type and content-length will be preserved in the PUT headers.
|
||||
|
||||
```javascript
|
||||
request.get('http://google.com/img.png').pipe(request.put('http://mysite.com/img.png'))
|
||||
```
|
||||
|
||||
Now let's get fancy.
|
||||
|
||||
```javascript
|
||||
http.createServer(function (req, resp) {
|
||||
if (req.url === '/doodle.png') {
|
||||
if (req.method === 'PUT') {
|
||||
req.pipe(request.put('http://mysite.com/doodle.png'))
|
||||
} else if (req.method === 'GET' || req.method === 'HEAD') {
|
||||
request.get('http://mysite.com/doodle.png').pipe(resp)
|
||||
}
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
You can also pipe() from a http.ServerRequest instance and to a http.ServerResponse instance. The HTTP method and headers will be sent as well as the entity-body data. Which means that, if you don't really care about security, you can do:
|
||||
|
||||
```javascript
|
||||
http.createServer(function (req, resp) {
|
||||
if (req.url === '/doodle.png') {
|
||||
var x = request('http://mysite.com/doodle.png')
|
||||
req.pipe(x)
|
||||
x.pipe(resp)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
And since pipe() returns the destination stream in node 0.5.x you can do one line proxying :)
|
||||
|
||||
```javascript
|
||||
req.pipe(request('http://mysite.com/doodle.png')).pipe(resp)
|
||||
```
|
||||
|
||||
Also, none of this new functionality conflicts with requests previous features, it just expands them.
|
||||
|
||||
```javascript
|
||||
var r = request.defaults({'proxy':'http://localproxy.com'})
|
||||
|
||||
http.createServer(function (req, resp) {
|
||||
if (req.url === '/doodle.png') {
|
||||
r.get('http://google.com/doodle.png').pipe(resp)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
You can still use intermediate proxies, the requests will still follow HTTP forwards, etc.
|
||||
|
||||
## OAuth Signing
|
||||
|
||||
```javascript
|
||||
// Twitter OAuth
|
||||
var qs = require('querystring')
|
||||
, oauth =
|
||||
{ callback: 'http://mysite.com/callback/'
|
||||
, consumer_key: CONSUMER_KEY
|
||||
, consumer_secret: CONSUMER_SECRET
|
||||
}
|
||||
, url = 'https://api.twitter.com/oauth/request_token'
|
||||
;
|
||||
request.post({url:url, oauth:oauth}, function (e, r, body) {
|
||||
// Assume by some stretch of magic you aquired the verifier
|
||||
var access_token = qs.parse(body)
|
||||
, oauth =
|
||||
{ consumer_key: CONSUMER_KEY
|
||||
, consumer_secret: CONSUMER_SECRET
|
||||
, token: access_token.oauth_token
|
||||
, verifier: VERIFIER
|
||||
, token_secret: access_token.oauth_token_secret
|
||||
}
|
||||
, url = 'https://api.twitter.com/oauth/access_token'
|
||||
;
|
||||
request.post({url:url, oauth:oauth}, function (e, r, body) {
|
||||
var perm_token = qs.parse(body)
|
||||
, oauth =
|
||||
{ consumer_key: CONSUMER_KEY
|
||||
, consumer_secret: CONSUMER_SECRET
|
||||
, token: perm_token.oauth_token
|
||||
, token_secret: perm_token.oauth_token_secret
|
||||
}
|
||||
, url = 'https://api.twitter.com/1/users/show.json?'
|
||||
, params =
|
||||
{ screen_name: perm_token.screen_name
|
||||
, user_id: perm_token.user_id
|
||||
}
|
||||
;
|
||||
url += qs.stringify(params)
|
||||
request.get({url:url, oauth:oauth, json:true}, function (e, r, user) {
|
||||
console.log(user)
|
||||
})
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
|
||||
### request(options, callback)
|
||||
|
||||
The first argument can be either a url or an options object. The only required option is uri, all others are optional.
|
||||
|
||||
* `uri` || `url` - fully qualified uri or a parsed url object from url.parse()
|
||||
* `qs` - object containing querystring values to be appended to the uri
|
||||
* `method` - http method, defaults to GET
|
||||
* `headers` - http headers, defaults to {}
|
||||
* `body` - entity body for POST and PUT requests. Must be buffer or string.
|
||||
* `form` - sets `body` but to querystring representation of value and adds `Content-type: application/x-www-form-urlencoded; charset=utf-8` header.
|
||||
* `json` - sets `body` but to JSON representation of value and adds `Content-type: application/json` header.
|
||||
* `multipart` - (experimental) array of objects which contains their own headers and `body` attribute. Sends `multipart/related` request. See example below.
|
||||
* `followRedirect` - follow HTTP 3xx responses as redirects. defaults to true.
|
||||
* `followAllRedirects` - follow non-GET HTTP 3xx responses as redirects. defaults to false.
|
||||
* `maxRedirects` - the maximum number of redirects to follow, defaults to 10.
|
||||
* `onResponse` - If true the callback will be fired on the "response" event instead of "end". If a function it will be called on "response" and not effect the regular semantics of the main callback on "end".
|
||||
* `encoding` - Encoding to be used on `setEncoding` of response data. If set to `null`, the body is returned as a Buffer.
|
||||
* `pool` - A hash object containing the agents for these requests. If omitted this request will use the global pool which is set to node's default maxSockets.
|
||||
* `pool.maxSockets` - Integer containing the maximum amount of sockets in the pool.
|
||||
* `timeout` - Integer containing the number of milliseconds to wait for a request to respond before aborting the request
|
||||
* `proxy` - An HTTP proxy to be used. Support proxy Auth with Basic Auth the same way it's supported with the `url` parameter by embedding the auth info in the uri.
|
||||
* `oauth` - Options for OAuth HMAC-SHA1 signing, see documentation above.
|
||||
* `strictSSL` - Set to `true` to require that SSL certificates be valid. Note: to use your own certificate authority, you need to specify an agent that was created with that ca as an option.
|
||||
* `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)
|
||||
|
||||
|
||||
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.
|
||||
|
||||
## Convenience methods
|
||||
|
||||
There are also shorthand methods for different HTTP METHODs and some other conveniences.
|
||||
|
||||
### request.defaults(options)
|
||||
|
||||
This method returns a wrapper around the normal request API that defaults to whatever options you pass in to it.
|
||||
|
||||
### request.put
|
||||
|
||||
Same as request() but defaults to `method: "PUT"`.
|
||||
|
||||
```javascript
|
||||
request.put(url)
|
||||
```
|
||||
|
||||
### request.post
|
||||
|
||||
Same as request() but defaults to `method: "POST"`.
|
||||
|
||||
```javascript
|
||||
request.post(url)
|
||||
```
|
||||
|
||||
### request.head
|
||||
|
||||
Same as request() but defaults to `method: "HEAD"`.
|
||||
|
||||
```javascript
|
||||
request.head(url)
|
||||
```
|
||||
|
||||
### request.del
|
||||
|
||||
Same as request() but defaults to `method: "DELETE"`.
|
||||
|
||||
```javascript
|
||||
request.del(url)
|
||||
```
|
||||
|
||||
### request.get
|
||||
|
||||
Alias to normal request method for uniformity.
|
||||
|
||||
```javascript
|
||||
request.get(url)
|
||||
```
|
||||
### request.cookie
|
||||
|
||||
Function that creates a new cookie.
|
||||
|
||||
```javascript
|
||||
request.cookie('cookie_string_here')
|
||||
```
|
||||
### request.jar
|
||||
|
||||
Function that creates a new cookie jar.
|
||||
|
||||
```javascript
|
||||
request.jar()
|
||||
```
|
||||
|
||||
|
||||
## Examples:
|
||||
|
||||
```javascript
|
||||
var request = require('request')
|
||||
, rand = Math.floor(Math.random()*100000000).toString()
|
||||
;
|
||||
request(
|
||||
{ method: 'PUT'
|
||||
, uri: 'http://mikeal.iriscouch.com/testjs/' + rand
|
||||
, multipart:
|
||||
[ { 'content-type': 'application/json'
|
||||
, body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}})
|
||||
}
|
||||
, { body: 'I am an attachment' }
|
||||
]
|
||||
}
|
||||
, function (error, response, body) {
|
||||
if(response.statusCode == 201){
|
||||
console.log('document saved as: http://mikeal.iriscouch.com/testjs/'+ rand)
|
||||
} else {
|
||||
console.log('error: '+ response.statusCode)
|
||||
console.log(body)
|
||||
}
|
||||
}
|
||||
)
|
||||
```
|
||||
Cookies are enabled by default (so they can be used in subsequent requests). To disable cookies set jar to false (either in defaults or in the options sent).
|
||||
|
||||
```javascript
|
||||
var request = request.defaults({jar: false})
|
||||
request('http://www.google.com', function () {
|
||||
request('http://images.google.com')
|
||||
})
|
||||
```
|
||||
|
||||
If you to use a custom cookie jar (instead of letting request use its own global cookie jar) you do so by setting the jar default or by specifying it as an option:
|
||||
|
||||
```javascript
|
||||
var j = request.jar()
|
||||
var request = request.defaults({jar:j})
|
||||
request('http://www.google.com', function () {
|
||||
request('http://images.google.com')
|
||||
})
|
||||
```
|
||||
OR
|
||||
|
||||
```javascript
|
||||
var j = request.jar()
|
||||
var cookie = request.cookie('your_cookie_here')
|
||||
j.add(cookie)
|
||||
request({url: 'http://www.google.com', jar: j}, function () {
|
||||
request('http://images.google.com')
|
||||
})
|
||||
```
|
||||
103
node_modules/request/forever.js
generated
vendored
Normal file
103
node_modules/request/forever.js
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
module.exports = ForeverAgent
|
||||
ForeverAgent.SSL = ForeverAgentSSL
|
||||
|
||||
var util = require('util')
|
||||
, Agent = require('http').Agent
|
||||
, net = require('net')
|
||||
, tls = require('tls')
|
||||
, AgentSSL = require('https').Agent
|
||||
|
||||
function ForeverAgent(options) {
|
||||
var self = this
|
||||
self.options = options || {}
|
||||
self.requests = {}
|
||||
self.sockets = {}
|
||||
self.freeSockets = {}
|
||||
self.maxSockets = self.options.maxSockets || Agent.defaultMaxSockets
|
||||
self.minSockets = self.options.minSockets || ForeverAgent.defaultMinSockets
|
||||
self.on('free', function(socket, host, port) {
|
||||
var name = host + ':' + port
|
||||
if (self.requests[name] && self.requests[name].length) {
|
||||
self.requests[name].shift().onSocket(socket)
|
||||
} else if (self.sockets[name].length < self.minSockets) {
|
||||
if (!self.freeSockets[name]) self.freeSockets[name] = []
|
||||
self.freeSockets[name].push(socket)
|
||||
|
||||
// if an error happens while we don't use the socket anyway, meh, throw the socket away
|
||||
function onIdleError() {
|
||||
socket.destroy()
|
||||
}
|
||||
socket._onIdleError = onIdleError
|
||||
socket.on('error', onIdleError)
|
||||
} else {
|
||||
// If there are no pending requests just destroy the
|
||||
// socket and it will get removed from the pool. This
|
||||
// gets us out of timeout issues and allows us to
|
||||
// default to Connection:keep-alive.
|
||||
socket.destroy();
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
util.inherits(ForeverAgent, Agent)
|
||||
|
||||
ForeverAgent.defaultMinSockets = 5
|
||||
|
||||
|
||||
ForeverAgent.prototype.createConnection = net.createConnection
|
||||
ForeverAgent.prototype.addRequestNoreuse = Agent.prototype.addRequest
|
||||
ForeverAgent.prototype.addRequest = function(req, host, port) {
|
||||
var name = host + ':' + port
|
||||
if (this.freeSockets[name] && this.freeSockets[name].length > 0 && !req.useChunkedEncodingByDefault) {
|
||||
var idleSocket = this.freeSockets[name].pop()
|
||||
idleSocket.removeListener('error', idleSocket._onIdleError)
|
||||
delete idleSocket._onIdleError
|
||||
req._reusedSocket = true
|
||||
req.onSocket(idleSocket)
|
||||
} else {
|
||||
this.addRequestNoreuse(req, host, port)
|
||||
}
|
||||
}
|
||||
|
||||
ForeverAgent.prototype.removeSocket = function(s, name, host, port) {
|
||||
if (this.sockets[name]) {
|
||||
var index = this.sockets[name].indexOf(s);
|
||||
if (index !== -1) {
|
||||
this.sockets[name].splice(index, 1);
|
||||
}
|
||||
} else if (this.sockets[name] && this.sockets[name].length === 0) {
|
||||
// don't leak
|
||||
delete this.sockets[name];
|
||||
delete this.requests[name];
|
||||
}
|
||||
|
||||
if (this.freeSockets[name]) {
|
||||
var index = this.freeSockets[name].indexOf(s)
|
||||
if (index !== -1) {
|
||||
this.freeSockets[name].splice(index, 1)
|
||||
if (this.freeSockets[name].length === 0) {
|
||||
delete this.freeSockets[name]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.requests[name] && this.requests[name].length) {
|
||||
// If we have pending requests and a socket gets closed a new one
|
||||
// needs to be created to take over in the pool for the one that closed.
|
||||
this.createSocket(name, host, port).emit('free');
|
||||
}
|
||||
}
|
||||
|
||||
function ForeverAgentSSL (options) {
|
||||
ForeverAgent.call(this, options)
|
||||
}
|
||||
util.inherits(ForeverAgentSSL, ForeverAgent)
|
||||
|
||||
ForeverAgentSSL.prototype.createConnection = createConnectionSSL
|
||||
ForeverAgentSSL.prototype.addRequestNoreuse = AgentSSL.prototype.addRequest
|
||||
|
||||
function createConnectionSSL (port, host, options) {
|
||||
options.port = port
|
||||
options.host = host
|
||||
return tls.connect(options)
|
||||
}
|
||||
874
node_modules/request/main.js
generated
vendored
Normal file
874
node_modules/request/main.js
generated
vendored
Normal file
@@ -0,0 +1,874 @@
|
||||
// Copyright 2010-2012 Mikeal Rogers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
var http = require('http')
|
||||
, https = false
|
||||
, tls = false
|
||||
, url = require('url')
|
||||
, util = require('util')
|
||||
, stream = require('stream')
|
||||
, qs = require('querystring')
|
||||
, mimetypes = require('./mimetypes')
|
||||
, oauth = require('./oauth')
|
||||
, uuid = require('./uuid')
|
||||
, ForeverAgent = require('./forever')
|
||||
, Cookie = require('./vendor/cookie')
|
||||
, CookieJar = require('./vendor/cookie/jar')
|
||||
, cookieJar = new CookieJar
|
||||
, tunnel = require('./tunnel')
|
||||
;
|
||||
|
||||
if (process.logging) {
|
||||
var log = process.logging('request')
|
||||
}
|
||||
|
||||
try {
|
||||
https = require('https')
|
||||
} catch (e) {}
|
||||
|
||||
try {
|
||||
tls = require('tls')
|
||||
} catch (e) {}
|
||||
|
||||
function toBase64 (str) {
|
||||
return (new Buffer(str || "", "ascii")).toString("base64")
|
||||
}
|
||||
|
||||
// Hacky fix for pre-0.4.4 https
|
||||
if (https && !https.Agent) {
|
||||
https.Agent = function (options) {
|
||||
http.Agent.call(this, options)
|
||||
}
|
||||
util.inherits(https.Agent, http.Agent)
|
||||
https.Agent.prototype._getConnection = function(host, port, cb) {
|
||||
var s = tls.connect(port, host, this.options, function() {
|
||||
// do other checks here?
|
||||
if (cb) cb()
|
||||
})
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
function isReadStream (rs) {
|
||||
if (rs.readable && rs.path && rs.mode) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
function copy (obj) {
|
||||
var o = {}
|
||||
Object.keys(obj).forEach(function (i) {
|
||||
o[i] = obj[i]
|
||||
})
|
||||
return o
|
||||
}
|
||||
|
||||
var isUrl = /^https?:/
|
||||
|
||||
var globalPool = {}
|
||||
|
||||
function Request (options) {
|
||||
stream.Stream.call(this)
|
||||
this.readable = true
|
||||
this.writable = true
|
||||
|
||||
if (typeof options === 'string') {
|
||||
options = {uri:options}
|
||||
}
|
||||
|
||||
var reserved = Object.keys(Request.prototype)
|
||||
for (var i in options) {
|
||||
if (reserved.indexOf(i) === -1) {
|
||||
this[i] = options[i]
|
||||
} else {
|
||||
if (typeof options[i] === 'function') {
|
||||
delete options[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
options = copy(options)
|
||||
|
||||
this.init(options)
|
||||
}
|
||||
util.inherits(Request, stream.Stream)
|
||||
Request.prototype.init = function (options) {
|
||||
var self = this
|
||||
|
||||
if (!options) options = {}
|
||||
|
||||
if (!self.pool) self.pool = globalPool
|
||||
self.dests = []
|
||||
self.__isRequestRequest = true
|
||||
|
||||
// Protect against double callback
|
||||
if (!self._callback && self.callback) {
|
||||
self._callback = self.callback
|
||||
self.callback = function () {
|
||||
if (self._callbackCalled) return // Print a warning maybe?
|
||||
self._callback.apply(self, arguments)
|
||||
self._callbackCalled = true
|
||||
}
|
||||
}
|
||||
|
||||
if (self.url) {
|
||||
// People use this property instead all the time so why not just support it.
|
||||
self.uri = self.url
|
||||
delete self.url
|
||||
}
|
||||
|
||||
if (!self.uri) {
|
||||
throw new Error("options.uri is a required argument")
|
||||
} else {
|
||||
if (typeof self.uri == "string") self.uri = url.parse(self.uri)
|
||||
}
|
||||
if (self.proxy) {
|
||||
if (typeof self.proxy == 'string') self.proxy = url.parse(self.proxy)
|
||||
|
||||
// do the HTTP CONNECT dance using koichik/node-tunnel
|
||||
if (http.globalAgent && self.uri.protocol === "https:") {
|
||||
self.tunnel = true
|
||||
var tunnelFn = self.proxy.protocol === "http:"
|
||||
? tunnel.httpsOverHttp : tunnel.httpsOverHttps
|
||||
|
||||
var tunnelOptions = { proxy: { host: self.proxy.hostname
|
||||
, port: +self.proxy.port }
|
||||
, ca: this.ca }
|
||||
|
||||
self.agent = tunnelFn(tunnelOptions)
|
||||
self.tunnel = true
|
||||
}
|
||||
}
|
||||
|
||||
self._redirectsFollowed = self._redirectsFollowed || 0
|
||||
self.maxRedirects = (self.maxRedirects !== undefined) ? self.maxRedirects : 10
|
||||
self.followRedirect = (self.followRedirect !== undefined) ? self.followRedirect : true
|
||||
self.followAllRedirects = (self.followAllRedirects !== undefined) ? self.followAllRedirects : false;
|
||||
if (self.followRedirect || self.followAllRedirects)
|
||||
self.redirects = self.redirects || []
|
||||
|
||||
self.headers = self.headers ? copy(self.headers) : {}
|
||||
|
||||
self.setHost = false
|
||||
if (!self.headers.host) {
|
||||
self.headers.host = self.uri.hostname
|
||||
if (self.uri.port) {
|
||||
if ( !(self.uri.port === 80 && self.uri.protocol === 'http:') &&
|
||||
!(self.uri.port === 443 && self.uri.protocol === 'https:') )
|
||||
self.headers.host += (':'+self.uri.port)
|
||||
}
|
||||
self.setHost = true
|
||||
}
|
||||
|
||||
self.jar(options.jar)
|
||||
|
||||
if (!self.uri.pathname) {self.uri.pathname = '/'}
|
||||
if (!self.uri.port) {
|
||||
if (self.uri.protocol == 'http:') {self.uri.port = 80}
|
||||
else if (self.uri.protocol == 'https:') {self.uri.port = 443}
|
||||
}
|
||||
|
||||
if (self.proxy && !self.tunnel) {
|
||||
self.port = self.proxy.port
|
||||
self.host = self.proxy.hostname
|
||||
} else {
|
||||
self.port = self.uri.port
|
||||
self.host = self.uri.hostname
|
||||
}
|
||||
|
||||
if (self.onResponse === true) {
|
||||
self.onResponse = self.callback
|
||||
delete self.callback
|
||||
}
|
||||
|
||||
self.clientErrorHandler = function (error) {
|
||||
if (self._aborted) return
|
||||
|
||||
if (self.setHost) delete self.headers.host
|
||||
if (self.req._reusedSocket && error.code === 'ECONNRESET'
|
||||
&& self.agent.addRequestNoreuse) {
|
||||
self.agent = { addRequest: self.agent.addRequestNoreuse.bind(self.agent) }
|
||||
self.start()
|
||||
self.req.end()
|
||||
return
|
||||
}
|
||||
if (self.timeout && self.timeoutTimer) {
|
||||
clearTimeout(self.timeoutTimer);
|
||||
self.timeoutTimer = null;
|
||||
}
|
||||
self.emit('error', error)
|
||||
}
|
||||
if (self.onResponse) self.on('error', function (e) {self.onResponse(e)})
|
||||
if (self.callback) self.on('error', function (e) {self.callback(e)})
|
||||
|
||||
if (options.form) {
|
||||
self.form(options.form)
|
||||
}
|
||||
|
||||
if (options.oauth) {
|
||||
self.oauth(options.oauth)
|
||||
}
|
||||
|
||||
if (self.uri.auth && !self.headers.authorization) {
|
||||
self.headers.authorization = "Basic " + toBase64(self.uri.auth.split(':').map(function(item){ return qs.unescape(item)}).join(':'))
|
||||
}
|
||||
if (self.proxy && self.proxy.auth && !self.headers['proxy-authorization'] && !self.tunnel) {
|
||||
self.headers['proxy-authorization'] = "Basic " + toBase64(self.proxy.auth.split(':').map(function(item){ return qs.unescape(item)}).join(':'))
|
||||
}
|
||||
|
||||
if (options.qs) self.qs(options.qs)
|
||||
|
||||
if (self.uri.path) {
|
||||
self.path = self.uri.path
|
||||
} else {
|
||||
self.path = self.uri.pathname + (self.uri.search || "")
|
||||
}
|
||||
|
||||
if (self.path.length === 0) self.path = '/'
|
||||
|
||||
if (self.proxy && !self.tunnel) self.path = (self.uri.protocol + '//' + self.uri.host + self.path)
|
||||
|
||||
if (options.json) {
|
||||
self.json(options.json)
|
||||
} else if (options.multipart) {
|
||||
self.multipart(options.multipart)
|
||||
}
|
||||
|
||||
if (self.body) {
|
||||
var length = 0
|
||||
if (!Buffer.isBuffer(self.body)) {
|
||||
if (Array.isArray(self.body)) {
|
||||
for (var i = 0; i < self.body.length; i++) {
|
||||
length += self.body[i].length
|
||||
}
|
||||
} else {
|
||||
self.body = new Buffer(self.body)
|
||||
length = self.body.length
|
||||
}
|
||||
} else {
|
||||
length = self.body.length
|
||||
}
|
||||
if (length) {
|
||||
self.headers['content-length'] = length
|
||||
} else {
|
||||
throw new Error('Argument error, options.body.')
|
||||
}
|
||||
}
|
||||
|
||||
var protocol = self.proxy && !self.tunnel ? self.proxy.protocol : self.uri.protocol
|
||||
, defaultModules = {'http:':http, 'https:':https}
|
||||
, httpModules = self.httpModules || {}
|
||||
;
|
||||
self.httpModule = httpModules[protocol] || defaultModules[protocol]
|
||||
|
||||
if (!self.httpModule) throw new Error("Invalid protocol")
|
||||
|
||||
if (options.ca) self.ca = options.ca
|
||||
|
||||
if (!self.agent) {
|
||||
if (options.agentOptions) self.agentOptions = options.agentOptions
|
||||
|
||||
if (options.agentClass) {
|
||||
self.agentClass = options.agentClass
|
||||
} else if (options.forever) {
|
||||
self.agentClass = protocol === 'http:' ? ForeverAgent : ForeverAgent.SSL
|
||||
} else {
|
||||
self.agentClass = self.httpModule.Agent
|
||||
}
|
||||
}
|
||||
|
||||
if (self.pool === false) {
|
||||
self.agent = false
|
||||
} else {
|
||||
self.agent = self.agent || self.getAgent()
|
||||
if (self.maxSockets) {
|
||||
// Don't use our pooling if node has the refactored client
|
||||
self.agent.maxSockets = self.maxSockets
|
||||
}
|
||||
if (self.pool.maxSockets) {
|
||||
// Don't use our pooling if node has the refactored client
|
||||
self.agent.maxSockets = self.pool.maxSockets
|
||||
}
|
||||
}
|
||||
|
||||
self.once('pipe', function (src) {
|
||||
if (self.ntick) throw new Error("You cannot pipe to this stream after the first nextTick() after creation of the request stream.")
|
||||
self.src = src
|
||||
if (isReadStream(src)) {
|
||||
if (!self.headers['content-type'] && !self.headers['Content-Type'])
|
||||
self.headers['content-type'] = mimetypes.lookup(src.path.slice(src.path.lastIndexOf('.')+1))
|
||||
} else {
|
||||
if (src.headers) {
|
||||
for (var i in src.headers) {
|
||||
if (!self.headers[i]) {
|
||||
self.headers[i] = src.headers[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
if (src.method && !self.method) {
|
||||
self.method = src.method
|
||||
}
|
||||
}
|
||||
|
||||
self.on('pipe', function () {
|
||||
console.error("You have already piped to this stream. Pipeing twice is likely to break the request.")
|
||||
})
|
||||
})
|
||||
|
||||
process.nextTick(function () {
|
||||
if (self._aborted) return
|
||||
|
||||
if (self.body) {
|
||||
if (Array.isArray(self.body)) {
|
||||
self.body.forEach(function(part) {
|
||||
self.write(part)
|
||||
})
|
||||
} else {
|
||||
self.write(self.body)
|
||||
}
|
||||
self.end()
|
||||
} else if (self.requestBodyStream) {
|
||||
console.warn("options.requestBodyStream is deprecated, please pass the request object to stream.pipe.")
|
||||
self.requestBodyStream.pipe(self)
|
||||
} else if (!self.src) {
|
||||
self.headers['content-length'] = 0
|
||||
self.end()
|
||||
}
|
||||
self.ntick = true
|
||||
})
|
||||
}
|
||||
|
||||
Request.prototype.getAgent = function () {
|
||||
var Agent = this.agentClass
|
||||
var options = {}
|
||||
if (this.agentOptions) {
|
||||
for (var i in this.agentOptions) {
|
||||
options[i] = this.agentOptions[i]
|
||||
}
|
||||
}
|
||||
if (this.ca) options.ca = this.ca
|
||||
|
||||
var poolKey = ''
|
||||
|
||||
// different types of agents are in different pools
|
||||
if (Agent !== this.httpModule.Agent) {
|
||||
poolKey += Agent.name
|
||||
}
|
||||
|
||||
if (!this.httpModule.globalAgent) {
|
||||
// node 0.4.x
|
||||
options.host = this.host
|
||||
options.port = this.port
|
||||
if (poolKey) poolKey += ':'
|
||||
poolKey += this.host + ':' + this.port
|
||||
}
|
||||
|
||||
if (options.ca) {
|
||||
if (poolKey) poolKey += ':'
|
||||
poolKey += options.ca
|
||||
}
|
||||
|
||||
if (!poolKey && Agent === this.httpModule.Agent && this.httpModule.globalAgent) {
|
||||
// not doing anything special. Use the globalAgent
|
||||
return this.httpModule.globalAgent
|
||||
}
|
||||
|
||||
// already generated an agent for this setting
|
||||
if (this.pool[poolKey]) return this.pool[poolKey]
|
||||
|
||||
return this.pool[poolKey] = new Agent(options)
|
||||
}
|
||||
|
||||
Request.prototype.start = function () {
|
||||
var self = this
|
||||
|
||||
if (self._aborted) return
|
||||
|
||||
self._started = true
|
||||
self.method = self.method || 'GET'
|
||||
self.href = self.uri.href
|
||||
if (log) log('%method %href', self)
|
||||
self.req = self.httpModule.request(self, function (response) {
|
||||
if (self._aborted) return
|
||||
if (self._paused) response.pause()
|
||||
|
||||
self.response = response
|
||||
response.request = self
|
||||
|
||||
if (self.httpModule === https &&
|
||||
self.strictSSL &&
|
||||
!response.client.authorized) {
|
||||
var sslErr = response.client.authorizationError
|
||||
self.emit('error', new Error('SSL Error: '+ sslErr))
|
||||
return
|
||||
}
|
||||
|
||||
if (self.setHost) delete self.headers.host
|
||||
if (self.timeout && self.timeoutTimer) {
|
||||
clearTimeout(self.timeoutTimer);
|
||||
self.timeoutTimer = null;
|
||||
}
|
||||
|
||||
if (response.headers['set-cookie'] && (!self._disableCookies)) {
|
||||
response.headers['set-cookie'].forEach(function(cookie) {
|
||||
if (self._jar) self._jar.add(new Cookie(cookie))
|
||||
else cookieJar.add(new Cookie(cookie))
|
||||
})
|
||||
}
|
||||
|
||||
if (response.statusCode >= 300 && response.statusCode < 400 &&
|
||||
(self.followAllRedirects ||
|
||||
(self.followRedirect && (self.method !== 'PUT' && self.method !== 'POST' && self.method !== 'DELETE'))) &&
|
||||
response.headers.location) {
|
||||
if (self._redirectsFollowed >= self.maxRedirects) {
|
||||
self.emit('error', new Error("Exceeded maxRedirects. Probably stuck in a redirect loop."))
|
||||
return
|
||||
}
|
||||
self._redirectsFollowed += 1
|
||||
|
||||
if (!isUrl.test(response.headers.location)) {
|
||||
response.headers.location = url.resolve(self.uri.href, response.headers.location)
|
||||
}
|
||||
self.uri = response.headers.location
|
||||
self.redirects.push(
|
||||
{ statusCode : response.statusCode
|
||||
, redirectUri: response.headers.location
|
||||
}
|
||||
)
|
||||
self.method = 'GET'; // Force all redirects to use GET
|
||||
delete self.req
|
||||
delete self.agent
|
||||
delete self._started
|
||||
if (self.headers) {
|
||||
delete self.headers.host
|
||||
}
|
||||
if (log) log('Redirect to %uri', self)
|
||||
self.init()
|
||||
return // Ignore the rest of the response
|
||||
} else {
|
||||
self._redirectsFollowed = self._redirectsFollowed || 0
|
||||
// Be a good stream and emit end when the response is finished.
|
||||
// Hack to emit end on close because of a core bug that never fires end
|
||||
response.on('close', function () {
|
||||
if (!self._ended) self.response.emit('end')
|
||||
})
|
||||
|
||||
if (self.encoding) {
|
||||
if (self.dests.length !== 0) {
|
||||
console.error("Ingoring encoding parameter as this stream is being piped to another stream which makes the encoding option invalid.")
|
||||
} else {
|
||||
response.setEncoding(self.encoding)
|
||||
}
|
||||
}
|
||||
|
||||
self.dests.forEach(function (dest) {
|
||||
self.pipeDest(dest)
|
||||
})
|
||||
|
||||
response.on("data", function (chunk) {
|
||||
self._destdata = true
|
||||
self.emit("data", chunk)
|
||||
})
|
||||
response.on("end", function (chunk) {
|
||||
self._ended = true
|
||||
self.emit("end", chunk)
|
||||
})
|
||||
response.on("close", function () {self.emit("close")})
|
||||
|
||||
self.emit('response', response)
|
||||
|
||||
if (self.onResponse) {
|
||||
self.onResponse(null, response)
|
||||
}
|
||||
if (self.callback) {
|
||||
var buffer = []
|
||||
var bodyLen = 0
|
||||
self.on("data", function (chunk) {
|
||||
buffer.push(chunk)
|
||||
bodyLen += chunk.length
|
||||
})
|
||||
self.on("end", function () {
|
||||
if (self._aborted) return
|
||||
|
||||
if (buffer.length && Buffer.isBuffer(buffer[0])) {
|
||||
var body = new Buffer(bodyLen)
|
||||
var i = 0
|
||||
buffer.forEach(function (chunk) {
|
||||
chunk.copy(body, i, 0, chunk.length)
|
||||
i += chunk.length
|
||||
})
|
||||
if (self.encoding === null) {
|
||||
response.body = body
|
||||
} else {
|
||||
response.body = body.toString()
|
||||
}
|
||||
} else if (buffer.length) {
|
||||
response.body = buffer.join('')
|
||||
}
|
||||
|
||||
if (self._json) {
|
||||
try {
|
||||
response.body = JSON.parse(response.body)
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
self.callback(null, response, response.body)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (self.timeout && !self.timeoutTimer) {
|
||||
self.timeoutTimer = setTimeout(function() {
|
||||
self.req.abort()
|
||||
var e = new Error("ETIMEDOUT")
|
||||
e.code = "ETIMEDOUT"
|
||||
self.emit("error", e)
|
||||
}, self.timeout)
|
||||
|
||||
// Set additional timeout on socket - in case if remote
|
||||
// server freeze after sending headers
|
||||
if (self.req.setTimeout) { // only works on node 0.6+
|
||||
self.req.setTimeout(self.timeout, function(){
|
||||
if (self.req) {
|
||||
self.req.abort()
|
||||
var e = new Error("ESOCKETTIMEDOUT")
|
||||
e.code = "ESOCKETTIMEDOUT"
|
||||
self.emit("error", e)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
self.req.on('error', self.clientErrorHandler)
|
||||
|
||||
self.emit('request', self.req)
|
||||
}
|
||||
|
||||
Request.prototype.abort = function() {
|
||||
this._aborted = true;
|
||||
|
||||
if (this.req) {
|
||||
this.req.abort()
|
||||
}
|
||||
else if (this.response) {
|
||||
this.response.abort()
|
||||
}
|
||||
|
||||
this.emit("abort")
|
||||
}
|
||||
|
||||
Request.prototype.pipeDest = function (dest) {
|
||||
var response = this.response
|
||||
// Called after the response is received
|
||||
if (dest.headers) {
|
||||
dest.headers['content-type'] = response.headers['content-type']
|
||||
if (response.headers['content-length']) {
|
||||
dest.headers['content-length'] = response.headers['content-length']
|
||||
}
|
||||
}
|
||||
if (dest.setHeader) {
|
||||
for (var i in response.headers) {
|
||||
dest.setHeader(i, response.headers[i])
|
||||
}
|
||||
dest.statusCode = response.statusCode
|
||||
}
|
||||
if (this.pipefilter) this.pipefilter(response, dest)
|
||||
}
|
||||
|
||||
// Composable API
|
||||
Request.prototype.setHeader = function (name, value, clobber) {
|
||||
if (clobber === undefined) clobber = true
|
||||
if (clobber || !this.headers.hasOwnProperty(name)) this.headers[name] = value
|
||||
else this.headers[name] += ',' + value
|
||||
return this
|
||||
}
|
||||
Request.prototype.setHeaders = function (headers) {
|
||||
for (i in headers) {this.setHeader(i, headers[i])}
|
||||
return this
|
||||
}
|
||||
Request.prototype.qs = function (q, clobber) {
|
||||
var uri = {
|
||||
protocol: this.uri.protocol,
|
||||
host: this.uri.host,
|
||||
pathname: this.uri.pathname,
|
||||
query: clobber ? q : qs.parse(this.uri.query),
|
||||
hash: this.uri.hash
|
||||
};
|
||||
if (!clobber) for (var i in q) uri.query[i] = q[i]
|
||||
|
||||
this.uri= url.parse(url.format(uri))
|
||||
|
||||
return this
|
||||
}
|
||||
Request.prototype.form = function (form) {
|
||||
this.headers['content-type'] = 'application/x-www-form-urlencoded; charset=utf-8'
|
||||
this.body = qs.stringify(form).toString('utf8')
|
||||
return this
|
||||
}
|
||||
Request.prototype.multipart = function (multipart) {
|
||||
var self = this
|
||||
self.body = []
|
||||
|
||||
if (!self.headers['content-type']) {
|
||||
self.headers['content-type'] = 'multipart/related;boundary="frontier"';
|
||||
} else {
|
||||
self.headers['content-type'] = self.headers['content-type'].split(';')[0] + ';boundary="frontier"';
|
||||
}
|
||||
|
||||
if (!multipart.forEach) throw new Error('Argument error, options.multipart.')
|
||||
|
||||
multipart.forEach(function (part) {
|
||||
var body = part.body
|
||||
if(!body) throw Error('Body attribute missing in multipart.')
|
||||
delete part.body
|
||||
var preamble = '--frontier\r\n'
|
||||
Object.keys(part).forEach(function(key){
|
||||
preamble += key + ': ' + part[key] + '\r\n'
|
||||
})
|
||||
preamble += '\r\n'
|
||||
self.body.push(new Buffer(preamble))
|
||||
self.body.push(new Buffer(body))
|
||||
self.body.push(new Buffer('\r\n'))
|
||||
})
|
||||
self.body.push(new Buffer('--frontier--'))
|
||||
return self
|
||||
}
|
||||
Request.prototype.json = function (val) {
|
||||
this.setHeader('content-type', 'application/json')
|
||||
this.setHeader('accept', 'application/json')
|
||||
this._json = true
|
||||
if (typeof val === 'boolean') {
|
||||
if (typeof this.body === 'object') this.body = JSON.stringify(this.body)
|
||||
} else {
|
||||
this.body = JSON.stringify(val)
|
||||
}
|
||||
return this
|
||||
}
|
||||
Request.prototype.oauth = function (_oauth) {
|
||||
var form
|
||||
if (this.headers['content-type'] &&
|
||||
this.headers['content-type'].slice(0, 'application/x-www-form-urlencoded'.length) ===
|
||||
'application/x-www-form-urlencoded'
|
||||
) {
|
||||
form = qs.parse(this.body)
|
||||
}
|
||||
if (this.uri.query) {
|
||||
form = qs.parse(this.uri.query)
|
||||
}
|
||||
if (!form) form = {}
|
||||
var oa = {}
|
||||
for (var i in form) oa[i] = form[i]
|
||||
for (var i in _oauth) oa['oauth_'+i] = _oauth[i]
|
||||
if (!oa.oauth_version) oa.oauth_version = '1.0'
|
||||
if (!oa.oauth_timestamp) oa.oauth_timestamp = Math.floor( (new Date()).getTime() / 1000 ).toString()
|
||||
if (!oa.oauth_nonce) oa.oauth_nonce = uuid().replace(/-/g, '')
|
||||
|
||||
oa.oauth_signature_method = 'HMAC-SHA1'
|
||||
|
||||
var consumer_secret = oa.oauth_consumer_secret
|
||||
delete oa.oauth_consumer_secret
|
||||
var token_secret = oa.oauth_token_secret
|
||||
delete oa.oauth_token_secret
|
||||
|
||||
var baseurl = this.uri.protocol + '//' + this.uri.host + this.uri.pathname
|
||||
var signature = oauth.hmacsign(this.method, baseurl, oa, consumer_secret, token_secret)
|
||||
|
||||
// oa.oauth_signature = signature
|
||||
for (var i in form) {
|
||||
if ( i.slice(0, 'oauth_') in _oauth) {
|
||||
// skip
|
||||
} else {
|
||||
delete oa['oauth_'+i]
|
||||
}
|
||||
}
|
||||
this.headers.authorization =
|
||||
'OAuth '+Object.keys(oa).sort().map(function (i) {return i+'="'+oauth.rfc3986(oa[i])+'"'}).join(',')
|
||||
this.headers.authorization += ',oauth_signature="'+oauth.rfc3986(signature)+'"'
|
||||
return this
|
||||
}
|
||||
Request.prototype.jar = function (jar) {
|
||||
var cookies
|
||||
|
||||
if (this._redirectsFollowed === 0) {
|
||||
this.originalCookieHeader = this.headers.cookie
|
||||
}
|
||||
|
||||
if (jar === false) {
|
||||
// disable cookies
|
||||
cookies = false;
|
||||
this._disableCookies = true;
|
||||
} else if (jar) {
|
||||
// fetch cookie from the user defined cookie jar
|
||||
cookies = jar.get({ url: this.uri.href })
|
||||
} else {
|
||||
// fetch cookie from the global cookie jar
|
||||
cookies = cookieJar.get({ url: this.uri.href })
|
||||
}
|
||||
|
||||
if (cookies && cookies.length) {
|
||||
var cookieString = cookies.map(function (c) {
|
||||
return c.name + "=" + c.value
|
||||
}).join("; ")
|
||||
|
||||
if (this.originalCookieHeader) {
|
||||
// Don't overwrite existing Cookie header
|
||||
this.headers.cookie = this.originalCookieHeader + '; ' + cookieString
|
||||
} else {
|
||||
this.headers.cookie = cookieString
|
||||
}
|
||||
}
|
||||
this._jar = jar
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
// Stream API
|
||||
Request.prototype.pipe = function (dest, opts) {
|
||||
if (this.response) {
|
||||
if (this._destdata) {
|
||||
throw new Error("You cannot pipe after data has been emitted from the response.")
|
||||
} else if (this._ended) {
|
||||
throw new Error("You cannot pipe after the response has been ended.")
|
||||
} else {
|
||||
stream.Stream.prototype.pipe.call(this, dest, opts)
|
||||
this.pipeDest(dest)
|
||||
return dest
|
||||
}
|
||||
} else {
|
||||
this.dests.push(dest)
|
||||
stream.Stream.prototype.pipe.call(this, dest, opts)
|
||||
return dest
|
||||
}
|
||||
}
|
||||
Request.prototype.write = function () {
|
||||
if (!this._started) this.start()
|
||||
this.req.write.apply(this.req, arguments)
|
||||
}
|
||||
Request.prototype.end = function (chunk) {
|
||||
if (chunk) this.write(chunk)
|
||||
if (!this._started) this.start()
|
||||
this.req.end()
|
||||
}
|
||||
Request.prototype.pause = function () {
|
||||
if (!this.response) this._paused = true
|
||||
else this.response.pause.apply(this.response, arguments)
|
||||
}
|
||||
Request.prototype.resume = function () {
|
||||
if (!this.response) this._paused = false
|
||||
else this.response.resume.apply(this.response, arguments)
|
||||
}
|
||||
Request.prototype.destroy = function () {
|
||||
if (!this._ended) this.end()
|
||||
}
|
||||
|
||||
// organize params for post, put, head, del
|
||||
function initParams(uri, options, callback) {
|
||||
if ((typeof options === 'function') && !callback) callback = options;
|
||||
if (typeof options === 'object') {
|
||||
options.uri = uri;
|
||||
} else if (typeof uri === 'string') {
|
||||
options = {uri:uri};
|
||||
} else {
|
||||
options = uri;
|
||||
uri = options.uri;
|
||||
}
|
||||
return { uri: uri, options: options, callback: callback };
|
||||
}
|
||||
|
||||
function request (uri, options, callback) {
|
||||
if ((typeof options === 'function') && !callback) callback = options;
|
||||
if (typeof options === 'object') {
|
||||
options.uri = uri;
|
||||
} else if (typeof uri === 'string') {
|
||||
options = {uri:uri};
|
||||
} else {
|
||||
options = uri;
|
||||
}
|
||||
|
||||
if (callback) options.callback = callback;
|
||||
var r = new Request(options)
|
||||
return r
|
||||
}
|
||||
|
||||
module.exports = request
|
||||
|
||||
request.defaults = function (options) {
|
||||
var def = function (method) {
|
||||
var d = function (uri, opts, callback) {
|
||||
var params = initParams(uri, opts, callback);
|
||||
for (var i in options) {
|
||||
if (params.options[i] === undefined) params.options[i] = options[i]
|
||||
}
|
||||
return method(params.uri, params.options, params.callback)
|
||||
}
|
||||
return d
|
||||
}
|
||||
var de = def(request)
|
||||
de.get = def(request.get)
|
||||
de.post = def(request.post)
|
||||
de.put = def(request.put)
|
||||
de.head = def(request.head)
|
||||
de.del = def(request.del)
|
||||
de.cookie = def(request.cookie)
|
||||
de.jar = def(request.jar)
|
||||
return de
|
||||
}
|
||||
|
||||
request.forever = function (agentOptions, optionsArg) {
|
||||
var options = {}
|
||||
if (optionsArg) {
|
||||
for (option in optionsArg) {
|
||||
options[option] = optionsArg[option]
|
||||
}
|
||||
}
|
||||
if (agentOptions) options.agentOptions = agentOptions
|
||||
options.forever = true
|
||||
return request.defaults(options)
|
||||
}
|
||||
|
||||
request.get = request
|
||||
request.post = function (uri, options, callback) {
|
||||
var params = initParams(uri, options, callback);
|
||||
params.options.method = 'POST';
|
||||
return request(params.uri, params.options, params.callback)
|
||||
}
|
||||
request.put = function (uri, options, callback) {
|
||||
var params = initParams(uri, options, callback);
|
||||
params.options.method = 'PUT'
|
||||
return request(params.uri, params.options, params.callback)
|
||||
}
|
||||
request.head = function (uri, options, callback) {
|
||||
var params = initParams(uri, options, callback);
|
||||
params.options.method = 'HEAD'
|
||||
if (params.options.body ||
|
||||
params.options.requestBodyStream ||
|
||||
(params.options.json && typeof params.options.json !== 'boolean') ||
|
||||
params.options.multipart) {
|
||||
throw new Error("HTTP HEAD requests MUST NOT include a request body.")
|
||||
}
|
||||
return request(params.uri, params.options, params.callback)
|
||||
}
|
||||
request.del = function (uri, options, callback) {
|
||||
var params = initParams(uri, options, callback);
|
||||
params.options.method = 'DELETE'
|
||||
return request(params.uri, params.options, params.callback)
|
||||
}
|
||||
request.jar = function () {
|
||||
return new CookieJar
|
||||
}
|
||||
request.cookie = function (str) {
|
||||
if (str && str.uri) str = str.uri
|
||||
if (typeof str !== 'string') throw new Error("The cookie function only accepts STRING as param")
|
||||
return new Cookie(str)
|
||||
}
|
||||
152
node_modules/request/mimetypes.js
generated
vendored
Normal file
152
node_modules/request/mimetypes.js
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
// from http://github.com/felixge/node-paperboy
|
||||
exports.types = {
|
||||
"3gp":"video/3gpp",
|
||||
"aiff":"audio/x-aiff",
|
||||
"arj":"application/x-arj-compressed",
|
||||
"asf":"video/x-ms-asf",
|
||||
"asx":"video/x-ms-asx",
|
||||
"au":"audio/ulaw",
|
||||
"avi":"video/x-msvideo",
|
||||
"bcpio":"application/x-bcpio",
|
||||
"ccad":"application/clariscad",
|
||||
"cod":"application/vnd.rim.cod",
|
||||
"com":"application/x-msdos-program",
|
||||
"cpio":"application/x-cpio",
|
||||
"cpt":"application/mac-compactpro",
|
||||
"csh":"application/x-csh",
|
||||
"css":"text/css",
|
||||
"deb":"application/x-debian-package",
|
||||
"dl":"video/dl",
|
||||
"doc":"application/msword",
|
||||
"drw":"application/drafting",
|
||||
"dvi":"application/x-dvi",
|
||||
"dwg":"application/acad",
|
||||
"dxf":"application/dxf",
|
||||
"dxr":"application/x-director",
|
||||
"etx":"text/x-setext",
|
||||
"ez":"application/andrew-inset",
|
||||
"fli":"video/x-fli",
|
||||
"flv":"video/x-flv",
|
||||
"gif":"image/gif",
|
||||
"gl":"video/gl",
|
||||
"gtar":"application/x-gtar",
|
||||
"gz":"application/x-gzip",
|
||||
"hdf":"application/x-hdf",
|
||||
"hqx":"application/mac-binhex40",
|
||||
"html":"text/html",
|
||||
"ice":"x-conference/x-cooltalk",
|
||||
"ico":"image/x-icon",
|
||||
"ief":"image/ief",
|
||||
"igs":"model/iges",
|
||||
"ips":"application/x-ipscript",
|
||||
"ipx":"application/x-ipix",
|
||||
"jad":"text/vnd.sun.j2me.app-descriptor",
|
||||
"jar":"application/java-archive",
|
||||
"jpeg":"image/jpeg",
|
||||
"jpg":"image/jpeg",
|
||||
"js":"text/javascript",
|
||||
"json":"application/json",
|
||||
"latex":"application/x-latex",
|
||||
"lsp":"application/x-lisp",
|
||||
"lzh":"application/octet-stream",
|
||||
"m":"text/plain",
|
||||
"m3u":"audio/x-mpegurl",
|
||||
"m4v":"video/mp4",
|
||||
"man":"application/x-troff-man",
|
||||
"me":"application/x-troff-me",
|
||||
"midi":"audio/midi",
|
||||
"mif":"application/x-mif",
|
||||
"mime":"www/mime",
|
||||
"mkv":" video/x-matrosk",
|
||||
"movie":"video/x-sgi-movie",
|
||||
"mp4":"video/mp4",
|
||||
"mp41":"video/mp4",
|
||||
"mp42":"video/mp4",
|
||||
"mpg":"video/mpeg",
|
||||
"mpga":"audio/mpeg",
|
||||
"ms":"application/x-troff-ms",
|
||||
"mustache":"text/plain",
|
||||
"nc":"application/x-netcdf",
|
||||
"oda":"application/oda",
|
||||
"ogm":"application/ogg",
|
||||
"pbm":"image/x-portable-bitmap",
|
||||
"pdf":"application/pdf",
|
||||
"pgm":"image/x-portable-graymap",
|
||||
"pgn":"application/x-chess-pgn",
|
||||
"pgp":"application/pgp",
|
||||
"pm":"application/x-perl",
|
||||
"png":"image/png",
|
||||
"pnm":"image/x-portable-anymap",
|
||||
"ppm":"image/x-portable-pixmap",
|
||||
"ppz":"application/vnd.ms-powerpoint",
|
||||
"pre":"application/x-freelance",
|
||||
"prt":"application/pro_eng",
|
||||
"ps":"application/postscript",
|
||||
"qt":"video/quicktime",
|
||||
"ra":"audio/x-realaudio",
|
||||
"rar":"application/x-rar-compressed",
|
||||
"ras":"image/x-cmu-raster",
|
||||
"rgb":"image/x-rgb",
|
||||
"rm":"audio/x-pn-realaudio",
|
||||
"rpm":"audio/x-pn-realaudio-plugin",
|
||||
"rtf":"text/rtf",
|
||||
"rtx":"text/richtext",
|
||||
"scm":"application/x-lotusscreencam",
|
||||
"set":"application/set",
|
||||
"sgml":"text/sgml",
|
||||
"sh":"application/x-sh",
|
||||
"shar":"application/x-shar",
|
||||
"silo":"model/mesh",
|
||||
"sit":"application/x-stuffit",
|
||||
"skt":"application/x-koan",
|
||||
"smil":"application/smil",
|
||||
"snd":"audio/basic",
|
||||
"sol":"application/solids",
|
||||
"spl":"application/x-futuresplash",
|
||||
"src":"application/x-wais-source",
|
||||
"stl":"application/SLA",
|
||||
"stp":"application/STEP",
|
||||
"sv4cpio":"application/x-sv4cpio",
|
||||
"sv4crc":"application/x-sv4crc",
|
||||
"svg":"image/svg+xml",
|
||||
"swf":"application/x-shockwave-flash",
|
||||
"tar":"application/x-tar",
|
||||
"tcl":"application/x-tcl",
|
||||
"tex":"application/x-tex",
|
||||
"texinfo":"application/x-texinfo",
|
||||
"tgz":"application/x-tar-gz",
|
||||
"tiff":"image/tiff",
|
||||
"tr":"application/x-troff",
|
||||
"tsi":"audio/TSP-audio",
|
||||
"tsp":"application/dsptype",
|
||||
"tsv":"text/tab-separated-values",
|
||||
"unv":"application/i-deas",
|
||||
"ustar":"application/x-ustar",
|
||||
"vcd":"application/x-cdlink",
|
||||
"vda":"application/vda",
|
||||
"vivo":"video/vnd.vivo",
|
||||
"vrm":"x-world/x-vrml",
|
||||
"wav":"audio/x-wav",
|
||||
"wax":"audio/x-ms-wax",
|
||||
"webm":"video/webm",
|
||||
"wma":"audio/x-ms-wma",
|
||||
"wmv":"video/x-ms-wmv",
|
||||
"wmx":"video/x-ms-wmx",
|
||||
"wrl":"model/vrml",
|
||||
"wvx":"video/x-ms-wvx",
|
||||
"xbm":"image/x-xbitmap",
|
||||
"xlw":"application/vnd.ms-excel",
|
||||
"xml":"text/xml",
|
||||
"xpm":"image/x-xpixmap",
|
||||
"xwd":"image/x-xwindowdump",
|
||||
"xyz":"chemical/x-pdb",
|
||||
"zip":"application/zip"
|
||||
};
|
||||
|
||||
exports.lookup = function(ext, defaultType) {
|
||||
defaultType = defaultType || 'application/octet-stream';
|
||||
|
||||
return (ext in exports.types)
|
||||
? exports.types[ext]
|
||||
: defaultType;
|
||||
};
|
||||
34
node_modules/request/oauth.js
generated
vendored
Normal file
34
node_modules/request/oauth.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
var crypto = require('crypto')
|
||||
, qs = require('querystring')
|
||||
;
|
||||
|
||||
function sha1 (key, body) {
|
||||
return crypto.createHmac('sha1', key).update(body).digest('base64')
|
||||
}
|
||||
|
||||
function rfc3986 (str) {
|
||||
return encodeURIComponent(str)
|
||||
.replace('!','%21')
|
||||
.replace('*','%2A')
|
||||
.replace('(','%28')
|
||||
.replace(')','%29')
|
||||
.replace("'",'%27')
|
||||
;
|
||||
}
|
||||
|
||||
function hmacsign (httpMethod, base_uri, params, consumer_secret, token_secret, body) {
|
||||
// adapted from https://dev.twitter.com/docs/auth/oauth
|
||||
var base =
|
||||
(httpMethod || 'GET') + "&" +
|
||||
encodeURIComponent( base_uri ) + "&" +
|
||||
Object.keys(params).sort().map(function (i) {
|
||||
// big WTF here with the escape + encoding but it's what twitter wants
|
||||
return escape(rfc3986(i)) + "%3D" + escape(rfc3986(params[i]))
|
||||
}).join("%26")
|
||||
var key = consumer_secret + '&'
|
||||
if (token_secret) key += token_secret
|
||||
return sha1(key, base)
|
||||
}
|
||||
|
||||
exports.hmacsign = hmacsign
|
||||
exports.rfc3986 = rfc3986
|
||||
15
node_modules/request/package.json
generated
vendored
Normal file
15
node_modules/request/package.json
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
{ "name" : "request"
|
||||
, "description" : "Simplified HTTP request client."
|
||||
, "tags" : ["http", "simple", "util", "utility"]
|
||||
, "version" : "2.9.153"
|
||||
, "author" : "Mikeal Rogers <mikeal.rogers@gmail.com>"
|
||||
, "repository" :
|
||||
{ "type" : "git"
|
||||
, "url" : "http://github.com/mikeal/request.git"
|
||||
}
|
||||
, "bugs" :
|
||||
{ "url" : "http://github.com/mikeal/request/issues" }
|
||||
, "engines" : ["node >= 0.3.6"]
|
||||
, "main" : "./main"
|
||||
, "scripts": { "test": "node tests/run.js" }
|
||||
}
|
||||
BIN
node_modules/request/tests/googledoodle.png
generated
vendored
Normal file
BIN
node_modules/request/tests/googledoodle.png
generated
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
37
node_modules/request/tests/run.js
generated
vendored
Normal file
37
node_modules/request/tests/run.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
var spawn = require('child_process').spawn
|
||||
, exitCode = 0
|
||||
;
|
||||
|
||||
var tests = [
|
||||
'test-body.js'
|
||||
, 'test-cookie.js'
|
||||
, 'test-cookiejar.js'
|
||||
, 'test-defaults.js'
|
||||
, 'test-errors.js'
|
||||
, 'test-headers.js'
|
||||
, 'test-httpModule.js'
|
||||
, 'test-https.js'
|
||||
, 'test-https-strict.js'
|
||||
, 'test-oauth.js'
|
||||
, 'test-pipes.js'
|
||||
, 'test-proxy.js'
|
||||
, 'test-qs.js'
|
||||
, 'test-redirect.js'
|
||||
, 'test-timeout.js'
|
||||
, 'test-tunnel.js'
|
||||
]
|
||||
|
||||
var next = function () {
|
||||
if (tests.length === 0) process.exit(exitCode);
|
||||
|
||||
var file = tests.shift()
|
||||
console.log(file)
|
||||
var proc = spawn('node', [ 'tests/' + file ])
|
||||
proc.stdout.pipe(process.stdout)
|
||||
proc.stderr.pipe(process.stderr)
|
||||
proc.on('exit', function (code) {
|
||||
exitCode += code || 0
|
||||
next()
|
||||
})
|
||||
}
|
||||
next()
|
||||
82
node_modules/request/tests/server.js
generated
vendored
Normal file
82
node_modules/request/tests/server.js
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
var fs = require('fs')
|
||||
, http = require('http')
|
||||
, path = require('path')
|
||||
, https = require('https')
|
||||
, events = require('events')
|
||||
, stream = require('stream')
|
||||
, assert = require('assert')
|
||||
;
|
||||
|
||||
exports.createServer = function (port) {
|
||||
port = port || 6767
|
||||
var s = http.createServer(function (req, resp) {
|
||||
s.emit(req.url, req, resp);
|
||||
})
|
||||
s.port = port
|
||||
s.url = 'http://localhost:'+port
|
||||
return s;
|
||||
}
|
||||
|
||||
exports.createSSLServer = function(port, opts) {
|
||||
port = port || 16767
|
||||
|
||||
var options = { 'key' : path.join(__dirname, 'ssl', 'test.key')
|
||||
, 'cert': path.join(__dirname, 'ssl', 'test.crt')
|
||||
}
|
||||
if (opts) {
|
||||
for (var i in opts) options[i] = opts[i]
|
||||
}
|
||||
|
||||
for (var i in options) {
|
||||
options[i] = fs.readFileSync(options[i])
|
||||
}
|
||||
|
||||
var s = https.createServer(options, function (req, resp) {
|
||||
s.emit(req.url, req, resp);
|
||||
})
|
||||
s.port = port
|
||||
s.url = 'https://localhost:'+port
|
||||
return s;
|
||||
}
|
||||
|
||||
exports.createPostStream = function (text) {
|
||||
var postStream = new stream.Stream();
|
||||
postStream.writeable = true;
|
||||
postStream.readable = true;
|
||||
setTimeout(function () {postStream.emit('data', new Buffer(text)); postStream.emit('end')}, 0);
|
||||
return postStream;
|
||||
}
|
||||
exports.createPostValidator = function (text) {
|
||||
var l = function (req, resp) {
|
||||
var r = '';
|
||||
req.on('data', function (chunk) {r += chunk})
|
||||
req.on('end', function () {
|
||||
if (r !== text) console.log(r, text);
|
||||
assert.equal(r, text)
|
||||
resp.writeHead(200, {'content-type':'text/plain'})
|
||||
resp.write('OK')
|
||||
resp.end()
|
||||
})
|
||||
}
|
||||
return l;
|
||||
}
|
||||
exports.createGetResponse = function (text, contentType) {
|
||||
var l = function (req, resp) {
|
||||
contentType = contentType || 'text/plain'
|
||||
resp.writeHead(200, {'content-type':contentType})
|
||||
resp.write(text)
|
||||
resp.end()
|
||||
}
|
||||
return l;
|
||||
}
|
||||
exports.createChunkResponse = function (chunks, contentType) {
|
||||
var l = function (req, resp) {
|
||||
contentType = contentType || 'text/plain'
|
||||
resp.writeHead(200, {'content-type':contentType})
|
||||
chunks.forEach(function (chunk) {
|
||||
resp.write(chunk)
|
||||
})
|
||||
resp.end()
|
||||
}
|
||||
return l;
|
||||
}
|
||||
77
node_modules/request/tests/squid.conf
generated
vendored
Normal file
77
node_modules/request/tests/squid.conf
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
#
|
||||
# Recommended minimum configuration:
|
||||
#
|
||||
acl manager proto cache_object
|
||||
acl localhost src 127.0.0.1/32 ::1
|
||||
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1
|
||||
|
||||
# Example rule allowing access from your local networks.
|
||||
# Adapt to list your (internal) IP networks from where browsing
|
||||
# should be allowed
|
||||
acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
|
||||
acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
|
||||
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
|
||||
acl localnet src fc00::/7 # RFC 4193 local private network range
|
||||
acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines
|
||||
|
||||
acl SSL_ports port 443
|
||||
acl Safe_ports port 80 # http
|
||||
acl Safe_ports port 21 # ftp
|
||||
acl Safe_ports port 443 # https
|
||||
acl Safe_ports port 70 # gopher
|
||||
acl Safe_ports port 210 # wais
|
||||
acl Safe_ports port 1025-65535 # unregistered ports
|
||||
acl Safe_ports port 280 # http-mgmt
|
||||
acl Safe_ports port 488 # gss-http
|
||||
acl Safe_ports port 591 # filemaker
|
||||
acl Safe_ports port 777 # multiling http
|
||||
acl CONNECT method CONNECT
|
||||
|
||||
#
|
||||
# Recommended minimum Access Permission configuration:
|
||||
#
|
||||
# Only allow cachemgr access from localhost
|
||||
http_access allow manager localhost
|
||||
http_access deny manager
|
||||
|
||||
# Deny requests to certain unsafe ports
|
||||
http_access deny !Safe_ports
|
||||
|
||||
# Deny CONNECT to other than secure SSL ports
|
||||
#http_access deny CONNECT !SSL_ports
|
||||
|
||||
# We strongly recommend the following be uncommented to protect innocent
|
||||
# web applications running on the proxy server who think the only
|
||||
# one who can access services on "localhost" is a local user
|
||||
#http_access deny to_localhost
|
||||
|
||||
#
|
||||
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
|
||||
#
|
||||
|
||||
# Example rule allowing access from your local networks.
|
||||
# Adapt localnet in the ACL section to list your (internal) IP networks
|
||||
# from where browsing should be allowed
|
||||
http_access allow localnet
|
||||
http_access allow localhost
|
||||
|
||||
# And finally deny all other access to this proxy
|
||||
http_access deny all
|
||||
|
||||
# Squid normally listens to port 3128
|
||||
http_port 3128
|
||||
|
||||
# We recommend you to use at least the following line.
|
||||
hierarchy_stoplist cgi-bin ?
|
||||
|
||||
# Uncomment and adjust the following to add a disk cache directory.
|
||||
#cache_dir ufs /usr/local/var/cache 100 16 256
|
||||
|
||||
# Leave coredumps in the first cache dir
|
||||
coredump_dir /usr/local/var/cache
|
||||
|
||||
# Add any of your own refresh_pattern entries above these.
|
||||
refresh_pattern ^ftp: 1440 20% 10080
|
||||
refresh_pattern ^gopher: 1440 0% 1440
|
||||
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
|
||||
refresh_pattern . 0 20% 4320
|
||||
20
node_modules/request/tests/ssl/ca/ca.cnf
generated
vendored
Normal file
20
node_modules/request/tests/ssl/ca/ca.cnf
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
[ req ]
|
||||
default_bits = 1024
|
||||
days = 3650
|
||||
distinguished_name = req_distinguished_name
|
||||
attributes = req_attributes
|
||||
prompt = no
|
||||
output_password = password
|
||||
|
||||
[ req_distinguished_name ]
|
||||
C = US
|
||||
ST = CA
|
||||
L = Oakland
|
||||
O = request
|
||||
OU = request Certificate Authority
|
||||
CN = requestCA
|
||||
emailAddress = mikeal@mikealrogers.com
|
||||
|
||||
[ req_attributes ]
|
||||
challengePassword = password challenge
|
||||
|
||||
0
node_modules/request/tests/ssl/ca/ca.crl
generated
vendored
Normal file
0
node_modules/request/tests/ssl/ca/ca.crl
generated
vendored
Normal file
17
node_modules/request/tests/ssl/ca/ca.crt
generated
vendored
Normal file
17
node_modules/request/tests/ssl/ca/ca.crt
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICvTCCAiYCCQDn+P/MSbDsWjANBgkqhkiG9w0BAQUFADCBojELMAkGA1UEBhMC
|
||||
VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMRAwDgYDVQQKEwdyZXF1
|
||||
ZXN0MSYwJAYDVQQLEx1yZXF1ZXN0IENlcnRpZmljYXRlIEF1dGhvcml0eTESMBAG
|
||||
A1UEAxMJcmVxdWVzdENBMSYwJAYJKoZIhvcNAQkBFhdtaWtlYWxAbWlrZWFscm9n
|
||||
ZXJzLmNvbTAeFw0xMjAzMDEyMjUwNTZaFw0yMjAyMjcyMjUwNTZaMIGiMQswCQYD
|
||||
VQQGEwJVUzELMAkGA1UECBMCQ0ExEDAOBgNVBAcTB09ha2xhbmQxEDAOBgNVBAoT
|
||||
B3JlcXVlc3QxJjAkBgNVBAsTHXJlcXVlc3QgQ2VydGlmaWNhdGUgQXV0aG9yaXR5
|
||||
MRIwEAYDVQQDEwlyZXF1ZXN0Q0ExJjAkBgkqhkiG9w0BCQEWF21pa2VhbEBtaWtl
|
||||
YWxyb2dlcnMuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC7t9pQUAK4
|
||||
5XJYTI6NrF0n3G2HZsfN+rPYSVzzL8SuVyb1tHXos+vbPm3NKI4E8X1yVAXU8CjJ
|
||||
5SqXnp4DAypAhaseho81cbhk7LXUhFz78OvAa+OD+xTAEAnNQ8tGUr4VGyplEjfD
|
||||
xsBVuqV2j8GPNTftr+drOCFlqfAgMrBn4wIDAQABMA0GCSqGSIb3DQEBBQUAA4GB
|
||||
ADVdTlVAL45R+PACNS7Gs4o81CwSclukBu4FJbxrkd4xGQmurgfRrYYKjtqiopQm
|
||||
D7ysRamS3HMN9/VKq2T7r3z1PMHPAy7zM4uoXbbaTKwlnX4j/8pGPn8Ca3qHXYlo
|
||||
88L/OOPc6Di7i7qckS3HFbXQCTiULtxWmy97oEuTwrAj
|
||||
-----END CERTIFICATE-----
|
||||
13
node_modules/request/tests/ssl/ca/ca.csr
generated
vendored
Normal file
13
node_modules/request/tests/ssl/ca/ca.csr
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
-----BEGIN CERTIFICATE REQUEST-----
|
||||
MIICBjCCAW8CAQAwgaIxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEQMA4GA1UE
|
||||
BxMHT2FrbGFuZDEQMA4GA1UEChMHcmVxdWVzdDEmMCQGA1UECxMdcmVxdWVzdCBD
|
||||
ZXJ0aWZpY2F0ZSBBdXRob3JpdHkxEjAQBgNVBAMTCXJlcXVlc3RDQTEmMCQGCSqG
|
||||
SIb3DQEJARYXbWlrZWFsQG1pa2VhbHJvZ2Vycy5jb20wgZ8wDQYJKoZIhvcNAQEB
|
||||
BQADgY0AMIGJAoGBALu32lBQArjlclhMjo2sXSfcbYdmx836s9hJXPMvxK5XJvW0
|
||||
deiz69s+bc0ojgTxfXJUBdTwKMnlKpeengMDKkCFqx6GjzVxuGTstdSEXPvw68Br
|
||||
44P7FMAQCc1Dy0ZSvhUbKmUSN8PGwFW6pXaPwY81N+2v52s4IWWp8CAysGfjAgMB
|
||||
AAGgIzAhBgkqhkiG9w0BCQcxFBMScGFzc3dvcmQgY2hhbGxlbmdlMA0GCSqGSIb3
|
||||
DQEBBQUAA4GBAGJO7grHeVHXetjHEK8urIxdnvfB2qeZeObz4GPKIkqUurjr0rfj
|
||||
bA3EK1kDMR5aeQWR8RunixdM16Q6Ry0lEdLVWkdSwRN9dmirIHT9cypqnD/FYOia
|
||||
SdezZ0lUzXgmJIwRYRwB1KSMMocIf52ll/xC2bEGg7/ZAEuAyAgcZV3X
|
||||
-----END CERTIFICATE REQUEST-----
|
||||
18
node_modules/request/tests/ssl/ca/ca.key
generated
vendored
Normal file
18
node_modules/request/tests/ssl/ca/ca.key
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,C8B5887048377F02
|
||||
|
||||
nyD5ZH0Wup2uWsDvurq5mKDaDrf8lvNn9w0SH/ZkVnfR1/bkwqrFriqJWvZNUG+q
|
||||
nS0iBYczsWLJnbub9a1zLOTENWUKVD5uqbC3aGHhnoUTNSa27DONgP8gHOn6JgR+
|
||||
GAKo01HCSTiVT4LjkwN337QKHnMP2fTzg+IoC/CigvMcq09hRLwU1/guq0GJKGwH
|
||||
gTxYNuYmQC4Tjh8vdS4liF+Ve/P3qPR2CehZrIOkDT8PHJBGQJRo4xGUIB7Tpk38
|
||||
VCk+UZ0JCS2coY8VkY/9tqFJp/ZnnQQVmaNbdRqg7ECKL+bXnNo7yjzmazPZmPe3
|
||||
/ShbE0+CTt7LrjCaQAxWbeDzqfo1lQfgN1LulTm8MCXpQaJpv7v1VhIhQ7afjMYb
|
||||
4thW/ypHPiYS2YJCAkAVlua9Oxzzh1qJoh8Df19iHtpd79Q77X/qf+1JvITlMu0U
|
||||
gi7yEatmQcmYNws1mtTC1q2DXrO90c+NZ0LK/Alse6NRL/xiUdjug2iHeTf/idOR
|
||||
Gg/5dSZbnnlj1E5zjSMDkzg6EHAFmHV4jYGSAFLEQgp4V3ZhMVoWZrvvSHgKV/Qh
|
||||
FqrAK4INr1G2+/QTd09AIRzfy3/j6yD4A9iNaOsEf9Ua7Qh6RcALRCAZTWR5QtEf
|
||||
dX+iSNJ4E85qXs0PqwkMDkoaxIJ+tmIRJY7y8oeylV8cfGAi8Soubt/i3SlR8IHC
|
||||
uDMas/2OnwafK3N7ODeE1i7r7wkzQkSHaEz0TrF8XRnP25jAICCSLiMdAAjKfxVb
|
||||
EvzsFSuAy3Jt6bU3hSLY9o4YVYKE+68ITMv9yNjvTsEiW+T+IbN34w==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
1
node_modules/request/tests/ssl/ca/ca.srl
generated
vendored
Normal file
1
node_modules/request/tests/ssl/ca/ca.srl
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
ADF62016AA40C9C3
|
||||
19
node_modules/request/tests/ssl/ca/server.cnf
generated
vendored
Normal file
19
node_modules/request/tests/ssl/ca/server.cnf
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
[ req ]
|
||||
default_bits = 1024
|
||||
days = 3650
|
||||
distinguished_name = req_distinguished_name
|
||||
attributes = req_attributes
|
||||
prompt = no
|
||||
|
||||
[ req_distinguished_name ]
|
||||
C = US
|
||||
ST = CA
|
||||
L = Oakland
|
||||
O = request
|
||||
OU = testing
|
||||
CN = testing.request.mikealrogers.com
|
||||
emailAddress = mikeal@mikealrogers.com
|
||||
|
||||
[ req_attributes ]
|
||||
challengePassword = password challenge
|
||||
|
||||
16
node_modules/request/tests/ssl/ca/server.crt
generated
vendored
Normal file
16
node_modules/request/tests/ssl/ca/server.crt
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICejCCAeMCCQCt9iAWqkDJwzANBgkqhkiG9w0BAQUFADCBojELMAkGA1UEBhMC
|
||||
VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMRAwDgYDVQQKEwdyZXF1
|
||||
ZXN0MSYwJAYDVQQLEx1yZXF1ZXN0IENlcnRpZmljYXRlIEF1dGhvcml0eTESMBAG
|
||||
A1UEAxMJcmVxdWVzdENBMSYwJAYJKoZIhvcNAQkBFhdtaWtlYWxAbWlrZWFscm9n
|
||||
ZXJzLmNvbTAeFw0xMjAzMDEyMjUwNTZaFw0yMjAyMjcyMjUwNTZaMIGjMQswCQYD
|
||||
VQQGEwJVUzELMAkGA1UECBMCQ0ExEDAOBgNVBAcTB09ha2xhbmQxEDAOBgNVBAoT
|
||||
B3JlcXVlc3QxEDAOBgNVBAsTB3Rlc3RpbmcxKTAnBgNVBAMTIHRlc3RpbmcucmVx
|
||||
dWVzdC5taWtlYWxyb2dlcnMuY29tMSYwJAYJKoZIhvcNAQkBFhdtaWtlYWxAbWlr
|
||||
ZWFscm9nZXJzLmNvbTBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQDgVl0jMumvOpmM
|
||||
20W5v9yhGgZj8hPhEQF/N7yCBVBn/rWGYm70IHC8T/pR5c0LkWc5gdnCJEvKWQjh
|
||||
DBKxZD8FAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEABShRkNgFbgs4vUWW9R9deNJj
|
||||
7HJoiTmvkmoOC7QzcYkjdgHbOxsSq3rBnwxsVjY9PAtPwBn0GRspOeG7KzKRgySB
|
||||
kb22LyrCFKbEOfKO/+CJc80ioK9zEPVjGsFMyAB+ftYRqM+s/4cQlTg/m89l01wC
|
||||
yapjN3RxZbInGhWR+jA=
|
||||
-----END CERTIFICATE-----
|
||||
11
node_modules/request/tests/ssl/ca/server.csr
generated
vendored
Normal file
11
node_modules/request/tests/ssl/ca/server.csr
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
-----BEGIN CERTIFICATE REQUEST-----
|
||||
MIIBgjCCASwCAQAwgaMxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEQMA4GA1UE
|
||||
BxMHT2FrbGFuZDEQMA4GA1UEChMHcmVxdWVzdDEQMA4GA1UECxMHdGVzdGluZzEp
|
||||
MCcGA1UEAxMgdGVzdGluZy5yZXF1ZXN0Lm1pa2VhbHJvZ2Vycy5jb20xJjAkBgkq
|
||||
hkiG9w0BCQEWF21pa2VhbEBtaWtlYWxyb2dlcnMuY29tMFwwDQYJKoZIhvcNAQEB
|
||||
BQADSwAwSAJBAOBWXSMy6a86mYzbRbm/3KEaBmPyE+ERAX83vIIFUGf+tYZibvQg
|
||||
cLxP+lHlzQuRZzmB2cIkS8pZCOEMErFkPwUCAwEAAaAjMCEGCSqGSIb3DQEJBzEU
|
||||
ExJwYXNzd29yZCBjaGFsbGVuZ2UwDQYJKoZIhvcNAQEFBQADQQBD3E5WekQzCEJw
|
||||
7yOcqvtPYIxGaX8gRKkYfLPoj3pm3GF5SGqtJKhylKfi89szHXgktnQgzff9FN+A
|
||||
HidVJ/3u
|
||||
-----END CERTIFICATE REQUEST-----
|
||||
28
node_modules/request/tests/ssl/ca/server.js
generated
vendored
Normal file
28
node_modules/request/tests/ssl/ca/server.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
var fs = require("fs")
|
||||
var https = require("https")
|
||||
var options = { key: fs.readFileSync("./server.key")
|
||||
, cert: fs.readFileSync("./server.crt") }
|
||||
|
||||
var server = https.createServer(options, function (req, res) {
|
||||
res.writeHead(200)
|
||||
res.end()
|
||||
server.close()
|
||||
})
|
||||
server.listen(1337)
|
||||
|
||||
var ca = fs.readFileSync("./ca.crt")
|
||||
var agent = new https.Agent({ host: "localhost", port: 1337, ca: ca })
|
||||
|
||||
https.request({ host: "localhost"
|
||||
, method: "HEAD"
|
||||
, port: 1337
|
||||
, headers: { host: "testing.request.mikealrogers.com" }
|
||||
, agent: agent
|
||||
, ca: [ ca ]
|
||||
, path: "/" }, function (res) {
|
||||
if (res.client.authorized) {
|
||||
console.log("node test: OK")
|
||||
} else {
|
||||
throw new Error(res.client.authorizationError)
|
||||
}
|
||||
}).end()
|
||||
9
node_modules/request/tests/ssl/ca/server.key
generated
vendored
Normal file
9
node_modules/request/tests/ssl/ca/server.key
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIBOwIBAAJBAOBWXSMy6a86mYzbRbm/3KEaBmPyE+ERAX83vIIFUGf+tYZibvQg
|
||||
cLxP+lHlzQuRZzmB2cIkS8pZCOEMErFkPwUCAwEAAQJAK+r8ZM2sze8s7FRo/ApB
|
||||
iRBtO9fCaIdJwbwJnXKo4RKwZDt1l2mm+fzZ+/QaQNjY1oTROkIIXmnwRvZWfYlW
|
||||
gQIhAPKYsG+YSBN9o8Sdp1DMyZ/rUifKX3OE6q9tINkgajDVAiEA7Ltqh01+cnt0
|
||||
JEnud/8HHcuehUBLMofeg0G+gCnSbXECIQCqDvkXsWNNLnS/3lgsnvH0Baz4sbeJ
|
||||
rjIpuVEeg8eM5QIgbu0+9JmOV6ybdmmiMV4yAncoF35R/iKGVHDZCAsQzDECIQDZ
|
||||
0jGz22tlo5YMcYSqrdD3U4sds1pwiAaWFRbCunoUJw==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
16
node_modules/request/tests/ssl/npm-ca.crt
generated
vendored
Normal file
16
node_modules/request/tests/ssl/npm-ca.crt
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIChzCCAfACCQDauvz/KHp8ejANBgkqhkiG9w0BAQUFADCBhzELMAkGA1UEBhMC
|
||||
VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMQwwCgYDVQQKEwNucG0x
|
||||
IjAgBgNVBAsTGW5wbSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkxDjAMBgNVBAMTBW5w
|
||||
bUNBMRcwFQYJKoZIhvcNAQkBFghpQGl6cy5tZTAeFw0xMTA5MDUwMTQ3MTdaFw0y
|
||||
MTA5MDIwMTQ3MTdaMIGHMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExEDAOBgNV
|
||||
BAcTB09ha2xhbmQxDDAKBgNVBAoTA25wbTEiMCAGA1UECxMZbnBtIENlcnRpZmlj
|
||||
YXRlIEF1dGhvcml0eTEOMAwGA1UEAxMFbnBtQ0ExFzAVBgkqhkiG9w0BCQEWCGlA
|
||||
aXpzLm1lMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDLI4tIqPpRW+ACw9GE
|
||||
OgBlJZwK5f8nnKCLK629Pv5yJpQKs3DENExAyOgDcyaF0HD0zk8zTp+ZsLaNdKOz
|
||||
Gn2U181KGprGKAXP6DU6ByOJDWmTlY6+Ad1laYT0m64fERSpHw/hjD3D+iX4aMOl
|
||||
y0HdbT5m1ZGh6SJz3ZqxavhHLQIDAQABMA0GCSqGSIb3DQEBBQUAA4GBAC4ySDbC
|
||||
l7W1WpLmtLGEQ/yuMLUf6Jy/vr+CRp4h+UzL+IQpCv8FfxsYE7dhf/bmWTEupBkv
|
||||
yNL18lipt2jSvR3v6oAHAReotvdjqhxddpe5Holns6EQd1/xEZ7sB1YhQKJtvUrl
|
||||
ZNufy1Jf1r0ldEGeA+0ISck7s+xSh9rQD2Op
|
||||
-----END CERTIFICATE-----
|
||||
15
node_modules/request/tests/ssl/test.crt
generated
vendored
Normal file
15
node_modules/request/tests/ssl/test.crt
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICQzCCAawCCQCO/XWtRFck1jANBgkqhkiG9w0BAQUFADBmMQswCQYDVQQGEwJU
|
||||
SDEQMA4GA1UECBMHQmFuZ2tvazEOMAwGA1UEBxMFU2lsb20xGzAZBgNVBAoTElRo
|
||||
ZSBSZXF1ZXN0IE1vZHVsZTEYMBYGA1UEAxMPcmVxdWVzdC5leGFtcGxlMB4XDTEx
|
||||
MTIwMzAyMjkyM1oXDTIxMTEzMDAyMjkyM1owZjELMAkGA1UEBhMCVEgxEDAOBgNV
|
||||
BAgTB0Jhbmdrb2sxDjAMBgNVBAcTBVNpbG9tMRswGQYDVQQKExJUaGUgUmVxdWVz
|
||||
dCBNb2R1bGUxGDAWBgNVBAMTD3JlcXVlc3QuZXhhbXBsZTCBnzANBgkqhkiG9w0B
|
||||
AQEFAAOBjQAwgYkCgYEAwmctddZqlA48+NXs0yOy92DijcQV1jf87zMiYAIlNUto
|
||||
wghVbTWgJU5r0pdKrD16AptnWJTzKanhItEX8XCCPgsNkq1afgTtJP7rNkwu3xcj
|
||||
eIMkhJg/ay4ZnkbnhYdsii5VTU5prix6AqWRAhbkBgoA+iVyHyof8wvZyKBoFTMC
|
||||
AwEAATANBgkqhkiG9w0BAQUFAAOBgQB6BybMJbpeiABgihDfEVBcAjDoQ8gUMgwV
|
||||
l4NulugfKTDmArqnR9aPd4ET5jX5dkMP4bwCHYsvrcYDeWEQy7x5WWuylOdKhua4
|
||||
L4cEi2uDCjqEErIG3cc1MCOk6Cl6Ld6tkIzQSf953qfdEACRytOeUqLNQcrXrqeE
|
||||
c7U8F6MWLQ==
|
||||
-----END CERTIFICATE-----
|
||||
15
node_modules/request/tests/ssl/test.key
generated
vendored
Normal file
15
node_modules/request/tests/ssl/test.key
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIICXgIBAAKBgQDCZy111mqUDjz41ezTI7L3YOKNxBXWN/zvMyJgAiU1S2jCCFVt
|
||||
NaAlTmvSl0qsPXoCm2dYlPMpqeEi0RfxcII+Cw2SrVp+BO0k/us2TC7fFyN4gySE
|
||||
mD9rLhmeRueFh2yKLlVNTmmuLHoCpZECFuQGCgD6JXIfKh/zC9nIoGgVMwIDAQAB
|
||||
AoGBALXFwfUf8vHTSmGlrdZS2AGFPvEtuvldyoxi9K5u8xmdFCvxnOcLsF2RsTHt
|
||||
Mu5QYWhUpNJoG+IGLTPf7RJdj/kNtEs7xXqWy4jR36kt5z5MJzqiK+QIgiO9UFWZ
|
||||
fjUb6oeDnTIJA9YFBdYi97MDuL89iU/UK3LkJN3hd4rciSbpAkEA+MCkowF5kSFb
|
||||
rkOTBYBXZfiAG78itDXN6DXmqb9XYY+YBh3BiQM28oxCeQYyFy6pk/nstnd4TXk6
|
||||
V/ryA2g5NwJBAMgRKTY9KvxJWbESeMEFe2iBIV0c26/72Amgi7ZKUCLukLfD4tLF
|
||||
+WSZdmTbbqI1079YtwaiOVfiLm45Q/3B0eUCQAaQ/0eWSGE+Yi8tdXoVszjr4GXb
|
||||
G81qBi91DMu6U1It+jNfIba+MPsiHLcZJMVb4/oWBNukN7bD1nhwFWdlnu0CQQCf
|
||||
Is9WHkdvz2RxbZDxb8verz/7kXXJQJhx5+rZf7jIYFxqX3yvTNv3wf2jcctJaWlZ
|
||||
fVZwB193YSivcgt778xlAkEAprYUz3jczjF5r2hrgbizPzPDR94tM5BTO3ki2v3w
|
||||
kbf+j2g7FNAx6kZiVN8XwfLc8xEeUGiPKwtq3ddPDFh17w==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
95
node_modules/request/tests/test-body.js
generated
vendored
Normal file
95
node_modules/request/tests/test-body.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
var server = require('./server')
|
||||
, events = require('events')
|
||||
, stream = require('stream')
|
||||
, assert = require('assert')
|
||||
, request = require('../main.js')
|
||||
;
|
||||
|
||||
var s = server.createServer();
|
||||
|
||||
var tests =
|
||||
{ testGet :
|
||||
{ resp : server.createGetResponse("TESTING!")
|
||||
, expectBody: "TESTING!"
|
||||
}
|
||||
, testGetChunkBreak :
|
||||
{ resp : server.createChunkResponse(
|
||||
[ new Buffer([239])
|
||||
, new Buffer([163])
|
||||
, new Buffer([191])
|
||||
, new Buffer([206])
|
||||
, new Buffer([169])
|
||||
, new Buffer([226])
|
||||
, new Buffer([152])
|
||||
, new Buffer([131])
|
||||
])
|
||||
, expectBody: "Ω☃"
|
||||
}
|
||||
, testGetBuffer :
|
||||
{ resp : server.createGetResponse(new Buffer("TESTING!"))
|
||||
, encoding: null
|
||||
, expectBody: new Buffer("TESTING!")
|
||||
}
|
||||
, testGetJSON :
|
||||
{ resp : server.createGetResponse('{"test":true}', 'application/json')
|
||||
, json : true
|
||||
, expectBody: {"test":true}
|
||||
}
|
||||
, testPutString :
|
||||
{ resp : server.createPostValidator("PUTTINGDATA")
|
||||
, method : "PUT"
|
||||
, body : "PUTTINGDATA"
|
||||
}
|
||||
, testPutBuffer :
|
||||
{ resp : server.createPostValidator("PUTTINGDATA")
|
||||
, method : "PUT"
|
||||
, body : new Buffer("PUTTINGDATA")
|
||||
}
|
||||
, testPutJSON :
|
||||
{ resp : server.createPostValidator(JSON.stringify({foo: 'bar'}))
|
||||
, method: "PUT"
|
||||
, json: {foo: 'bar'}
|
||||
}
|
||||
, testPutMultipart :
|
||||
{ resp: server.createPostValidator(
|
||||
'--frontier\r\n' +
|
||||
'content-type: text/html\r\n' +
|
||||
'\r\n' +
|
||||
'<html><body>Oh hi.</body></html>' +
|
||||
'\r\n--frontier\r\n\r\n' +
|
||||
'Oh hi.' +
|
||||
'\r\n--frontier--'
|
||||
)
|
||||
, method: "PUT"
|
||||
, multipart:
|
||||
[ {'content-type': 'text/html', 'body': '<html><body>Oh hi.</body></html>'}
|
||||
, {'body': 'Oh hi.'}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
s.listen(s.port, function () {
|
||||
|
||||
var counter = 0
|
||||
|
||||
for (i in tests) {
|
||||
(function () {
|
||||
var test = tests[i]
|
||||
s.on('/'+i, test.resp)
|
||||
test.uri = s.url + '/' + i
|
||||
request(test, function (err, resp, body) {
|
||||
if (err) throw err
|
||||
if (test.expectBody) {
|
||||
assert.deepEqual(test.expectBody, body)
|
||||
}
|
||||
counter = counter - 1;
|
||||
if (counter === 0) {
|
||||
console.log(Object.keys(tests).length+" tests passed.")
|
||||
s.close()
|
||||
}
|
||||
})
|
||||
counter++
|
||||
})()
|
||||
}
|
||||
})
|
||||
|
||||
29
node_modules/request/tests/test-cookie.js
generated
vendored
Normal file
29
node_modules/request/tests/test-cookie.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
var Cookie = require('../vendor/cookie')
|
||||
, assert = require('assert');
|
||||
|
||||
var str = 'sid="s543qactge.wKE61E01Bs%2BKhzmxrwrnug="; path=/; httpOnly; expires=Sat, 04 Dec 2010 23:27:28 GMT';
|
||||
var cookie = new Cookie(str);
|
||||
|
||||
// test .toString()
|
||||
assert.equal(cookie.toString(), str);
|
||||
|
||||
// test .path
|
||||
assert.equal(cookie.path, '/');
|
||||
|
||||
// test .httpOnly
|
||||
assert.equal(cookie.httpOnly, true);
|
||||
|
||||
// test .name
|
||||
assert.equal(cookie.name, 'sid');
|
||||
|
||||
// test .value
|
||||
assert.equal(cookie.value, '"s543qactge.wKE61E01Bs%2BKhzmxrwrnug="');
|
||||
|
||||
// test .expires
|
||||
assert.equal(cookie.expires instanceof Date, true);
|
||||
|
||||
// test .path default
|
||||
var cookie = new Cookie('foo=bar', { url: 'http://foo.com/bar' });
|
||||
assert.equal(cookie.path, '/bar');
|
||||
|
||||
console.log('All tests passed');
|
||||
90
node_modules/request/tests/test-cookiejar.js
generated
vendored
Normal file
90
node_modules/request/tests/test-cookiejar.js
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
var Cookie = require('../vendor/cookie')
|
||||
, Jar = require('../vendor/cookie/jar')
|
||||
, assert = require('assert');
|
||||
|
||||
function expires(ms) {
|
||||
return new Date(Date.now() + ms).toUTCString();
|
||||
}
|
||||
|
||||
// test .get() expiration
|
||||
(function() {
|
||||
var jar = new Jar;
|
||||
var cookie = new Cookie('sid=1234; path=/; expires=' + expires(1000));
|
||||
jar.add(cookie);
|
||||
setTimeout(function(){
|
||||
var cookies = jar.get({ url: 'http://foo.com/foo' });
|
||||
assert.equal(cookies.length, 1);
|
||||
assert.equal(cookies[0], cookie);
|
||||
setTimeout(function(){
|
||||
var cookies = jar.get({ url: 'http://foo.com/foo' });
|
||||
assert.equal(cookies.length, 0);
|
||||
}, 1000);
|
||||
}, 5);
|
||||
})();
|
||||
|
||||
// test .get() path support
|
||||
(function() {
|
||||
var jar = new Jar;
|
||||
var a = new Cookie('sid=1234; path=/');
|
||||
var b = new Cookie('sid=1111; path=/foo/bar');
|
||||
var c = new Cookie('sid=2222; path=/');
|
||||
jar.add(a);
|
||||
jar.add(b);
|
||||
jar.add(c);
|
||||
|
||||
// should remove the duplicates
|
||||
assert.equal(jar.cookies.length, 2);
|
||||
|
||||
// same name, same path, latter prevails
|
||||
var cookies = jar.get({ url: 'http://foo.com/' });
|
||||
assert.equal(cookies.length, 1);
|
||||
assert.equal(cookies[0], c);
|
||||
|
||||
// same name, diff path, path specifity prevails, latter prevails
|
||||
var cookies = jar.get({ url: 'http://foo.com/foo/bar' });
|
||||
assert.equal(cookies.length, 1);
|
||||
assert.equal(cookies[0], b);
|
||||
|
||||
var jar = new Jar;
|
||||
var a = new Cookie('sid=1111; path=/foo/bar');
|
||||
var b = new Cookie('sid=1234; path=/');
|
||||
jar.add(a);
|
||||
jar.add(b);
|
||||
|
||||
var cookies = jar.get({ url: 'http://foo.com/foo/bar' });
|
||||
assert.equal(cookies.length, 1);
|
||||
assert.equal(cookies[0], a);
|
||||
|
||||
var cookies = jar.get({ url: 'http://foo.com/' });
|
||||
assert.equal(cookies.length, 1);
|
||||
assert.equal(cookies[0], b);
|
||||
|
||||
var jar = new Jar;
|
||||
var a = new Cookie('sid=1111; path=/foo/bar');
|
||||
var b = new Cookie('sid=3333; path=/foo/bar');
|
||||
var c = new Cookie('pid=3333; path=/foo/bar');
|
||||
var d = new Cookie('sid=2222; path=/foo/');
|
||||
var e = new Cookie('sid=1234; path=/');
|
||||
jar.add(a);
|
||||
jar.add(b);
|
||||
jar.add(c);
|
||||
jar.add(d);
|
||||
jar.add(e);
|
||||
|
||||
var cookies = jar.get({ url: 'http://foo.com/foo/bar' });
|
||||
assert.equal(cookies.length, 2);
|
||||
assert.equal(cookies[0], b);
|
||||
assert.equal(cookies[1], c);
|
||||
|
||||
var cookies = jar.get({ url: 'http://foo.com/foo/' });
|
||||
assert.equal(cookies.length, 1);
|
||||
assert.equal(cookies[0], d);
|
||||
|
||||
var cookies = jar.get({ url: 'http://foo.com/' });
|
||||
assert.equal(cookies.length, 1);
|
||||
assert.equal(cookies[0], e);
|
||||
})();
|
||||
|
||||
setTimeout(function() {
|
||||
console.log('All tests passed');
|
||||
}, 1200);
|
||||
68
node_modules/request/tests/test-defaults.js
generated
vendored
Normal file
68
node_modules/request/tests/test-defaults.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
var server = require('./server')
|
||||
, assert = require('assert')
|
||||
, request = require('../main.js')
|
||||
;
|
||||
|
||||
var s = server.createServer();
|
||||
|
||||
s.listen(s.port, function () {
|
||||
var counter = 0;
|
||||
s.on('/get', function (req, resp) {
|
||||
assert.equal(req.headers.foo, 'bar');
|
||||
assert.equal(req.method, 'GET')
|
||||
resp.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
resp.end('TESTING!');
|
||||
});
|
||||
|
||||
// test get(string, function)
|
||||
request.defaults({headers:{foo:"bar"}})(s.url + '/get', function (e, r, b){
|
||||
if (e) throw e;
|
||||
assert.deepEqual("TESTING!", b);
|
||||
counter += 1;
|
||||
});
|
||||
|
||||
s.on('/post', function (req, resp) {
|
||||
assert.equal(req.headers.foo, 'bar');
|
||||
assert.equal(req.headers['content-type'], 'application/json');
|
||||
assert.equal(req.method, 'POST')
|
||||
resp.writeHead(200, {'Content-Type': 'application/json'});
|
||||
resp.end(JSON.stringify({foo:'bar'}));
|
||||
});
|
||||
|
||||
// test post(string, object, function)
|
||||
request.defaults({headers:{foo:"bar"}}).post(s.url + '/post', {json: true}, function (e, r, b){
|
||||
if (e) throw e;
|
||||
assert.deepEqual('bar', b.foo);
|
||||
counter += 1;
|
||||
});
|
||||
|
||||
s.on('/del', function (req, resp) {
|
||||
assert.equal(req.headers.foo, 'bar');
|
||||
assert.equal(req.method, 'DELETE')
|
||||
resp.writeHead(200, {'Content-Type': 'application/json'});
|
||||
resp.end(JSON.stringify({foo:'bar'}));
|
||||
});
|
||||
|
||||
// test .del(string, function)
|
||||
request.defaults({headers:{foo:"bar"}, json:true}).del(s.url + '/del', function (e, r, b){
|
||||
if (e) throw e;
|
||||
assert.deepEqual('bar', b.foo);
|
||||
counter += 1;
|
||||
});
|
||||
|
||||
s.on('/head', function (req, resp) {
|
||||
assert.equal(req.headers.foo, 'bar');
|
||||
assert.equal(req.method, 'HEAD')
|
||||
resp.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
resp.end();
|
||||
});
|
||||
|
||||
// test head.(object, function)
|
||||
request.defaults({headers:{foo:"bar"}}).head({uri: s.url + '/head'}, function (e, r, b){
|
||||
if (e) throw e;
|
||||
counter += 1;
|
||||
console.log(counter.toString() + " tests passed.")
|
||||
s.close()
|
||||
});
|
||||
|
||||
})
|
||||
37
node_modules/request/tests/test-errors.js
generated
vendored
Normal file
37
node_modules/request/tests/test-errors.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
var server = require('./server')
|
||||
, events = require('events')
|
||||
, assert = require('assert')
|
||||
, request = require('../main.js')
|
||||
;
|
||||
|
||||
var local = 'http://localhost:8888/asdf'
|
||||
|
||||
try {
|
||||
request({uri:local, body:{}})
|
||||
assert.fail("Should have throw")
|
||||
} catch(e) {
|
||||
assert.equal(e.message, 'Argument error, options.body.')
|
||||
}
|
||||
|
||||
try {
|
||||
request({uri:local, multipart: 'foo'})
|
||||
assert.fail("Should have throw")
|
||||
} catch(e) {
|
||||
assert.equal(e.message, 'Argument error, options.multipart.')
|
||||
}
|
||||
|
||||
try {
|
||||
request({uri:local, multipart: [{}]})
|
||||
assert.fail("Should have throw")
|
||||
} catch(e) {
|
||||
assert.equal(e.message, 'Body attribute missing in multipart.')
|
||||
}
|
||||
|
||||
try {
|
||||
request(local, {multipart: [{}]})
|
||||
assert.fail("Should have throw")
|
||||
} catch(e) {
|
||||
assert.equal(e.message, 'Body attribute missing in multipart.')
|
||||
}
|
||||
|
||||
console.log("All tests passed.")
|
||||
52
node_modules/request/tests/test-headers.js
generated
vendored
Normal file
52
node_modules/request/tests/test-headers.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
var server = require('./server')
|
||||
, assert = require('assert')
|
||||
, request = require('../main.js')
|
||||
, Cookie = require('../vendor/cookie')
|
||||
, Jar = require('../vendor/cookie/jar')
|
||||
, s = server.createServer()
|
||||
|
||||
s.listen(s.port, function () {
|
||||
var serverUri = 'http://localhost:' + s.port
|
||||
, numTests = 0
|
||||
, numOutstandingTests = 0
|
||||
|
||||
function createTest(requestObj, serverAssertFn) {
|
||||
var testNumber = numTests;
|
||||
numTests += 1;
|
||||
numOutstandingTests += 1;
|
||||
s.on('/' + testNumber, function (req, res) {
|
||||
serverAssertFn(req, res);
|
||||
res.writeHead(200);
|
||||
res.end();
|
||||
});
|
||||
requestObj.url = serverUri + '/' + testNumber
|
||||
request(requestObj, function (err, res, body) {
|
||||
assert.ok(!err)
|
||||
assert.equal(res.statusCode, 200)
|
||||
numOutstandingTests -= 1
|
||||
if (numOutstandingTests === 0) {
|
||||
console.log(numTests + ' tests passed.')
|
||||
s.close()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Issue #125: headers.cookie shouldn't be replaced when a cookie jar isn't specified
|
||||
createTest({headers: {cookie: 'foo=bar'}}, function (req, res) {
|
||||
assert.ok(req.headers.cookie)
|
||||
assert.equal(req.headers.cookie, 'foo=bar')
|
||||
})
|
||||
|
||||
// Issue #125: headers.cookie + cookie jar
|
||||
var jar = new Jar()
|
||||
jar.add(new Cookie('quux=baz'));
|
||||
createTest({jar: jar, headers: {cookie: 'foo=bar'}}, function (req, res) {
|
||||
assert.ok(req.headers.cookie)
|
||||
assert.equal(req.headers.cookie, 'foo=bar; quux=baz')
|
||||
})
|
||||
|
||||
// There should be no cookie header when neither headers.cookie nor a cookie jar is specified
|
||||
createTest({}, function (req, res) {
|
||||
assert.ok(!req.headers.cookie)
|
||||
})
|
||||
})
|
||||
94
node_modules/request/tests/test-httpModule.js
generated
vendored
Normal file
94
node_modules/request/tests/test-httpModule.js
generated
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
var http = require('http')
|
||||
, https = require('https')
|
||||
, server = require('./server')
|
||||
, assert = require('assert')
|
||||
, request = require('../main.js')
|
||||
|
||||
|
||||
var faux_requests_made = {'http':0, 'https':0}
|
||||
function wrap_request(name, module) {
|
||||
// Just like the http or https module, but note when a request is made.
|
||||
var wrapped = {}
|
||||
Object.keys(module).forEach(function(key) {
|
||||
var value = module[key];
|
||||
|
||||
if(key != 'request')
|
||||
wrapped[key] = value;
|
||||
else
|
||||
wrapped[key] = function(options, callback) {
|
||||
faux_requests_made[name] += 1
|
||||
return value.apply(this, arguments)
|
||||
}
|
||||
})
|
||||
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
|
||||
var faux_http = wrap_request('http', http)
|
||||
, faux_https = wrap_request('https', https)
|
||||
, plain_server = server.createServer()
|
||||
, https_server = server.createSSLServer()
|
||||
|
||||
|
||||
plain_server.listen(plain_server.port, function() {
|
||||
plain_server.on('/plain', function (req, res) {
|
||||
res.writeHead(200)
|
||||
res.end('plain')
|
||||
})
|
||||
plain_server.on('/to_https', function (req, res) {
|
||||
res.writeHead(301, {'location':'https://localhost:'+https_server.port + '/https'})
|
||||
res.end()
|
||||
})
|
||||
|
||||
https_server.listen(https_server.port, function() {
|
||||
https_server.on('/https', function (req, res) {
|
||||
res.writeHead(200)
|
||||
res.end('https')
|
||||
})
|
||||
https_server.on('/to_plain', function (req, res) {
|
||||
res.writeHead(302, {'location':'http://localhost:'+plain_server.port + '/plain'})
|
||||
res.end()
|
||||
})
|
||||
|
||||
run_tests()
|
||||
run_tests({})
|
||||
run_tests({'http:':faux_http})
|
||||
run_tests({'https:':faux_https})
|
||||
run_tests({'http:':faux_http, 'https:':faux_https})
|
||||
})
|
||||
})
|
||||
|
||||
function run_tests(httpModules) {
|
||||
var to_https = 'http://localhost:'+plain_server.port+'/to_https'
|
||||
var to_plain = 'https://localhost:'+https_server.port+'/to_plain'
|
||||
|
||||
request(to_https, {'httpModules':httpModules}, function (er, res, body) {
|
||||
assert.ok(!er, 'Bounce to SSL worked')
|
||||
assert.equal(body, 'https', 'Received HTTPS server body')
|
||||
done()
|
||||
})
|
||||
|
||||
request(to_plain, {'httpModules':httpModules}, function (er, res, body) {
|
||||
assert.ok(!er, 'Bounce to plaintext server worked')
|
||||
assert.equal(body, 'plain', 'Received HTTPS server body')
|
||||
done()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
var passed = 0;
|
||||
function done() {
|
||||
passed += 1
|
||||
var expected = 10
|
||||
|
||||
if(passed == expected) {
|
||||
plain_server.close()
|
||||
https_server.close()
|
||||
|
||||
assert.equal(faux_requests_made.http, 4, 'Wrapped http module called appropriately')
|
||||
assert.equal(faux_requests_made.https, 4, 'Wrapped https module called appropriately')
|
||||
|
||||
console.log((expected+2) + ' tests passed.')
|
||||
}
|
||||
}
|
||||
97
node_modules/request/tests/test-https-strict.js
generated
vendored
Normal file
97
node_modules/request/tests/test-https-strict.js
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
// a test where we validate the siguature of the keys
|
||||
// otherwise exactly the same as the ssl test
|
||||
|
||||
var server = require('./server')
|
||||
, assert = require('assert')
|
||||
, request = require('../main.js')
|
||||
, fs = require('fs')
|
||||
, path = require('path')
|
||||
, opts = { key: path.resolve(__dirname, 'ssl/ca/server.key')
|
||||
, cert: path.resolve(__dirname, 'ssl/ca/server.crt') }
|
||||
, s = server.createSSLServer(null, opts)
|
||||
, caFile = path.resolve(__dirname, 'ssl/ca/ca.crt')
|
||||
, ca = fs.readFileSync(caFile)
|
||||
|
||||
var tests =
|
||||
{ testGet :
|
||||
{ resp : server.createGetResponse("TESTING!")
|
||||
, expectBody: "TESTING!"
|
||||
}
|
||||
, testGetChunkBreak :
|
||||
{ resp : server.createChunkResponse(
|
||||
[ new Buffer([239])
|
||||
, new Buffer([163])
|
||||
, new Buffer([191])
|
||||
, new Buffer([206])
|
||||
, new Buffer([169])
|
||||
, new Buffer([226])
|
||||
, new Buffer([152])
|
||||
, new Buffer([131])
|
||||
])
|
||||
, expectBody: "Ω☃"
|
||||
}
|
||||
, testGetJSON :
|
||||
{ resp : server.createGetResponse('{"test":true}', 'application/json')
|
||||
, json : true
|
||||
, expectBody: {"test":true}
|
||||
}
|
||||
, testPutString :
|
||||
{ resp : server.createPostValidator("PUTTINGDATA")
|
||||
, method : "PUT"
|
||||
, body : "PUTTINGDATA"
|
||||
}
|
||||
, testPutBuffer :
|
||||
{ resp : server.createPostValidator("PUTTINGDATA")
|
||||
, method : "PUT"
|
||||
, body : new Buffer("PUTTINGDATA")
|
||||
}
|
||||
, testPutJSON :
|
||||
{ resp : server.createPostValidator(JSON.stringify({foo: 'bar'}))
|
||||
, method: "PUT"
|
||||
, json: {foo: 'bar'}
|
||||
}
|
||||
, testPutMultipart :
|
||||
{ resp: server.createPostValidator(
|
||||
'--frontier\r\n' +
|
||||
'content-type: text/html\r\n' +
|
||||
'\r\n' +
|
||||
'<html><body>Oh hi.</body></html>' +
|
||||
'\r\n--frontier\r\n\r\n' +
|
||||
'Oh hi.' +
|
||||
'\r\n--frontier--'
|
||||
)
|
||||
, method: "PUT"
|
||||
, multipart:
|
||||
[ {'content-type': 'text/html', 'body': '<html><body>Oh hi.</body></html>'}
|
||||
, {'body': 'Oh hi.'}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
s.listen(s.port, function () {
|
||||
|
||||
var counter = 0
|
||||
|
||||
for (i in tests) {
|
||||
(function () {
|
||||
var test = tests[i]
|
||||
s.on('/'+i, test.resp)
|
||||
test.uri = s.url + '/' + i
|
||||
test.strictSSL = true
|
||||
test.ca = ca
|
||||
test.headers = { host: 'testing.request.mikealrogers.com' }
|
||||
request(test, function (err, resp, body) {
|
||||
if (err) throw err
|
||||
if (test.expectBody) {
|
||||
assert.deepEqual(test.expectBody, body)
|
||||
}
|
||||
counter = counter - 1;
|
||||
if (counter === 0) {
|
||||
console.log(Object.keys(tests).length+" tests passed.")
|
||||
s.close()
|
||||
}
|
||||
})
|
||||
counter++
|
||||
})()
|
||||
}
|
||||
})
|
||||
86
node_modules/request/tests/test-https.js
generated
vendored
Normal file
86
node_modules/request/tests/test-https.js
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
var server = require('./server')
|
||||
, assert = require('assert')
|
||||
, request = require('../main.js')
|
||||
|
||||
var s = server.createSSLServer();
|
||||
|
||||
var tests =
|
||||
{ testGet :
|
||||
{ resp : server.createGetResponse("TESTING!")
|
||||
, expectBody: "TESTING!"
|
||||
}
|
||||
, testGetChunkBreak :
|
||||
{ resp : server.createChunkResponse(
|
||||
[ new Buffer([239])
|
||||
, new Buffer([163])
|
||||
, new Buffer([191])
|
||||
, new Buffer([206])
|
||||
, new Buffer([169])
|
||||
, new Buffer([226])
|
||||
, new Buffer([152])
|
||||
, new Buffer([131])
|
||||
])
|
||||
, expectBody: "Ω☃"
|
||||
}
|
||||
, testGetJSON :
|
||||
{ resp : server.createGetResponse('{"test":true}', 'application/json')
|
||||
, json : true
|
||||
, expectBody: {"test":true}
|
||||
}
|
||||
, testPutString :
|
||||
{ resp : server.createPostValidator("PUTTINGDATA")
|
||||
, method : "PUT"
|
||||
, body : "PUTTINGDATA"
|
||||
}
|
||||
, testPutBuffer :
|
||||
{ resp : server.createPostValidator("PUTTINGDATA")
|
||||
, method : "PUT"
|
||||
, body : new Buffer("PUTTINGDATA")
|
||||
}
|
||||
, testPutJSON :
|
||||
{ resp : server.createPostValidator(JSON.stringify({foo: 'bar'}))
|
||||
, method: "PUT"
|
||||
, json: {foo: 'bar'}
|
||||
}
|
||||
, testPutMultipart :
|
||||
{ resp: server.createPostValidator(
|
||||
'--frontier\r\n' +
|
||||
'content-type: text/html\r\n' +
|
||||
'\r\n' +
|
||||
'<html><body>Oh hi.</body></html>' +
|
||||
'\r\n--frontier\r\n\r\n' +
|
||||
'Oh hi.' +
|
||||
'\r\n--frontier--'
|
||||
)
|
||||
, method: "PUT"
|
||||
, multipart:
|
||||
[ {'content-type': 'text/html', 'body': '<html><body>Oh hi.</body></html>'}
|
||||
, {'body': 'Oh hi.'}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
s.listen(s.port, function () {
|
||||
|
||||
var counter = 0
|
||||
|
||||
for (i in tests) {
|
||||
(function () {
|
||||
var test = tests[i]
|
||||
s.on('/'+i, test.resp)
|
||||
test.uri = s.url + '/' + i
|
||||
request(test, function (err, resp, body) {
|
||||
if (err) throw err
|
||||
if (test.expectBody) {
|
||||
assert.deepEqual(test.expectBody, body)
|
||||
}
|
||||
counter = counter - 1;
|
||||
if (counter === 0) {
|
||||
console.log(Object.keys(tests).length+" tests passed.")
|
||||
s.close()
|
||||
}
|
||||
})
|
||||
counter++
|
||||
})()
|
||||
}
|
||||
})
|
||||
117
node_modules/request/tests/test-oauth.js
generated
vendored
Normal file
117
node_modules/request/tests/test-oauth.js
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
var hmacsign = require('../oauth').hmacsign
|
||||
, assert = require('assert')
|
||||
, qs = require('querystring')
|
||||
, request = require('../main')
|
||||
;
|
||||
|
||||
function getsignature (r) {
|
||||
var sign
|
||||
r.headers.authorization.slice('OAuth '.length).replace(/,\ /g, ',').split(',').forEach(function (v) {
|
||||
if (v.slice(0, 'oauth_signature="'.length) === 'oauth_signature="') sign = v.slice('oauth_signature="'.length, -1)
|
||||
})
|
||||
return decodeURIComponent(sign)
|
||||
}
|
||||
|
||||
// Tests from Twitter documentation https://dev.twitter.com/docs/auth/oauth
|
||||
|
||||
var reqsign = hmacsign('POST', 'https://api.twitter.com/oauth/request_token',
|
||||
{ oauth_callback: 'http://localhost:3005/the_dance/process_callback?service_provider_id=11'
|
||||
, oauth_consumer_key: 'GDdmIQH6jhtmLUypg82g'
|
||||
, oauth_nonce: 'QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk'
|
||||
, oauth_signature_method: 'HMAC-SHA1'
|
||||
, oauth_timestamp: '1272323042'
|
||||
, oauth_version: '1.0'
|
||||
}, "MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98")
|
||||
|
||||
console.log(reqsign)
|
||||
console.log('8wUi7m5HFQy76nowoCThusfgB+Q=')
|
||||
assert.equal(reqsign, '8wUi7m5HFQy76nowoCThusfgB+Q=')
|
||||
|
||||
var accsign = hmacsign('POST', 'https://api.twitter.com/oauth/access_token',
|
||||
{ oauth_consumer_key: 'GDdmIQH6jhtmLUypg82g'
|
||||
, oauth_nonce: '9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8'
|
||||
, oauth_signature_method: 'HMAC-SHA1'
|
||||
, oauth_token: '8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc'
|
||||
, oauth_timestamp: '1272323047'
|
||||
, oauth_verifier: 'pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY'
|
||||
, oauth_version: '1.0'
|
||||
}, "MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98", "x6qpRnlEmW9JbQn4PQVVeVG8ZLPEx6A0TOebgwcuA")
|
||||
|
||||
console.log(accsign)
|
||||
console.log('PUw/dHA4fnlJYM6RhXk5IU/0fCc=')
|
||||
assert.equal(accsign, 'PUw/dHA4fnlJYM6RhXk5IU/0fCc=')
|
||||
|
||||
var upsign = hmacsign('POST', 'http://api.twitter.com/1/statuses/update.json',
|
||||
{ oauth_consumer_key: "GDdmIQH6jhtmLUypg82g"
|
||||
, oauth_nonce: "oElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y"
|
||||
, oauth_signature_method: "HMAC-SHA1"
|
||||
, oauth_token: "819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw"
|
||||
, oauth_timestamp: "1272325550"
|
||||
, oauth_version: "1.0"
|
||||
, status: 'setting up my twitter 私のさえずりを設定する'
|
||||
}, "MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98", "J6zix3FfA9LofH0awS24M3HcBYXO5nI1iYe8EfBA")
|
||||
|
||||
console.log(upsign)
|
||||
console.log('yOahq5m0YjDDjfjxHaXEsW9D+X0=')
|
||||
assert.equal(upsign, 'yOahq5m0YjDDjfjxHaXEsW9D+X0=')
|
||||
|
||||
|
||||
var rsign = request.post(
|
||||
{ url: 'https://api.twitter.com/oauth/request_token'
|
||||
, oauth:
|
||||
{ callback: 'http://localhost:3005/the_dance/process_callback?service_provider_id=11'
|
||||
, consumer_key: 'GDdmIQH6jhtmLUypg82g'
|
||||
, nonce: 'QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk'
|
||||
, timestamp: '1272323042'
|
||||
, version: '1.0'
|
||||
, consumer_secret: "MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98"
|
||||
}
|
||||
})
|
||||
|
||||
setTimeout(function () {
|
||||
console.log(getsignature(rsign))
|
||||
assert.equal(reqsign, getsignature(rsign))
|
||||
})
|
||||
|
||||
var raccsign = request.post(
|
||||
{ url: 'https://api.twitter.com/oauth/access_token'
|
||||
, oauth:
|
||||
{ consumer_key: 'GDdmIQH6jhtmLUypg82g'
|
||||
, nonce: '9zWH6qe0qG7Lc1telCn7FhUbLyVdjEaL3MO5uHxn8'
|
||||
, signature_method: 'HMAC-SHA1'
|
||||
, token: '8ldIZyxQeVrFZXFOZH5tAwj6vzJYuLQpl0WUEYtWc'
|
||||
, timestamp: '1272323047'
|
||||
, verifier: 'pDNg57prOHapMbhv25RNf75lVRd6JDsni1AJJIDYoTY'
|
||||
, version: '1.0'
|
||||
, consumer_secret: "MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98"
|
||||
, token_secret: "x6qpRnlEmW9JbQn4PQVVeVG8ZLPEx6A0TOebgwcuA"
|
||||
}
|
||||
})
|
||||
|
||||
setTimeout(function () {
|
||||
console.log(getsignature(raccsign))
|
||||
assert.equal(accsign, getsignature(raccsign))
|
||||
}, 1)
|
||||
|
||||
var rupsign = request.post(
|
||||
{ url: 'http://api.twitter.com/1/statuses/update.json'
|
||||
, oauth:
|
||||
{ consumer_key: "GDdmIQH6jhtmLUypg82g"
|
||||
, nonce: "oElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y"
|
||||
, signature_method: "HMAC-SHA1"
|
||||
, token: "819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw"
|
||||
, timestamp: "1272325550"
|
||||
, version: "1.0"
|
||||
, consumer_secret: "MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98"
|
||||
, token_secret: "J6zix3FfA9LofH0awS24M3HcBYXO5nI1iYe8EfBA"
|
||||
}
|
||||
, form: {status: 'setting up my twitter 私のさえずりを設定する'}
|
||||
})
|
||||
setTimeout(function () {
|
||||
console.log(getsignature(rupsign))
|
||||
assert.equal(upsign, getsignature(rupsign))
|
||||
}, 1)
|
||||
|
||||
|
||||
|
||||
|
||||
92
node_modules/request/tests/test-params.js
generated
vendored
Normal file
92
node_modules/request/tests/test-params.js
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
var server = require('./server')
|
||||
, assert = require('assert')
|
||||
, request = require('../main.js')
|
||||
;
|
||||
|
||||
var s = server.createServer();
|
||||
|
||||
var tests =
|
||||
{ testGet :
|
||||
{ resp : server.createGetResponse("TESTING!")
|
||||
, expectBody: "TESTING!"
|
||||
}
|
||||
, testGetChunkBreak :
|
||||
{ resp : server.createChunkResponse(
|
||||
[ new Buffer([239])
|
||||
, new Buffer([163])
|
||||
, new Buffer([191])
|
||||
, new Buffer([206])
|
||||
, new Buffer([169])
|
||||
, new Buffer([226])
|
||||
, new Buffer([152])
|
||||
, new Buffer([131])
|
||||
])
|
||||
, expectBody: "Ω☃"
|
||||
}
|
||||
, testGetBuffer :
|
||||
{ resp : server.createGetResponse(new Buffer("TESTING!"))
|
||||
, encoding: null
|
||||
, expectBody: new Buffer("TESTING!")
|
||||
}
|
||||
, testGetJSON :
|
||||
{ resp : server.createGetResponse('{"test":true}', 'application/json')
|
||||
, json : true
|
||||
, expectBody: {"test":true}
|
||||
}
|
||||
, testPutString :
|
||||
{ resp : server.createPostValidator("PUTTINGDATA")
|
||||
, method : "PUT"
|
||||
, body : "PUTTINGDATA"
|
||||
}
|
||||
, testPutBuffer :
|
||||
{ resp : server.createPostValidator("PUTTINGDATA")
|
||||
, method : "PUT"
|
||||
, body : new Buffer("PUTTINGDATA")
|
||||
}
|
||||
, testPutJSON :
|
||||
{ resp : server.createPostValidator(JSON.stringify({foo: 'bar'}))
|
||||
, method: "PUT"
|
||||
, json: {foo: 'bar'}
|
||||
}
|
||||
, testPutMultipart :
|
||||
{ resp: server.createPostValidator(
|
||||
'--frontier\r\n' +
|
||||
'content-type: text/html\r\n' +
|
||||
'\r\n' +
|
||||
'<html><body>Oh hi.</body></html>' +
|
||||
'\r\n--frontier\r\n\r\n' +
|
||||
'Oh hi.' +
|
||||
'\r\n--frontier--'
|
||||
)
|
||||
, method: "PUT"
|
||||
, multipart:
|
||||
[ {'content-type': 'text/html', 'body': '<html><body>Oh hi.</body></html>'}
|
||||
, {'body': 'Oh hi.'}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
s.listen(s.port, function () {
|
||||
|
||||
var counter = 0
|
||||
|
||||
for (i in tests) {
|
||||
(function () {
|
||||
var test = tests[i]
|
||||
s.on('/'+i, test.resp)
|
||||
//test.uri = s.url + '/' + i
|
||||
request(s.url + '/' + i, test, function (err, resp, body) {
|
||||
if (err) throw err
|
||||
if (test.expectBody) {
|
||||
assert.deepEqual(test.expectBody, body)
|
||||
}
|
||||
counter = counter - 1;
|
||||
if (counter === 0) {
|
||||
console.log(Object.keys(tests).length+" tests passed.")
|
||||
s.close()
|
||||
}
|
||||
})
|
||||
counter++
|
||||
})()
|
||||
}
|
||||
})
|
||||
202
node_modules/request/tests/test-pipes.js
generated
vendored
Normal file
202
node_modules/request/tests/test-pipes.js
generated
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
var server = require('./server')
|
||||
, events = require('events')
|
||||
, stream = require('stream')
|
||||
, assert = require('assert')
|
||||
, fs = require('fs')
|
||||
, request = require('../main.js')
|
||||
, path = require('path')
|
||||
, util = require('util')
|
||||
;
|
||||
|
||||
var s = server.createServer(3453);
|
||||
|
||||
function ValidationStream(str) {
|
||||
this.str = str
|
||||
this.buf = ''
|
||||
this.on('data', function (data) {
|
||||
this.buf += data
|
||||
})
|
||||
this.on('end', function () {
|
||||
assert.equal(this.str, this.buf)
|
||||
})
|
||||
this.writable = true
|
||||
}
|
||||
util.inherits(ValidationStream, stream.Stream)
|
||||
ValidationStream.prototype.write = function (chunk) {
|
||||
this.emit('data', chunk)
|
||||
}
|
||||
ValidationStream.prototype.end = function (chunk) {
|
||||
if (chunk) emit('data', chunk)
|
||||
this.emit('end')
|
||||
}
|
||||
|
||||
s.listen(s.port, function () {
|
||||
counter = 0;
|
||||
|
||||
var check = function () {
|
||||
counter = counter - 1
|
||||
if (counter === 0) {
|
||||
console.log('All tests passed.')
|
||||
setTimeout(function () {
|
||||
process.exit();
|
||||
}, 500)
|
||||
}
|
||||
}
|
||||
|
||||
// Test pipeing to a request object
|
||||
s.once('/push', server.createPostValidator("mydata"));
|
||||
|
||||
var mydata = new stream.Stream();
|
||||
mydata.readable = true
|
||||
|
||||
counter++
|
||||
var r1 = request.put({url:'http://localhost:3453/push'}, function () {
|
||||
check();
|
||||
})
|
||||
mydata.pipe(r1)
|
||||
|
||||
mydata.emit('data', 'mydata');
|
||||
mydata.emit('end');
|
||||
|
||||
|
||||
// Test pipeing from a request object.
|
||||
s.once('/pull', server.createGetResponse("mypulldata"));
|
||||
|
||||
var mypulldata = new stream.Stream();
|
||||
mypulldata.writable = true
|
||||
|
||||
counter++
|
||||
request({url:'http://localhost:3453/pull'}).pipe(mypulldata)
|
||||
|
||||
var d = '';
|
||||
|
||||
mypulldata.write = function (chunk) {
|
||||
d += chunk;
|
||||
}
|
||||
mypulldata.end = function () {
|
||||
assert.equal(d, 'mypulldata');
|
||||
check();
|
||||
};
|
||||
|
||||
|
||||
s.on('/cat', function (req, resp) {
|
||||
if (req.method === "GET") {
|
||||
resp.writeHead(200, {'content-type':'text/plain-test', 'content-length':4});
|
||||
resp.end('asdf')
|
||||
} else if (req.method === "PUT") {
|
||||
assert.equal(req.headers['content-type'], 'text/plain-test');
|
||||
assert.equal(req.headers['content-length'], 4)
|
||||
var validate = '';
|
||||
|
||||
req.on('data', function (chunk) {validate += chunk})
|
||||
req.on('end', function () {
|
||||
resp.writeHead(201);
|
||||
resp.end();
|
||||
assert.equal(validate, 'asdf');
|
||||
check();
|
||||
})
|
||||
}
|
||||
})
|
||||
s.on('/pushjs', function (req, resp) {
|
||||
if (req.method === "PUT") {
|
||||
assert.equal(req.headers['content-type'], 'text/javascript');
|
||||
check();
|
||||
}
|
||||
})
|
||||
s.on('/catresp', function (req, resp) {
|
||||
request.get('http://localhost:3453/cat').pipe(resp)
|
||||
})
|
||||
s.on('/doodle', function (req, resp) {
|
||||
if (req.headers['x-oneline-proxy']) {
|
||||
resp.setHeader('x-oneline-proxy', 'yup')
|
||||
}
|
||||
resp.writeHead('200', {'content-type':'image/png'})
|
||||
fs.createReadStream(path.join(__dirname, 'googledoodle.png')).pipe(resp)
|
||||
})
|
||||
s.on('/onelineproxy', function (req, resp) {
|
||||
var x = request('http://localhost:3453/doodle')
|
||||
req.pipe(x)
|
||||
x.pipe(resp)
|
||||
})
|
||||
|
||||
counter++
|
||||
fs.createReadStream(__filename).pipe(request.put('http://localhost:3453/pushjs'))
|
||||
|
||||
counter++
|
||||
request.get('http://localhost:3453/cat').pipe(request.put('http://localhost:3453/cat'))
|
||||
|
||||
counter++
|
||||
request.get('http://localhost:3453/catresp', function (e, resp, body) {
|
||||
assert.equal(resp.headers['content-type'], 'text/plain-test');
|
||||
assert.equal(resp.headers['content-length'], 4)
|
||||
check();
|
||||
})
|
||||
|
||||
var doodleWrite = fs.createWriteStream(path.join(__dirname, 'test.png'))
|
||||
|
||||
counter++
|
||||
request.get('http://localhost:3453/doodle').pipe(doodleWrite)
|
||||
|
||||
doodleWrite.on('close', function () {
|
||||
assert.deepEqual(fs.readFileSync(path.join(__dirname, 'googledoodle.png')), fs.readFileSync(path.join(__dirname, 'test.png')))
|
||||
check()
|
||||
})
|
||||
|
||||
process.on('exit', function () {
|
||||
fs.unlinkSync(path.join(__dirname, 'test.png'))
|
||||
})
|
||||
|
||||
counter++
|
||||
request.get({uri:'http://localhost:3453/onelineproxy', headers:{'x-oneline-proxy':'nope'}}, function (err, resp, body) {
|
||||
assert.equal(resp.headers['x-oneline-proxy'], 'yup')
|
||||
check()
|
||||
})
|
||||
|
||||
s.on('/afterresponse', function (req, resp) {
|
||||
resp.write('d')
|
||||
resp.end()
|
||||
})
|
||||
|
||||
counter++
|
||||
var afterresp = request.post('http://localhost:3453/afterresponse').on('response', function () {
|
||||
var v = new ValidationStream('d')
|
||||
afterresp.pipe(v)
|
||||
v.on('end', check)
|
||||
})
|
||||
|
||||
s.on('/forward1', function (req, resp) {
|
||||
resp.writeHead(302, {location:'/forward2'})
|
||||
resp.end()
|
||||
})
|
||||
s.on('/forward2', function (req, resp) {
|
||||
resp.writeHead('200', {'content-type':'image/png'})
|
||||
resp.write('d')
|
||||
resp.end()
|
||||
})
|
||||
|
||||
counter++
|
||||
var validateForward = new ValidationStream('d')
|
||||
validateForward.on('end', check)
|
||||
request.get('http://localhost:3453/forward1').pipe(validateForward)
|
||||
|
||||
// Test pipe options
|
||||
s.once('/opts', server.createGetResponse('opts response'));
|
||||
|
||||
var optsStream = new stream.Stream();
|
||||
optsStream.writable = true
|
||||
|
||||
var optsData = '';
|
||||
optsStream.write = function (buf) {
|
||||
optsData += buf;
|
||||
if (optsData === 'opts response') {
|
||||
setTimeout(check, 10);
|
||||
}
|
||||
}
|
||||
|
||||
optsStream.end = function () {
|
||||
assert.fail('end called')
|
||||
};
|
||||
|
||||
counter++
|
||||
request({url:'http://localhost:3453/opts'}).pipe(optsStream, { end : false })
|
||||
})
|
||||
39
node_modules/request/tests/test-proxy.js
generated
vendored
Normal file
39
node_modules/request/tests/test-proxy.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
var server = require('./server')
|
||||
, events = require('events')
|
||||
, stream = require('stream')
|
||||
, assert = require('assert')
|
||||
, fs = require('fs')
|
||||
, request = require('../main.js')
|
||||
, path = require('path')
|
||||
, util = require('util')
|
||||
;
|
||||
|
||||
var port = 6768
|
||||
, called = false
|
||||
, proxiedHost = 'google.com'
|
||||
;
|
||||
|
||||
var s = server.createServer(port)
|
||||
s.listen(port, function () {
|
||||
s.on('http://google.com/', function (req, res) {
|
||||
called = true
|
||||
assert.equal(req.headers.host, proxiedHost)
|
||||
res.writeHeader(200)
|
||||
res.end()
|
||||
})
|
||||
request ({
|
||||
url: 'http://'+proxiedHost,
|
||||
proxy: 'http://localhost:'+port
|
||||
/*
|
||||
//should behave as if these arguments where passed:
|
||||
url: 'http://localhost:'+port,
|
||||
headers: {host: proxiedHost}
|
||||
//*/
|
||||
}, function (err, res, body) {
|
||||
s.close()
|
||||
})
|
||||
})
|
||||
|
||||
process.on('exit', function () {
|
||||
assert.ok(called, 'the request must be made to the proxy server')
|
||||
})
|
||||
28
node_modules/request/tests/test-qs.js
generated
vendored
Normal file
28
node_modules/request/tests/test-qs.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
var request = request = require('../main.js')
|
||||
, assert = require('assert')
|
||||
;
|
||||
|
||||
|
||||
// Test adding a querystring
|
||||
var req1 = request.get({ uri: 'http://www.google.com', qs: { q : 'search' }})
|
||||
setTimeout(function() {
|
||||
assert.equal('/?q=search', req1.path)
|
||||
}, 1)
|
||||
|
||||
// Test replacing a querystring value
|
||||
var req2 = request.get({ uri: 'http://www.google.com?q=abc', qs: { q : 'search' }})
|
||||
setTimeout(function() {
|
||||
assert.equal('/?q=search', req2.path)
|
||||
}, 1)
|
||||
|
||||
// Test appending a querystring value to the ones present in the uri
|
||||
var req3 = request.get({ uri: 'http://www.google.com?x=y', qs: { q : 'search' }})
|
||||
setTimeout(function() {
|
||||
assert.equal('/?x=y&q=search', req3.path)
|
||||
}, 1)
|
||||
|
||||
// Test leaving a querystring alone
|
||||
var req4 = request.get({ uri: 'http://www.google.com?x=y'})
|
||||
setTimeout(function() {
|
||||
assert.equal('/?x=y', req4.path)
|
||||
}, 1)
|
||||
159
node_modules/request/tests/test-redirect.js
generated
vendored
Normal file
159
node_modules/request/tests/test-redirect.js
generated
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
var server = require('./server')
|
||||
, assert = require('assert')
|
||||
, request = require('../main.js')
|
||||
, Cookie = require('../vendor/cookie')
|
||||
, Jar = require('../vendor/cookie/jar')
|
||||
|
||||
var s = server.createServer()
|
||||
|
||||
s.listen(s.port, function () {
|
||||
var server = 'http://localhost:' + s.port;
|
||||
var hits = {}
|
||||
var passed = 0;
|
||||
|
||||
bouncer(301, 'temp')
|
||||
bouncer(302, 'perm')
|
||||
bouncer(302, 'nope')
|
||||
|
||||
function bouncer(code, label) {
|
||||
var landing = label+'_landing';
|
||||
|
||||
s.on('/'+label, function (req, res) {
|
||||
hits[label] = true;
|
||||
res.writeHead(code, {'location':server + '/'+landing})
|
||||
res.end()
|
||||
})
|
||||
|
||||
s.on('/'+landing, function (req, res) {
|
||||
if (req.method !== 'GET') { // We should only accept GET redirects
|
||||
console.error("Got a non-GET request to the redirect destination URL");
|
||||
resp.writeHead(400);
|
||||
resp.end();
|
||||
return;
|
||||
}
|
||||
// Make sure the cookie doesn't get included twice, see #139:
|
||||
assert.equal(req.headers.cookie, 'foo=bar; quux=baz');
|
||||
hits[landing] = true;
|
||||
res.writeHead(200)
|
||||
res.end(landing)
|
||||
})
|
||||
}
|
||||
|
||||
// Permanent bounce
|
||||
var jar = new Jar()
|
||||
jar.add(new Cookie('quux=baz'))
|
||||
request({uri: server+'/perm', jar: jar, headers: {cookie: 'foo=bar'}}, function (er, res, body) {
|
||||
try {
|
||||
assert.ok(hits.perm, 'Original request is to /perm')
|
||||
assert.ok(hits.perm_landing, 'Forward to permanent landing URL')
|
||||
assert.equal(body, 'perm_landing', 'Got permanent landing content')
|
||||
passed += 1
|
||||
} finally {
|
||||
done()
|
||||
}
|
||||
})
|
||||
|
||||
// Temporary bounce
|
||||
request({uri: server+'/temp', jar: jar, headers: {cookie: 'foo=bar'}}, function (er, res, body) {
|
||||
try {
|
||||
assert.ok(hits.temp, 'Original request is to /temp')
|
||||
assert.ok(hits.temp_landing, 'Forward to temporary landing URL')
|
||||
assert.equal(body, 'temp_landing', 'Got temporary landing content')
|
||||
passed += 1
|
||||
} finally {
|
||||
done()
|
||||
}
|
||||
})
|
||||
|
||||
// Prevent bouncing.
|
||||
request({uri:server+'/nope', jar: jar, headers: {cookie: 'foo=bar'}, followRedirect:false}, function (er, res, body) {
|
||||
try {
|
||||
assert.ok(hits.nope, 'Original request to /nope')
|
||||
assert.ok(!hits.nope_landing, 'No chasing the redirect')
|
||||
assert.equal(res.statusCode, 302, 'Response is the bounce itself')
|
||||
passed += 1
|
||||
} finally {
|
||||
done()
|
||||
}
|
||||
})
|
||||
|
||||
// Should not follow post redirects by default
|
||||
request.post(server+'/temp', { jar: jar, headers: {cookie: 'foo=bar'}}, function (er, res, body) {
|
||||
try {
|
||||
assert.ok(hits.temp, 'Original request is to /temp')
|
||||
assert.ok(!hits.temp_landing, 'No chasing the redirect when post')
|
||||
assert.equal(res.statusCode, 301, 'Response is the bounce itself')
|
||||
passed += 1
|
||||
} finally {
|
||||
done()
|
||||
}
|
||||
})
|
||||
|
||||
// Should follow post redirects when followAllRedirects true
|
||||
request.post({uri:server+'/temp', followAllRedirects:true, jar: jar, headers: {cookie: 'foo=bar'}}, function (er, res, body) {
|
||||
try {
|
||||
assert.ok(hits.temp, 'Original request is to /temp')
|
||||
assert.ok(hits.temp_landing, 'Forward to temporary landing URL')
|
||||
assert.equal(body, 'temp_landing', 'Got temporary landing content')
|
||||
passed += 1
|
||||
} finally {
|
||||
done()
|
||||
}
|
||||
})
|
||||
|
||||
request.post({uri:server+'/temp', followAllRedirects:false, jar: jar, headers: {cookie: 'foo=bar'}}, function (er, res, body) {
|
||||
try {
|
||||
assert.ok(hits.temp, 'Original request is to /temp')
|
||||
assert.ok(!hits.temp_landing, 'No chasing the redirect')
|
||||
assert.equal(res.statusCode, 301, 'Response is the bounce itself')
|
||||
passed += 1
|
||||
} finally {
|
||||
done()
|
||||
}
|
||||
})
|
||||
|
||||
// Should not follow delete redirects by default
|
||||
request.del(server+'/temp', { jar: jar, headers: {cookie: 'foo=bar'}}, function (er, res, body) {
|
||||
try {
|
||||
assert.ok(hits.temp, 'Original request is to /temp')
|
||||
assert.ok(!hits.temp_landing, 'No chasing the redirect when delete')
|
||||
assert.equal(res.statusCode, 301, 'Response is the bounce itself')
|
||||
passed += 1
|
||||
} finally {
|
||||
done()
|
||||
}
|
||||
})
|
||||
|
||||
// Should not follow delete redirects even if followRedirect is set to true
|
||||
request.del(server+'/temp', { followRedirect: true, jar: jar, headers: {cookie: 'foo=bar'}}, function (er, res, body) {
|
||||
try {
|
||||
assert.ok(hits.temp, 'Original request is to /temp')
|
||||
assert.ok(!hits.temp_landing, 'No chasing the redirect when delete')
|
||||
assert.equal(res.statusCode, 301, 'Response is the bounce itself')
|
||||
passed += 1
|
||||
} finally {
|
||||
done()
|
||||
}
|
||||
})
|
||||
|
||||
// Should follow delete redirects when followAllRedirects true
|
||||
request.del(server+'/temp', {followAllRedirects:true, jar: jar, headers: {cookie: 'foo=bar'}}, function (er, res, body) {
|
||||
try {
|
||||
assert.ok(hits.temp, 'Original request is to /temp')
|
||||
assert.ok(hits.temp_landing, 'Forward to temporary landing URL')
|
||||
assert.equal(body, 'temp_landing', 'Got temporary landing content')
|
||||
passed += 1
|
||||
} finally {
|
||||
done()
|
||||
}
|
||||
})
|
||||
|
||||
var reqs_done = 0;
|
||||
function done() {
|
||||
reqs_done += 1;
|
||||
if(reqs_done == 9) {
|
||||
console.log(passed + ' tests passed.')
|
||||
s.close()
|
||||
}
|
||||
}
|
||||
})
|
||||
87
node_modules/request/tests/test-timeout.js
generated
vendored
Normal file
87
node_modules/request/tests/test-timeout.js
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
var server = require('./server')
|
||||
, events = require('events')
|
||||
, stream = require('stream')
|
||||
, assert = require('assert')
|
||||
, request = require('../main.js')
|
||||
;
|
||||
|
||||
var s = server.createServer();
|
||||
var expectedBody = "waited";
|
||||
var remainingTests = 5;
|
||||
|
||||
s.listen(s.port, function () {
|
||||
// Request that waits for 200ms
|
||||
s.on('/timeout', function (req, resp) {
|
||||
setTimeout(function(){
|
||||
resp.writeHead(200, {'content-type':'text/plain'})
|
||||
resp.write(expectedBody)
|
||||
resp.end()
|
||||
}, 200);
|
||||
});
|
||||
|
||||
// Scenario that should timeout
|
||||
var shouldTimeout = {
|
||||
url: s.url + "/timeout",
|
||||
timeout:100
|
||||
}
|
||||
|
||||
|
||||
request(shouldTimeout, function (err, resp, body) {
|
||||
assert.equal(err.code, "ETIMEDOUT");
|
||||
checkDone();
|
||||
})
|
||||
|
||||
|
||||
// Scenario that shouldn't timeout
|
||||
var shouldntTimeout = {
|
||||
url: s.url + "/timeout",
|
||||
timeout:300
|
||||
}
|
||||
|
||||
request(shouldntTimeout, function (err, resp, body) {
|
||||
assert.equal(err, null);
|
||||
assert.equal(expectedBody, body)
|
||||
checkDone();
|
||||
})
|
||||
|
||||
// Scenario with no timeout set, so shouldn't timeout
|
||||
var noTimeout = {
|
||||
url: s.url + "/timeout"
|
||||
}
|
||||
|
||||
request(noTimeout, function (err, resp, body) {
|
||||
assert.equal(err);
|
||||
assert.equal(expectedBody, body)
|
||||
checkDone();
|
||||
})
|
||||
|
||||
// Scenario with a negative timeout value, should be treated a zero or the minimum delay
|
||||
var negativeTimeout = {
|
||||
url: s.url + "/timeout",
|
||||
timeout:-1000
|
||||
}
|
||||
|
||||
request(negativeTimeout, function (err, resp, body) {
|
||||
assert.equal(err.code, "ETIMEDOUT");
|
||||
checkDone();
|
||||
})
|
||||
|
||||
// Scenario with a float timeout value, should be rounded by setTimeout anyway
|
||||
var floatTimeout = {
|
||||
url: s.url + "/timeout",
|
||||
timeout: 100.76
|
||||
}
|
||||
|
||||
request(floatTimeout, function (err, resp, body) {
|
||||
assert.equal(err.code, "ETIMEDOUT");
|
||||
checkDone();
|
||||
})
|
||||
|
||||
function checkDone() {
|
||||
if(--remainingTests == 0) {
|
||||
s.close();
|
||||
console.log("All tests passed.");
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
61
node_modules/request/tests/test-tunnel.js
generated
vendored
Normal file
61
node_modules/request/tests/test-tunnel.js
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
// test that we can tunnel a https request over an http proxy
|
||||
// keeping all the CA and whatnot intact.
|
||||
//
|
||||
// Note: this requires that squid is installed.
|
||||
// If the proxy fails to start, we'll just log a warning and assume success.
|
||||
|
||||
var server = require('./server')
|
||||
, assert = require('assert')
|
||||
, request = require('../main.js')
|
||||
, fs = require('fs')
|
||||
, path = require('path')
|
||||
, caFile = path.resolve(__dirname, 'ssl/npm-ca.crt')
|
||||
, ca = fs.readFileSync(caFile)
|
||||
, child_process = require('child_process')
|
||||
, sqConf = path.resolve(__dirname, 'squid.conf')
|
||||
, sqArgs = ['-f', sqConf, '-N', '-d', '5']
|
||||
, proxy = 'http://localhost:3128'
|
||||
, hadError = null
|
||||
|
||||
var squid = child_process.spawn('squid', sqArgs);
|
||||
var ready = false
|
||||
|
||||
squid.stderr.on('data', function (c) {
|
||||
console.error('SQUIDERR ' + c.toString().trim().split('\n')
|
||||
.join('\nSQUIDERR '))
|
||||
ready = c.toString().match(/ready to serve requests/i)
|
||||
})
|
||||
|
||||
squid.stdout.on('data', function (c) {
|
||||
console.error('SQUIDOUT ' + c.toString().trim().split('\n')
|
||||
.join('\nSQUIDOUT '))
|
||||
})
|
||||
|
||||
squid.on('exit', function (c) {
|
||||
console.error('exit '+c)
|
||||
if (c && !ready) {
|
||||
console.error('squid must be installed to run this test.')
|
||||
c = null
|
||||
hadError = null
|
||||
process.exit(0)
|
||||
return
|
||||
}
|
||||
|
||||
if (c) {
|
||||
hadError = hadError || new Error('Squid exited with '+c)
|
||||
}
|
||||
if (hadError) throw hadError
|
||||
})
|
||||
|
||||
setTimeout(function F () {
|
||||
if (!ready) return setTimeout(F, 100)
|
||||
request({ uri: 'https://registry.npmjs.org/request/'
|
||||
, proxy: 'http://localhost:3128'
|
||||
, ca: ca
|
||||
, json: true }, function (er, body) {
|
||||
hadError = er
|
||||
console.log(er || typeof body)
|
||||
if (!er) console.log("ok")
|
||||
squid.kill('SIGKILL')
|
||||
})
|
||||
}, 100)
|
||||
229
node_modules/request/tunnel.js
generated
vendored
Normal file
229
node_modules/request/tunnel.js
generated
vendored
Normal file
@@ -0,0 +1,229 @@
|
||||
'use strict';
|
||||
|
||||
var net = require('net');
|
||||
var tls = require('tls');
|
||||
var http = require('http');
|
||||
var https = require('https');
|
||||
var events = require('events');
|
||||
var assert = require('assert');
|
||||
var util = require('util');
|
||||
|
||||
|
||||
exports.httpOverHttp = httpOverHttp;
|
||||
exports.httpsOverHttp = httpsOverHttp;
|
||||
exports.httpOverHttps = httpOverHttps;
|
||||
exports.httpsOverHttps = httpsOverHttps;
|
||||
|
||||
|
||||
function httpOverHttp(options) {
|
||||
var agent = new TunnelingAgent(options);
|
||||
agent.request = http.request;
|
||||
return agent;
|
||||
}
|
||||
|
||||
function httpsOverHttp(options) {
|
||||
var agent = new TunnelingAgent(options);
|
||||
agent.request = http.request;
|
||||
agent.createSocket = createSecureSocket;
|
||||
return agent;
|
||||
}
|
||||
|
||||
function httpOverHttps(options) {
|
||||
var agent = new TunnelingAgent(options);
|
||||
agent.request = https.request;
|
||||
return agent;
|
||||
}
|
||||
|
||||
function httpsOverHttps(options) {
|
||||
var agent = new TunnelingAgent(options);
|
||||
agent.request = https.request;
|
||||
agent.createSocket = createSecureSocket;
|
||||
return agent;
|
||||
}
|
||||
|
||||
|
||||
function TunnelingAgent(options) {
|
||||
var self = this;
|
||||
self.options = options || {};
|
||||
self.proxyOptions = self.options.proxy || {};
|
||||
self.maxSockets = self.options.maxSockets || http.Agent.defaultMaxSockets;
|
||||
self.requests = [];
|
||||
self.sockets = [];
|
||||
|
||||
self.on('free', function onFree(socket, host, port) {
|
||||
for (var i = 0, len = self.requests.length; i < len; ++i) {
|
||||
var pending = self.requests[i];
|
||||
if (pending.host === host && pending.port === port) {
|
||||
// Detect the request to connect same origin server,
|
||||
// reuse the connection.
|
||||
self.requests.splice(i, 1);
|
||||
pending.request.onSocket(socket);
|
||||
return;
|
||||
}
|
||||
}
|
||||
socket.destroy();
|
||||
self.removeSocket(socket);
|
||||
});
|
||||
}
|
||||
util.inherits(TunnelingAgent, events.EventEmitter);
|
||||
|
||||
TunnelingAgent.prototype.addRequest = function addRequest(req, host, port) {
|
||||
var self = this;
|
||||
|
||||
if (self.sockets.length >= this.maxSockets) {
|
||||
// We are over limit so we'll add it to the queue.
|
||||
self.requests.push({host: host, port: port, request: req});
|
||||
return;
|
||||
}
|
||||
|
||||
// If we are under maxSockets create a new one.
|
||||
self.createSocket({host: host, port: port, request: req}, function(socket) {
|
||||
socket.on('free', onFree);
|
||||
socket.on('close', onCloseOrRemove);
|
||||
socket.on('agentRemove', onCloseOrRemove);
|
||||
req.onSocket(socket);
|
||||
|
||||
function onFree() {
|
||||
self.emit('free', socket, host, port);
|
||||
}
|
||||
|
||||
function onCloseOrRemove(err) {
|
||||
self.removeSocket();
|
||||
socket.removeListener('free', onFree);
|
||||
socket.removeListener('close', onCloseOrRemove);
|
||||
socket.removeListener('agentRemove', onCloseOrRemove);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
TunnelingAgent.prototype.createSocket = function createSocket(options, cb) {
|
||||
var self = this;
|
||||
var placeholder = {};
|
||||
self.sockets.push(placeholder);
|
||||
|
||||
var connectOptions = mergeOptions({}, self.proxyOptions, {
|
||||
method: 'CONNECT',
|
||||
path: options.host + ':' + options.port,
|
||||
agent: false
|
||||
});
|
||||
if (connectOptions.proxyAuth) {
|
||||
connectOptions.headers = connectOptions.headers || {};
|
||||
connectOptions.headers['Proxy-Authorization'] = 'Basic ' +
|
||||
new Buffer(connectOptions.proxyAuth).toString('base64');
|
||||
}
|
||||
|
||||
debug('making CONNECT request');
|
||||
var connectReq = self.request(connectOptions);
|
||||
connectReq.useChunkedEncodingByDefault = false; // for v0.6
|
||||
connectReq.once('response', onResponse); // for v0.6
|
||||
connectReq.once('upgrade', onUpgrade); // for v0.6
|
||||
connectReq.once('connect', onConnect); // for v0.7 or later
|
||||
connectReq.once('error', onError);
|
||||
connectReq.end();
|
||||
|
||||
function onResponse(res) {
|
||||
// Very hacky. This is necessary to avoid http-parser leaks.
|
||||
res.upgrade = true;
|
||||
}
|
||||
|
||||
function onUpgrade(res, socket, head) {
|
||||
// Hacky.
|
||||
process.nextTick(function() {
|
||||
onConnect(res, socket, head);
|
||||
});
|
||||
}
|
||||
|
||||
function onConnect(res, socket, head) {
|
||||
connectReq.removeAllListeners();
|
||||
socket.removeAllListeners();
|
||||
|
||||
if (res.statusCode === 200) {
|
||||
assert.equal(head.length, 0);
|
||||
debug('tunneling connection has established');
|
||||
self.sockets[self.sockets.indexOf(placeholder)] = socket;
|
||||
cb(socket);
|
||||
} else {
|
||||
debug('tunneling socket could not be established, statusCode=%d',
|
||||
res.statusCode);
|
||||
var error = new Error('tunneling socket could not be established, ' +
|
||||
'sutatusCode=' + res.statusCode);
|
||||
error.code = 'ECONNRESET';
|
||||
options.request.emit('error', error);
|
||||
self.removeSocket(placeholder);
|
||||
}
|
||||
}
|
||||
|
||||
function onError(cause) {
|
||||
connectReq.removeAllListeners();
|
||||
|
||||
debug('tunneling socket could not be established, cause=%s\n',
|
||||
cause.message, cause.stack);
|
||||
var error = new Error('tunneling socket could not be established, ' +
|
||||
'cause=' + cause.message);
|
||||
error.code = 'ECONNRESET';
|
||||
options.request.emit('error', error);
|
||||
self.removeSocket(placeholder);
|
||||
}
|
||||
};
|
||||
|
||||
TunnelingAgent.prototype.removeSocket = function removeSocket(socket) {
|
||||
var pos = this.sockets.indexOf(socket)
|
||||
if (pos === -1) {
|
||||
return;
|
||||
}
|
||||
this.sockets.splice(pos, 1);
|
||||
|
||||
var pending = this.requests.shift();
|
||||
if (pending) {
|
||||
// If we have pending requests and a socket gets closed a new one
|
||||
// needs to be created to take over in the pool for the one that closed.
|
||||
this.createSocket(pending, function(socket) {
|
||||
pending.request.onSocket(socket);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function createSecureSocket(options, cb) {
|
||||
var self = this;
|
||||
TunnelingAgent.prototype.createSocket.call(self, options, function(socket) {
|
||||
// 0 is dummy port for v0.6
|
||||
var secureSocket = tls.connect(0, mergeOptions({}, self.options, {
|
||||
socket: socket
|
||||
}));
|
||||
cb(secureSocket);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function mergeOptions(target) {
|
||||
for (var i = 1, len = arguments.length; i < len; ++i) {
|
||||
var overrides = arguments[i];
|
||||
if (typeof overrides === 'object') {
|
||||
var keys = Object.keys(overrides);
|
||||
for (var j = 0, keyLen = keys.length; j < keyLen; ++j) {
|
||||
var k = keys[j];
|
||||
if (overrides[k] !== undefined) {
|
||||
target[k] = overrides[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
var debug;
|
||||
if (process.env.NODE_DEBUG && /\btunnel\b/.test(process.env.NODE_DEBUG)) {
|
||||
debug = function() {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
if (typeof args[0] === 'string') {
|
||||
args[0] = 'TUNNEL: ' + args[0];
|
||||
} else {
|
||||
args.unshift('TUNNEL:');
|
||||
}
|
||||
console.error.apply(console, args);
|
||||
}
|
||||
} else {
|
||||
debug = function() {};
|
||||
}
|
||||
exports.debug = debug; // for test
|
||||
19
node_modules/request/uuid.js
generated
vendored
Normal file
19
node_modules/request/uuid.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
module.exports = function () {
|
||||
var s = [], itoh = '0123456789ABCDEF';
|
||||
|
||||
// Make array of random hex digits. The UUID only has 32 digits in it, but we
|
||||
// allocate an extra items to make room for the '-'s we'll be inserting.
|
||||
for (var i = 0; i <36; i++) s[i] = Math.floor(Math.random()*0x10);
|
||||
|
||||
// Conform to RFC-4122, section 4.4
|
||||
s[14] = 4; // Set 4 high bits of time_high field to version
|
||||
s[19] = (s[19] & 0x3) | 0x8; // Specify 2 high bits of clock sequence
|
||||
|
||||
// Convert to hex chars
|
||||
for (var i = 0; i <36; i++) s[i] = itoh[s[i]];
|
||||
|
||||
// Insert '-'s
|
||||
s[8] = s[13] = s[18] = s[23] = '-';
|
||||
|
||||
return s.join('');
|
||||
}
|
||||
60
node_modules/request/vendor/cookie/index.js
generated
vendored
Normal file
60
node_modules/request/vendor/cookie/index.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
/*!
|
||||
* Tobi - Cookie
|
||||
* Copyright(c) 2010 LearnBoost <dev@learnboost.com>
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var url = require('url');
|
||||
|
||||
/**
|
||||
* Initialize a new `Cookie` with the given cookie `str` and `req`.
|
||||
*
|
||||
* @param {String} str
|
||||
* @param {IncomingRequest} req
|
||||
* @api private
|
||||
*/
|
||||
|
||||
var Cookie = exports = module.exports = function Cookie(str, req) {
|
||||
this.str = str;
|
||||
|
||||
// First key is the name
|
||||
this.name = str.substr(0, str.indexOf('=')).trim();
|
||||
|
||||
// Map the key/val pairs
|
||||
str.split(/ *; */).reduce(function(obj, pair){
|
||||
var p = pair.indexOf('=');
|
||||
if(p > 0)
|
||||
obj[pair.substring(0, p).trim()] = pair.substring(p + 1).trim();
|
||||
else
|
||||
obj[pair.trim()] = true;
|
||||
return obj;
|
||||
}, this);
|
||||
|
||||
// Assign value
|
||||
this.value = this[this.name];
|
||||
|
||||
// Expires
|
||||
this.expires = this.expires
|
||||
? new Date(this.expires)
|
||||
: Infinity;
|
||||
|
||||
// Default or trim path
|
||||
this.path = this.path
|
||||
? this.path.trim(): req
|
||||
? url.parse(req.url).pathname: '/';
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the original cookie string.
|
||||
*
|
||||
* @return {String}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Cookie.prototype.toString = function(){
|
||||
return this.str;
|
||||
};
|
||||
72
node_modules/request/vendor/cookie/jar.js
generated
vendored
Normal file
72
node_modules/request/vendor/cookie/jar.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
/*!
|
||||
* Tobi - CookieJar
|
||||
* Copyright(c) 2010 LearnBoost <dev@learnboost.com>
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var url = require('url');
|
||||
|
||||
/**
|
||||
* Initialize a new `CookieJar`.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
var CookieJar = exports = module.exports = function CookieJar() {
|
||||
this.cookies = [];
|
||||
};
|
||||
|
||||
/**
|
||||
* Add the given `cookie` to the jar.
|
||||
*
|
||||
* @param {Cookie} cookie
|
||||
* @api private
|
||||
*/
|
||||
|
||||
CookieJar.prototype.add = function(cookie){
|
||||
this.cookies = this.cookies.filter(function(c){
|
||||
// Avoid duplication (same path, same name)
|
||||
return !(c.name == cookie.name && c.path == cookie.path);
|
||||
});
|
||||
this.cookies.push(cookie);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get cookies for the given `req`.
|
||||
*
|
||||
* @param {IncomingRequest} req
|
||||
* @return {Array}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
CookieJar.prototype.get = function(req){
|
||||
var path = url.parse(req.url).pathname
|
||||
, now = new Date
|
||||
, specificity = {};
|
||||
return this.cookies.filter(function(cookie){
|
||||
if (0 == path.indexOf(cookie.path) && now < cookie.expires
|
||||
&& cookie.path.length > (specificity[cookie.name] || 0))
|
||||
return specificity[cookie.name] = cookie.path.length;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Return Cookie string for the given `req`.
|
||||
*
|
||||
* @param {IncomingRequest} req
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
CookieJar.prototype.cookieString = function(req){
|
||||
var cookies = this.get(req);
|
||||
if (cookies.length) {
|
||||
return cookies.map(function(cookie){
|
||||
return cookie.name + '=' + cookie.value;
|
||||
}).join('; ');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user