init
This commit is contained in:
4
node_modules/simple-get/.travis.yml
generated
vendored
Normal file
4
node_modules/simple-get/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.11"
|
||||
- "0.10"
|
||||
20
node_modules/simple-get/LICENSE
generated
vendored
Normal file
20
node_modules/simple-get/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Feross Aboukhadijeh
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
112
node_modules/simple-get/README.md
generated
vendored
Normal file
112
node_modules/simple-get/README.md
generated
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
# simple-get [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url]
|
||||
|
||||
[travis-image]: https://img.shields.io/travis/feross/simple-get.svg?style=flat
|
||||
[travis-url]: https://travis-ci.org/feross/simple-get
|
||||
[npm-image]: https://img.shields.io/npm/v/simple-get.svg?style=flat
|
||||
[npm-url]: https://npmjs.org/package/simple-get
|
||||
[downloads-image]: https://img.shields.io/npm/dm/simple-get.svg?style=flat
|
||||
[downloads-url]: https://npmjs.org/package/simple-get
|
||||
|
||||
### Simplest way to make http get requests
|
||||
|
||||
## features
|
||||
|
||||
This module is designed to be the lightest possible wrapper on top of node.js `http`, but supporting:
|
||||
|
||||
- follows redirects
|
||||
- automatically handles gzip/deflate responses
|
||||
- supports HTTPS
|
||||
- supports convenience `url` key so there's no need to use `url.parse` on the url when specifying options
|
||||
|
||||
All this in < 100 lines of code.
|
||||
|
||||
## install
|
||||
|
||||
```
|
||||
npm install simple-get
|
||||
```
|
||||
|
||||
## usage
|
||||
|
||||
### simple GET request
|
||||
|
||||
Doesn't get easier than this:
|
||||
|
||||
```js
|
||||
var get = require('simple-get')
|
||||
|
||||
get('http://example.com', function (err, res) {
|
||||
if (err) throw err
|
||||
console.log(res.statusCode) // 200
|
||||
res.pipe(process.stdout) // `res` is a stream
|
||||
})
|
||||
```
|
||||
|
||||
### even simpler GET request
|
||||
|
||||
If you just want the data, and don't want to deal with streams:
|
||||
|
||||
```js
|
||||
var get = require('simple-get')
|
||||
|
||||
get.concat('http://example.com', function (err, data, res) {
|
||||
if (err) throw err
|
||||
console.log(res.statusCode) // 200
|
||||
console.log(data) // 'this is the server response'
|
||||
})
|
||||
```
|
||||
|
||||
### POST, PUT, PATCH, HEAD, DELETE support
|
||||
|
||||
For `POST`, call `get.post` or use option `{ method: 'POST' }`.
|
||||
|
||||
```js
|
||||
var get = require('simple-get')
|
||||
|
||||
var opts = {
|
||||
url: 'http://example.com',
|
||||
body: 'this is the POST body'
|
||||
}
|
||||
get.post(opts, function (err, res) {
|
||||
if (err) throw err
|
||||
res.pipe(process.stdout) // `res` is a stream
|
||||
})
|
||||
```
|
||||
|
||||
A more complex example:
|
||||
|
||||
```js
|
||||
var get = require('simple-get')
|
||||
var concat = require('concat-stream')
|
||||
|
||||
get({
|
||||
url: 'http://example.com',
|
||||
method: 'POST',
|
||||
body: 'this is the POST body',
|
||||
|
||||
// simple-get accepts all options that node.js `http` accepts
|
||||
// See: http://nodejs.org/api/http.html#http_http_request_options_callback
|
||||
headers: {
|
||||
'user-agent': 'my cool app'
|
||||
}
|
||||
}, function (err, res) {
|
||||
if (err) throw err
|
||||
|
||||
// All properties/methods from http.IncomingResponse are available,
|
||||
// even if a gunzip/inflate transform stream was returned.
|
||||
// See: http://nodejs.org/api/http.html#http_http_incomingmessage
|
||||
res.setTimeout(10000)
|
||||
console.log(res.headers)
|
||||
|
||||
res.pipe(concat(function (data) {
|
||||
// `data` is the decoded response, after it's been gunzipped or inflated
|
||||
// (if applicable)
|
||||
console.log('got the response: ' + data)
|
||||
}))
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
## license
|
||||
|
||||
MIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org).
|
||||
79
node_modules/simple-get/index.js
generated
vendored
Normal file
79
node_modules/simple-get/index.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
module.exports = simpleGet
|
||||
|
||||
var extend = require('xtend')
|
||||
var http = require('http')
|
||||
var https = require('https')
|
||||
var once = require('once')
|
||||
var unzipResponse = require('unzip-response') // excluded from browser build
|
||||
var url = require('url')
|
||||
|
||||
function simpleGet (opts, cb) {
|
||||
opts = typeof opts === 'string' ? { url: opts } : extend(opts)
|
||||
cb = once(cb)
|
||||
|
||||
if (opts.url) parseOptsUrl(opts)
|
||||
if (opts.headers == null) opts.headers = {}
|
||||
if (opts.maxRedirects == null) opts.maxRedirects = 10
|
||||
|
||||
var body = opts.body
|
||||
opts.body = undefined
|
||||
if (body && !opts.method) opts.method = 'POST'
|
||||
|
||||
// Request gzip/deflate
|
||||
var customAcceptEncoding = Object.keys(opts.headers).some(function (h) {
|
||||
return h.toLowerCase() === 'accept-encoding'
|
||||
})
|
||||
if (!customAcceptEncoding) opts.headers['accept-encoding'] = 'gzip, deflate'
|
||||
|
||||
// Support http: and https: urls
|
||||
var protocol = opts.protocol === 'https:' ? https : http
|
||||
var req = protocol.request(opts, function (res) {
|
||||
// Follow 3xx redirects
|
||||
if (res.statusCode >= 300 && res.statusCode < 400 && 'location' in res.headers) {
|
||||
opts.url = res.headers.location
|
||||
parseOptsUrl(opts)
|
||||
res.resume() // Discard response
|
||||
|
||||
opts.maxRedirects -= 1
|
||||
if (opts.maxRedirects > 0) simpleGet(opts, cb)
|
||||
else cb(new Error('too many redirects'))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
cb(null, typeof unzipResponse === 'function' ? unzipResponse(res) : res)
|
||||
})
|
||||
req.on('error', cb)
|
||||
req.end(body)
|
||||
return req
|
||||
}
|
||||
|
||||
module.exports.concat = function (opts, cb) {
|
||||
return simpleGet(opts, function (err, res) {
|
||||
if (err) return cb(err)
|
||||
var chunks = []
|
||||
res.on('data', function (chunk) {
|
||||
chunks.push(chunk)
|
||||
})
|
||||
res.on('end', function () {
|
||||
cb(null, Buffer.concat(chunks), res)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
;['get', 'post', 'put', 'patch', 'head', 'delete'].forEach(function (method) {
|
||||
module.exports[method] = function (opts, cb) {
|
||||
if (typeof opts === 'string') opts = { url: opts }
|
||||
opts.method = method.toUpperCase()
|
||||
return simpleGet(opts, cb)
|
||||
}
|
||||
})
|
||||
|
||||
function parseOptsUrl (opts) {
|
||||
var loc = url.parse(opts.url)
|
||||
if (loc.hostname) opts.hostname = loc.hostname
|
||||
if (loc.port) opts.port = loc.port
|
||||
if (loc.protocol) opts.protocol = loc.protocol
|
||||
opts.path = loc.path
|
||||
delete opts.url
|
||||
}
|
||||
111
node_modules/simple-get/package.json
generated
vendored
Normal file
111
node_modules/simple-get/package.json
generated
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"raw": "simple-get@^1.4.2",
|
||||
"scope": null,
|
||||
"escapedName": "simple-get",
|
||||
"name": "simple-get",
|
||||
"rawSpec": "^1.4.2",
|
||||
"spec": ">=1.4.2 <2.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"/home/vincent/Projects/SublimeTextProjects/shadowsocks-over-websocket/node_modules/prebuild-install"
|
||||
]
|
||||
],
|
||||
"_from": "simple-get@>=1.4.2 <2.0.0",
|
||||
"_id": "simple-get@1.4.3",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/simple-get",
|
||||
"_nodeVersion": "2.1.0",
|
||||
"_npmUser": {
|
||||
"name": "feross",
|
||||
"email": "feross@feross.org"
|
||||
},
|
||||
"_npmVersion": "2.10.1",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"raw": "simple-get@^1.4.2",
|
||||
"scope": null,
|
||||
"escapedName": "simple-get",
|
||||
"name": "simple-get",
|
||||
"rawSpec": "^1.4.2",
|
||||
"spec": ">=1.4.2 <2.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/prebuild-install"
|
||||
],
|
||||
"_resolved": "http://registry.npmjs.org/simple-get/-/simple-get-1.4.3.tgz",
|
||||
"_shasum": "e9755eda407e96da40c5e5158c9ea37b33becbeb",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "simple-get@^1.4.2",
|
||||
"_where": "/home/vincent/Projects/SublimeTextProjects/shadowsocks-over-websocket/node_modules/prebuild-install",
|
||||
"author": {
|
||||
"name": "Feross Aboukhadijeh",
|
||||
"email": "feross@feross.org",
|
||||
"url": "http://feross.org/"
|
||||
},
|
||||
"browser": {
|
||||
"unzip-response": false
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/feross/simple-get/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"once": "^1.3.1",
|
||||
"unzip-response": "^1.0.0",
|
||||
"xtend": "^4.0.0"
|
||||
},
|
||||
"description": "Simplest way to make http get requests. Supports HTTPS, redirects, gzip/deflate, streams in < 100 lines.",
|
||||
"devDependencies": {
|
||||
"concat-stream": "^1.4.7",
|
||||
"self-signed-https": "^1.0.5",
|
||||
"standard": "^5.1.0",
|
||||
"string-to-stream": "^1.0.0",
|
||||
"tape": "^4.0.0"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "e9755eda407e96da40c5e5158c9ea37b33becbeb",
|
||||
"tarball": "https://registry.npmjs.org/simple-get/-/simple-get-1.4.3.tgz"
|
||||
},
|
||||
"gitHead": "d212b1022d21b49c8ec83acf251d1dc4aeb38ca3",
|
||||
"homepage": "https://github.com/feross/simple-get",
|
||||
"keywords": [
|
||||
"request",
|
||||
"http",
|
||||
"GET",
|
||||
"get request",
|
||||
"http.get",
|
||||
"redirects",
|
||||
"follow redirects",
|
||||
"gzip",
|
||||
"deflate",
|
||||
"https",
|
||||
"http-https",
|
||||
"stream",
|
||||
"simple request",
|
||||
"simple get"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "feross",
|
||||
"email": "feross@feross.org"
|
||||
}
|
||||
],
|
||||
"name": "simple-get",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/feross/simple-get.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "standard && tape test/*.js"
|
||||
},
|
||||
"version": "1.4.3"
|
||||
}
|
||||
363
node_modules/simple-get/test/basic.js
generated
vendored
Normal file
363
node_modules/simple-get/test/basic.js
generated
vendored
Normal file
@@ -0,0 +1,363 @@
|
||||
var concat = require('concat-stream')
|
||||
var http = require('http')
|
||||
var get = require('../')
|
||||
var selfSignedHttps = require('self-signed-https')
|
||||
var str = require('string-to-stream')
|
||||
var test = require('tape')
|
||||
var zlib = require('zlib')
|
||||
|
||||
// Allow self-signed certs
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
|
||||
|
||||
test('simple get', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
var server = http.createServer(function (req, res) {
|
||||
t.equal(req.url, '/path')
|
||||
res.statusCode = 200
|
||||
res.end('response')
|
||||
})
|
||||
|
||||
server.listen(0, function () {
|
||||
var port = server.address().port
|
||||
get('http://localhost:' + port + '/path', function (err, res) {
|
||||
t.error(err)
|
||||
t.equal(res.statusCode, 200)
|
||||
res.pipe(concat(function (data) {
|
||||
t.equal(data.toString(), 'response')
|
||||
server.close()
|
||||
}))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('follow redirects (up to 10)', function (t) {
|
||||
t.plan(13)
|
||||
|
||||
var num = 1
|
||||
var server = http.createServer(function (req, res) {
|
||||
t.equal(req.url, '/' + num, 'visited /' + num)
|
||||
num += 1
|
||||
|
||||
if (num <= 10) {
|
||||
res.statusCode = 301
|
||||
res.setHeader('Location', '/' + num)
|
||||
res.end()
|
||||
} else {
|
||||
res.statusCode = 200
|
||||
res.end('response')
|
||||
}
|
||||
})
|
||||
|
||||
server.listen(0, function () {
|
||||
var port = server.address().port
|
||||
get('http://localhost:' + port + '/1', function (err, res) {
|
||||
t.error(err)
|
||||
t.equal(res.statusCode, 200)
|
||||
res.pipe(concat(function (data) {
|
||||
t.equal(data.toString(), 'response')
|
||||
server.close()
|
||||
}))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('do not follow redirects', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var server = http.createServer(function (req, res) {
|
||||
t.equal(req.url, '/1', 'visited /1')
|
||||
|
||||
res.statusCode = 301
|
||||
res.setHeader('Location', '/2')
|
||||
res.end()
|
||||
})
|
||||
|
||||
server.listen(0, function () {
|
||||
var port = server.address().port
|
||||
get({
|
||||
url: 'http://localhost:' + port + '/1',
|
||||
maxRedirects: 0
|
||||
}, function (err) {
|
||||
t.ok(err instanceof Error, 'got error')
|
||||
server.close()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('follow redirects (11 is too many)', function (t) {
|
||||
t.plan(11)
|
||||
|
||||
var num = 1
|
||||
var server = http.createServer(function (req, res) {
|
||||
t.equal(req.url, '/' + num, 'visited /' + num)
|
||||
num += 1
|
||||
|
||||
res.statusCode = 301
|
||||
res.setHeader('Location', '/' + num)
|
||||
res.end()
|
||||
})
|
||||
|
||||
server.listen(0, function () {
|
||||
var port = server.address().port
|
||||
get('http://localhost:' + port + '/1', function (err) {
|
||||
t.ok(err instanceof Error, 'got error')
|
||||
server.close()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('custom headers', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var server = http.createServer(function (req, res) {
|
||||
t.equal(req.headers['custom-header'], 'custom-value')
|
||||
res.statusCode = 200
|
||||
res.end('response')
|
||||
})
|
||||
|
||||
server.listen(0, function () {
|
||||
var port = server.address().port
|
||||
get({
|
||||
url: 'http://localhost:' + port,
|
||||
headers: {
|
||||
'custom-header': 'custom-value'
|
||||
}
|
||||
}, function (err, res) {
|
||||
t.error(err)
|
||||
res.resume()
|
||||
server.close()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('gzip response', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
var server = http.createServer(function (req, res) {
|
||||
res.statusCode = 200
|
||||
res.setHeader('content-encoding', 'gzip')
|
||||
str('response').pipe(zlib.createGzip()).pipe(res)
|
||||
})
|
||||
|
||||
server.listen(0, function () {
|
||||
var port = server.address().port
|
||||
get('http://localhost:' + port, function (err, res) {
|
||||
t.error(err)
|
||||
t.equal(res.statusCode, 200) // statusCode still works on gunzip stream
|
||||
res.pipe(concat(function (data) {
|
||||
t.equal(data.toString(), 'response')
|
||||
server.close()
|
||||
}))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('deflate response', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
var server = http.createServer(function (req, res) {
|
||||
res.statusCode = 200
|
||||
res.setHeader('content-encoding', 'deflate')
|
||||
str('response').pipe(zlib.createDeflate()).pipe(res)
|
||||
})
|
||||
|
||||
server.listen(0, function () {
|
||||
var port = server.address().port
|
||||
get('http://localhost:' + port, function (err, res) {
|
||||
t.error(err)
|
||||
t.equal(res.statusCode, 200) // statusCode still works on inflate stream
|
||||
res.pipe(concat(function (data) {
|
||||
t.equal(data.toString(), 'response')
|
||||
server.close()
|
||||
}))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('https', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
var server = selfSignedHttps(function (req, res) {
|
||||
t.equal(req.url, '/path')
|
||||
res.statusCode = 200
|
||||
res.end('response')
|
||||
})
|
||||
|
||||
server.listen(0, function () {
|
||||
var port = server.address().port
|
||||
get('https://localhost:' + port + '/path', function (err, res) {
|
||||
t.error(err)
|
||||
t.equal(res.statusCode, 200)
|
||||
res.pipe(concat(function (data) {
|
||||
t.equal(data.toString(), 'response')
|
||||
server.close()
|
||||
}))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('redirect https to http', function (t) {
|
||||
t.plan(5)
|
||||
|
||||
var httpPort = null
|
||||
var httpsPort = null
|
||||
|
||||
var httpsServer = selfSignedHttps(function (req, res) {
|
||||
t.equal(req.url, '/path1')
|
||||
res.statusCode = 301
|
||||
res.setHeader('Location', 'http://localhost:' + httpPort + '/path2')
|
||||
res.end()
|
||||
})
|
||||
|
||||
var httpServer = http.createServer(function (req, res) {
|
||||
t.equal(req.url, '/path2')
|
||||
res.statusCode = 200
|
||||
res.end('response')
|
||||
})
|
||||
|
||||
httpsServer.listen(0, function () {
|
||||
httpsPort = httpsServer.address().port
|
||||
httpServer.listen(0, function () {
|
||||
httpPort = httpServer.address().port
|
||||
get('https://localhost:' + httpsPort + '/path1', function (err, res) {
|
||||
t.error(err)
|
||||
t.equal(res.statusCode, 200)
|
||||
res.pipe(concat(function (data) {
|
||||
t.equal(data.toString(), 'response')
|
||||
httpsServer.close()
|
||||
httpServer.close()
|
||||
}))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('redirect http to https', function (t) {
|
||||
t.plan(5)
|
||||
|
||||
var httpsPort = null
|
||||
var httpPort = null
|
||||
|
||||
var httpServer = http.createServer(function (req, res) {
|
||||
t.equal(req.url, '/path1')
|
||||
res.statusCode = 301
|
||||
res.setHeader('Location', 'https://localhost:' + httpsPort + '/path2')
|
||||
res.end()
|
||||
})
|
||||
|
||||
var httpsServer = selfSignedHttps(function (req, res) {
|
||||
t.equal(req.url, '/path2')
|
||||
res.statusCode = 200
|
||||
res.end('response')
|
||||
})
|
||||
|
||||
httpServer.listen(0, function () {
|
||||
httpPort = httpServer.address().port
|
||||
httpsServer.listen(0, function () {
|
||||
httpsPort = httpsServer.address().port
|
||||
get('http://localhost:' + httpPort + '/path1', function (err, res) {
|
||||
t.error(err)
|
||||
t.equal(res.statusCode, 200)
|
||||
res.pipe(concat(function (data) {
|
||||
t.equal(data.toString(), 'response')
|
||||
httpsServer.close()
|
||||
httpServer.close()
|
||||
}))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('post (text body)', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
var server = http.createServer(function (req, res) {
|
||||
t.equal(req.method, 'POST')
|
||||
res.statusCode = 200
|
||||
req.pipe(res)
|
||||
})
|
||||
|
||||
server.listen(0, function () {
|
||||
var port = server.address().port
|
||||
var opts = {
|
||||
url: 'http://localhost:' + port,
|
||||
body: 'this is the body'
|
||||
}
|
||||
get.post(opts, function (err, res) {
|
||||
t.error(err)
|
||||
t.equal(res.statusCode, 200)
|
||||
res.pipe(concat(function (data) {
|
||||
t.equal(data.toString(), 'this is the body')
|
||||
server.close()
|
||||
}))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('post (buffer body)', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
var server = http.createServer(function (req, res) {
|
||||
t.equal(req.method, 'POST')
|
||||
res.statusCode = 200
|
||||
req.pipe(res)
|
||||
})
|
||||
|
||||
server.listen(0, function () {
|
||||
var port = server.address().port
|
||||
var opts = {
|
||||
url: 'http://localhost:' + port,
|
||||
body: new Buffer('this is the body')
|
||||
}
|
||||
get.post(opts, function (err, res) {
|
||||
t.error(err)
|
||||
t.equal(res.statusCode, 200)
|
||||
res.pipe(concat(function (data) {
|
||||
t.equal(data.toString(), 'this is the body')
|
||||
server.close()
|
||||
}))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('get.concat', function (t) {
|
||||
t.plan(4)
|
||||
var server = http.createServer(function (req, res) {
|
||||
res.statusCode = 200
|
||||
res.end('blah blah blah')
|
||||
})
|
||||
|
||||
server.listen(0, function () {
|
||||
var port = server.address().port
|
||||
get.concat('http://localhost:' + port, function (err, data, res) {
|
||||
t.error(err)
|
||||
t.equal(res.statusCode, 200)
|
||||
t.ok(Buffer.isBuffer(data), '`data` is type buffer')
|
||||
t.equal(data.toString(), 'blah blah blah')
|
||||
server.close()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('access `req` object', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var server = http.createServer(function (req, res) {
|
||||
res.statusCode = 200
|
||||
res.end('response')
|
||||
})
|
||||
|
||||
server.listen(0, function () {
|
||||
var port = server.address().port
|
||||
var req = get('http://localhost:' + port, function (err, res) {
|
||||
t.error(err)
|
||||
res.resume() // discard data
|
||||
server.close()
|
||||
})
|
||||
|
||||
req.on('socket', function () {
|
||||
t.pass('got `socket` event')
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user