Comparing version 3.11.0 to 3.13.0
@@ -37,3 +37,3 @@ var window = require('global') | ||
do { | ||
name = '_' + randomString({length: 20}) | ||
name = '_' + randomString({ length: 20 }) | ||
} while (typeof window[name] !== 'undefined') | ||
@@ -40,0 +40,0 @@ |
@@ -1,2 +0,2 @@ | ||
var merge = require('./merge') | ||
var deepExtend = require('./deepExtend') | ||
var resolveUrl = require('./resolveUrl') | ||
@@ -26,3 +26,3 @@ | ||
} else { | ||
var options = mergeClientOptions(_options, this._options) | ||
var options = mergeClientOptions(this._options, _options) | ||
request = { | ||
@@ -142,3 +142,3 @@ method: method, | ||
resolveUrl(this.url, args.url), | ||
mergeClientOptions(args.options, this._options), | ||
mergeClientOptions(this._options, args.options), | ||
this.middleware.slice() | ||
@@ -245,7 +245,8 @@ ) | ||
function mergeClientOptions (x, y) { | ||
var z = merge(x, y) | ||
if (z && z.headers) { z.headers = merge(x && x.headers, y && y.headers) } | ||
return z | ||
var r = {} | ||
deepExtend(r, x || {}) | ||
deepExtend(r, y || {}) | ||
return r | ||
} | ||
module.exports = client |
@@ -14,2 +14,5 @@ var extend = require('./extend') | ||
var param = params[id] | ||
if (param === undefined) { | ||
throw new Error('No value for :' + id + '*') | ||
} | ||
delete onlyQueryParams[id] | ||
@@ -21,2 +24,5 @@ return encodeURI(paramToString(param)) | ||
var param = params[id] | ||
if (param === undefined) { | ||
throw new Error('No value for :' + id) | ||
} | ||
delete onlyQueryParams[id] | ||
@@ -23,0 +29,0 @@ return encodeURIComponent(paramToString(param)) |
var debug = require('debug')('httpism:cache') | ||
var fileStore = require('./fileStore') | ||
var urlUtils = require('url') | ||
var URL = require('url').URL | ||
var pathUtils = require('path') | ||
@@ -10,3 +10,3 @@ | ||
} else { | ||
var parsedUrl = urlUtils.parse(url) | ||
var parsedUrl = new URL(url) | ||
return parsedUrl.protocol || 'file' | ||
@@ -13,0 +13,0 @@ } |
var fs = require('fs-promise') | ||
var PassThrough = require('stream').PassThrough | ||
var urlUtils = require('url') | ||
@@ -15,5 +14,3 @@ function writeStreamToFile (filename, stream) { | ||
module.exports = function (options) { | ||
var url = typeof options === 'object' && options.hasOwnProperty('url') ? options.url : undefined | ||
var parsedUrl = urlUtils.parse(url) | ||
var path = parsedUrl.path | ||
var path = typeof options === 'object' && options.hasOwnProperty('url') ? options.url : undefined | ||
@@ -20,0 +17,0 @@ return { |
@@ -5,3 +5,3 @@ var middleware = require('./middleware') | ||
var proxyForUrl = require('proxy-from-env').getProxyForUrl | ||
var urlUtils = require('url') | ||
var URL = require('url').URL | ||
var merge = require('../merge') | ||
@@ -20,4 +20,4 @@ var HttpsProxyAgent = require('https-proxy-agent') | ||
function proxyUrl (request, proxy) { | ||
var url = urlUtils.parse(request.url) | ||
var proxyUrl = urlUtils.parse(proxy) | ||
var url = new URL(request.url) | ||
var proxyUrl = new URL(proxy) | ||
@@ -34,6 +34,11 @@ request.headers.host = url.hostname | ||
var split = request.url.split('?') | ||
var pathname = split[0] | ||
var search = split[1] || '' | ||
return { | ||
hostname: proxyUrl.hostname, | ||
port: proxyUrl.port, | ||
path: request.url | ||
protocol: proxyUrl.protocol, | ||
pathname: pathname, | ||
search: search | ||
} | ||
@@ -49,3 +54,3 @@ } | ||
} else { | ||
return urlUtils.parse(request.url) | ||
return new URL(request.url) | ||
} | ||
@@ -63,3 +68,3 @@ } | ||
method: request.method, | ||
path: url.path, | ||
path: url.pathname + url.search, | ||
headers: request.headers, | ||
@@ -66,0 +71,0 @@ agent: url.agent |
@@ -9,3 +9,3 @@ var middleware = require('./middleware') | ||
do { | ||
name = '_' + randomString({length: 20}) | ||
name = '_' + randomString({ length: 20 }) | ||
} while (typeof window[name] !== 'undefined') | ||
@@ -12,0 +12,0 @@ |
{ | ||
"name": "httpism", | ||
"version": "3.11.0", | ||
"version": "3.13.0", | ||
"description": "HTTP client with middleware and good defaults", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"base-64": "0.1.0", | ||
"debug": "3.1.0", | ||
"debug": "4.1.1", | ||
"end-of-stream": "1.4.1", | ||
@@ -14,33 +14,33 @@ "fs-promise": "2.0.3", | ||
"https-proxy-agent": "2.2.1", | ||
"mime-types": "2.1.18", | ||
"mime-types": "2.1.22", | ||
"proxy-from-env": "1.0.0", | ||
"random-string": "0.2.0", | ||
"tough-cookie": "2.3.4", | ||
"underscore": "1.8.3" | ||
"tough-cookie": "3.0.1", | ||
"underscore": "1.9.1" | ||
}, | ||
"devDependencies": { | ||
"basic-auth": "2.0.0", | ||
"basic-auth": "2.0.1", | ||
"basic-auth-connect": "1.0.0", | ||
"body-parser": "1.18.2", | ||
"browserify": "16.1.0", | ||
"chai": "4.1.2", | ||
"body-parser": "1.18.3", | ||
"browserify": "16.2.3", | ||
"chai": "4.2.0", | ||
"chai-as-promised": "7.1.1", | ||
"cookie-parser": "1.4.3", | ||
"cors": "2.8.4", | ||
"electron": "2.0.5", | ||
"es6-promise": "4.2.4", | ||
"eslint": "4.18.1", | ||
"eslint-config-standard": "11.0.0", | ||
"eslint-plugin-es5": "1.2.0", | ||
"eslint-plugin-import": "2.9.0", | ||
"eslint-plugin-node": "6.0.1", | ||
"eslint-plugin-promise": "3.6.0", | ||
"eslint-plugin-standard": "3.0.1", | ||
"express": "4.16.2", | ||
"cookie-parser": "1.4.4", | ||
"cors": "2.8.5", | ||
"electron": "4.1.3", | ||
"es6-promise": "4.2.6", | ||
"eslint": "5.16.0", | ||
"eslint-config-standard": "12.0.0", | ||
"eslint-plugin-es5": "1.3.1", | ||
"eslint-plugin-import": "2.16.0", | ||
"eslint-plugin-node": "8.0.1", | ||
"eslint-plugin-promise": "4.1.1", | ||
"eslint-plugin-standard": "4.0.0", | ||
"express": "4.16.4", | ||
"fake-xml-http-request": "2.0.0", | ||
"form-data": "2.3.2", | ||
"http-proxy": "1.16.2", | ||
"karma": "2.0.0", | ||
"karma-browserify": "5.2.0", | ||
"karma-browserstack-launcher": "1.3.0", | ||
"form-data": "2.3.3", | ||
"http-proxy": "1.17.0", | ||
"karma": "4.0.1", | ||
"karma-browserify": "6.0.0", | ||
"karma-browserstack-launcher": "1.5.0", | ||
"karma-chrome-launcher": "2.2.0", | ||
@@ -51,11 +51,11 @@ "karma-electron-launcher": "^0.2.0", | ||
"karma-server-side": "1.7.0", | ||
"mocha": "5.0.1", | ||
"multiparty": "4.1.3", | ||
"qs": "6.5.1", | ||
"mocha": "6.0.2", | ||
"multiparty": "4.2.1", | ||
"qs": "6.7.0", | ||
"server-destroy": "1.0.1", | ||
"standard": "11.0.0", | ||
"uglify-js": "3.3.12", | ||
"standard": "12.0.1", | ||
"uglify-js": "3.5.3", | ||
"url-template": "2.0.8", | ||
"watchify": "3.10.0", | ||
"webpack": "4.0.1" | ||
"watchify": "3.11.1", | ||
"webpack": "4.29.6" | ||
}, | ||
@@ -62,0 +62,0 @@ "directories": { |
@@ -240,2 +240,4 @@ # httpism [![npm version](https://img.shields.io/npm/v/httpism.svg)](https://www.npmjs.com/package/httpism) [![npm](https://img.shields.io/npm/dm/httpism.svg)](https://www.npmjs.com/package/httpism) [![Build Status](https://travis-ci.org/featurist/httpism.svg?branch=master)](https://travis-ci.org/featurist/httpism) | ||
The template interpolation will throw an error if one of the `:param` or `:param*` parameters are given an `undefined` value. | ||
The template interpolation itself can be overridden with the `expandUrl` option, and is used as follows: | ||
@@ -242,0 +244,0 @@ |
@@ -7,3 +7,3 @@ var express = require('express') | ||
var fs = require('fs-promise') | ||
var middleware = require('../../middleware') | ||
var streamToString = require('../../streamToString') | ||
var basicAuth = require('basic-auth-connect') | ||
@@ -14,6 +14,6 @@ | ||
app.use(bodyParser.text()) | ||
app.use(bodyParser.urlencoded({extended: true})) | ||
app.use(bodyParser.urlencoded({ extended: true })) | ||
app.use(cookieParser()) | ||
var cors = corsMiddleware({credentials: true, origin: true}) | ||
var cors = corsMiddleware({ credentials: true, origin: true }) | ||
@@ -80,3 +80,3 @@ function respond (req, res) { | ||
console.log(err) | ||
res.status(500).send({message: err.message}) | ||
res.status(500).send({ message: err.message }) | ||
} | ||
@@ -90,3 +90,3 @@ var response = {} | ||
var file = files[field][0] | ||
return middleware.streamToString(fs.createReadStream(file.path)).then(function (contents) { | ||
return streamToString(fs.createReadStream(file.path)).then(function (contents) { | ||
response[field] = { | ||
@@ -93,0 +93,0 @@ contents: contents, |
@@ -32,3 +32,3 @@ /* eslint-env mocha */ | ||
it('can make a JSON GET request', function () { | ||
return httpism.get('/', {response: true}).then(function (response) { | ||
return httpism.get('/', { response: true }).then(function (response) { | ||
expect(response.body.method).to.equal('GET') | ||
@@ -42,5 +42,5 @@ expect(response.body.url).to.equal('/') | ||
it('can GET with query string', function () { | ||
return httpism.get('/', {response: true, params: {a: 'b', b: 'c', c: 'd'}}).then(function (response) { | ||
return httpism.get('/', { response: true, params: { a: 'b', b: 'c', c: 'd' } }).then(function (response) { | ||
expect(response.body.method).to.equal('GET') | ||
expect(response.body.query).to.eql({a: 'b', b: 'c', c: 'd'}) | ||
expect(response.body.query).to.eql({ a: 'b', b: 'c', c: 'd' }) | ||
expect(response.body.url).to.equal('/?a=b&b=c&c=d') | ||
@@ -72,4 +72,4 @@ expect(response.headers['content-type']).to.equal('application/json; charset=utf-8') | ||
it('can call JSONP', function () { | ||
return httpism.get(server + '/jsonp', {jsonp: 'callback'}).then(function (body) { | ||
expect(body).to.eql({blah: 'blah'}) | ||
return httpism.get(server + '/jsonp', { jsonp: 'callback' }).then(function (body) { | ||
expect(body).to.eql({ blah: 'blah' }) | ||
}) | ||
@@ -79,3 +79,3 @@ }) | ||
it('throws exception if there is an error', function () { | ||
return expect(httpism.get(server + '/404', {jsonp: 'callback'})).to.be.rejectedWith(server + '/404') | ||
return expect(httpism.get(server + '/404', { jsonp: 'callback' })).to.be.rejectedWith(server + '/404') | ||
}) | ||
@@ -85,3 +85,3 @@ }) | ||
it('can send and receive cookies', function () { | ||
return httpism.get('/cookies', {params: {a: 'b'}}).then(function () { | ||
return httpism.get('/cookies', { params: { a: 'b' } }).then(function () { | ||
expect(document.cookie).to.include('a=b') | ||
@@ -96,7 +96,7 @@ return httpism.get('/').then(function (body) { | ||
beforeEach(function () { | ||
return httpism.get(server + '/cookies', {params: {a: ''}, withCredentials: true}) | ||
return httpism.get(server + '/cookies', { params: { a: '' }, withCredentials: true }) | ||
}) | ||
it("by default, doesn't send cookies cross-domain", function () { | ||
return httpism.get(server + '/cookies', {params: {a: 'b'}, withCredentials: true}).then(function () { | ||
return httpism.get(server + '/cookies', { params: { a: 'b' }, withCredentials: true }).then(function () { | ||
return httpism.get(server + '/').then(function (body) { | ||
@@ -109,4 +109,4 @@ expect(body.cookies.a).to.equal(undefined) | ||
it('withCredentials = true, sends cookies cross-domain', function () { | ||
return httpism.get(server + '/cookies', {params: {a: 'b'}, withCredentials: true}).then(function () { | ||
return httpism.get(server + '/', {withCredentials: true}).then(function (body) { | ||
return httpism.get(server + '/cookies', { params: { a: 'b' }, withCredentials: true }).then(function () { | ||
return httpism.get(server + '/', { withCredentials: true }).then(function (body) { | ||
expect(body.cookies.a).to.equal('b') | ||
@@ -134,4 +134,4 @@ }) | ||
it('can make a json post request', function () { | ||
return httpism.post('/', {data: 'hehey'}, {response: true}).then(function (response) { | ||
expect(response.body.body).to.eql({data: 'hehey'}) | ||
return httpism.post('/', { data: 'hehey' }, { response: true }).then(function (response) { | ||
expect(response.body.body).to.eql({ data: 'hehey' }) | ||
expect(response.body.headers['content-type']).to.equal('application/json') | ||
@@ -144,4 +144,4 @@ expect(response.headers['content-type']).to.equal('application/json; charset=utf-8') | ||
it('can make a cross-origin json post request', function () { | ||
return httpism.post(server + '/', {data: 'hehey'}, {response: true}).then(function (response) { | ||
expect(response.body.body).to.eql({data: 'hehey'}) | ||
return httpism.post(server + '/', { data: 'hehey' }, { response: true }).then(function (response) { | ||
expect(response.body.body).to.eql({ data: 'hehey' }) | ||
expect(response.body.headers['content-type']).to.equal('application/json') | ||
@@ -154,3 +154,3 @@ expect(response.headers['content-type']).to.equal('application/json; charset=utf-8') | ||
it('can make a text post request', function () { | ||
return httpism.post('/', 'hehey', {response: true}).then(function (response) { | ||
return httpism.post('/', 'hehey', { response: true }).then(function (response) { | ||
expect(response.body.body).to.eql('hehey') | ||
@@ -164,4 +164,4 @@ expect(response.body.headers['content-type']).to.equal('text/plain;charset=UTF-8') | ||
it('can make a form post request', function () { | ||
return httpism.post('/', {message: 'hehey', to: 'bob'}, {response: true, form: true}).then(function (response) { | ||
expect(response.body.body).to.eql({message: 'hehey', to: 'bob'}) | ||
return httpism.post('/', { message: 'hehey', to: 'bob' }, { response: true, form: true }).then(function (response) { | ||
expect(response.body.body).to.eql({ message: 'hehey', to: 'bob' }) | ||
expect(response.body.headers['content-type']).to.equal('application/x-www-form-urlencoded') | ||
@@ -176,3 +176,3 @@ expect(response.headers['content-type']).to.equal('application/json; charset=utf-8') | ||
data.append('name', 'joe') | ||
data.append('file', new File(['file content'], 'file.txt', {type: 'text/plain'})) | ||
data.append('file', new File(['file content'], 'file.txt', { type: 'text/plain' })) | ||
return httpism.post('/form', data).then(function (body) { | ||
@@ -195,4 +195,4 @@ expect(body).to.eql({ | ||
it('can make a json put request', function () { | ||
return httpism.put('/', {data: 'hehey'}, {response: true}).then(function (response) { | ||
expect(response.body.body).to.eql({data: 'hehey'}) | ||
return httpism.put('/', { data: 'hehey' }, { response: true }).then(function (response) { | ||
expect(response.body.body).to.eql({ data: 'hehey' }) | ||
expect(response.body.headers['content-type']).to.equal('application/json') | ||
@@ -264,3 +264,3 @@ expect(response.headers['content-type']).to.equal('application/json; charset=utf-8') | ||
it('can respond with 204 and empty body', function () { | ||
return httpism.delete('/delete', {response: true}).then(function (response) { | ||
return httpism.delete('/delete', { response: true }).then(function (response) { | ||
expect(response.statusCode).to.equal(204) | ||
@@ -290,5 +290,5 @@ expect(response.body).to.equal(undefined) | ||
FakeXMLHttpRequest.prototype.onSend = function (xhr) { | ||
xhr.respond(200, {'Content-Type': 'text/plain'}, 'faked response') | ||
xhr.respond(200, { 'Content-Type': 'text/plain' }, 'faked response') | ||
} | ||
return httpism.get('/', {xhr: FakeXMLHttpRequest}).then(function (body) { | ||
return httpism.get('/', { xhr: FakeXMLHttpRequest }).then(function (body) { | ||
expect(body).to.equal('faked response') | ||
@@ -301,3 +301,3 @@ }) | ||
it('can specify basic authentication', function () { | ||
return httpism.get('/private', {basicAuth: {username: 'user', password: 'good'}}).then(function (body) { | ||
return httpism.get('/private', { basicAuth: { username: 'user', password: 'good' } }).then(function (body) { | ||
expect(body).to.equal('private') | ||
@@ -308,3 +308,3 @@ }) | ||
it('returns 401 when unauthorized', function () { | ||
return httpism.get('/private', {basicAuth: {username: 'user', password: 'bad'}, response: true, exceptions: false}).then(function (response) { | ||
return httpism.get('/private', { basicAuth: { username: 'user', password: 'bad' }, response: true, exceptions: false }).then(function (response) { | ||
expect(response.statusCode).to.equal(401) | ||
@@ -311,0 +311,0 @@ }) |
@@ -9,3 +9,3 @@ /* eslint-env mocha */ | ||
it('overrides existing params', function () { | ||
var url = expandUrl('https://example.com/?existing=asdf', {newparam: 'fdsa'}) | ||
var url = expandUrl('https://example.com/?existing=asdf', { newparam: 'fdsa' }) | ||
expect(url).to.equal('https://example.com/?existing=asdf&newparam=fdsa') | ||
@@ -15,11 +15,19 @@ }) | ||
it('replaces simple path params encoding as necessary', function () { | ||
var url = expandUrl('https://example.com/path/:param/file', {param: 'one/two'}) | ||
var url = expandUrl('https://example.com/path/:param/file', { param: 'one/two' }) | ||
expect(url).to.equal('https://example.com/path/one%2Ftwo/file') | ||
}) | ||
it('throws an error when a simple path param is missing', function () { | ||
expect(function () { expandUrl('https://example.com/path/:param/file', {}) }).to.throw('No value for :param') | ||
}) | ||
it('replaces full path params', function () { | ||
var url = expandUrl('https://example.com/path/:param*/file', {param: 'one/two'}) | ||
var url = expandUrl('https://example.com/path/:param*/file', { param: 'one/two' }) | ||
expect(url).to.equal('https://example.com/path/one/two/file') | ||
}) | ||
it('throws an error when a full path param is missing', function () { | ||
expect(function () { expandUrl('https://example.com/path/:param*/file', {}) }).to.throw('No value for :param*') | ||
}) | ||
it('maintains hash', function () { | ||
@@ -26,0 +34,0 @@ var url = expandUrl('https://example.com/path#hash', {}) |
@@ -14,3 +14,3 @@ /* eslint-env mocha */ | ||
var qs = require('qs') | ||
var middleware = require('../middleware') | ||
var streamToString = require('../streamToString') | ||
var basicAuthConnect = require('basic-auth-connect') | ||
@@ -284,3 +284,3 @@ var basicAuth = require('basic-auth') | ||
return httpism.post(baseurl + '/text', 'content as string', {response: true}).then(function (response) { | ||
return httpism.post(baseurl + '/text', 'content as string', { response: true }).then(function (response) { | ||
expect(response.headers['received-content-type']).to.equal('text/plain') | ||
@@ -332,3 +332,3 @@ expect(response.body).to.equal('content as string') | ||
}).then(function (body) { | ||
expect(body).to.eql({name: 'user', pass: 'pass'}) | ||
expect(body).to.eql({ name: 'user', pass: 'pass' }) | ||
}) | ||
@@ -367,53 +367,94 @@ }) | ||
describe('.client()', function () { | ||
it('can make a new client that adds headers', function () { | ||
app.get('/', function (req, res) { | ||
res.send({ | ||
joke: req.headers.joke | ||
describe('options', function () { | ||
it('can make a new client that adds headers', function () { | ||
app.get('/', function (req, res) { | ||
res.send({ | ||
joke: req.headers.joke | ||
}) | ||
}) | ||
}) | ||
var client = httpism.client(function (request, next) { | ||
request.headers.joke = 'a chicken...' | ||
return next(request) | ||
}) | ||
var client = httpism.client(function (request, next) { | ||
request.headers.joke = 'a chicken...' | ||
return next(request) | ||
}) | ||
return client.get(baseurl).then(function (body) { | ||
expect(body).to.eql({ | ||
joke: 'a chicken...' | ||
return client.get(baseurl).then(function (body) { | ||
expect(body).to.eql({ | ||
joke: 'a chicken...' | ||
}) | ||
}) | ||
}) | ||
}) | ||
it('can make a new client that adds headers by passing them to options', function () { | ||
app.get('/', function (req, res) { | ||
res.send({ | ||
x: req.headers.x, | ||
y: req.headers.y | ||
it('can make a new client that adds headers by passing them to options', function () { | ||
app.get('/', function (req, res) { | ||
res.send({ | ||
x: req.headers.x, | ||
y: req.headers.y | ||
}) | ||
}) | ||
var client = httpism.client('/', { headers: { x: '123' } }).client('/', { headers: { y: '456' } }) | ||
return client.get(baseurl).then(function (body) { | ||
expect(body).to.eql({ | ||
x: '123', | ||
y: '456' | ||
}) | ||
}) | ||
}) | ||
var client = httpism.client('/', { headers: { x: '123' } }).client('/', { headers: { y: '456' } }) | ||
it('can specify options in client, and override with another client', function () { | ||
app.get('/', function (req, res) { | ||
res.send({ | ||
x: req.query.x, | ||
y: req.query.y | ||
}) | ||
}) | ||
return client.get(baseurl).then(function (body) { | ||
expect(body).to.eql({ | ||
x: '123', | ||
y: '456' | ||
var client = httpism | ||
.client('/', { params: { x: 'original x', y: 'original y' } }) | ||
.client('/', { params: { y: 'new y' } }) | ||
return client.get(baseurl).then(function (body) { | ||
expect(body).to.eql({ | ||
x: 'original x', | ||
y: 'new y' | ||
}) | ||
}) | ||
}) | ||
}) | ||
it('makes requests with additional headers', function () { | ||
app.get('/', function (req, res) { | ||
res.send({ | ||
x: req.headers.x, | ||
y: req.headers.y | ||
it('can specify options in client, and override them when making request', function () { | ||
app.get('/', function (req, res) { | ||
res.send({ | ||
x: req.query.x, | ||
y: req.query.y | ||
}) | ||
}) | ||
var client = httpism | ||
.client('/', { params: { x: 'original x', y: 'original y' } }) | ||
return client.get(baseurl, { params: { y: 'new y' } }).then(function (body) { | ||
expect(body).to.eql({ | ||
x: 'original x', | ||
y: 'new y' | ||
}) | ||
}) | ||
}) | ||
var client = httpism.client({ headers: { x: '123' } }) | ||
it('makes requests with additional headers', function () { | ||
app.get('/', function (req, res) { | ||
res.send({ | ||
x: req.headers.x, | ||
y: req.headers.y | ||
}) | ||
}) | ||
return client.get(baseurl, { headers: { y: '456' } }).then(function (body) { | ||
expect(body).to.eql({ | ||
x: '123', | ||
y: '456' | ||
var client = httpism.client({ headers: { x: '123' } }) | ||
return client.get(baseurl, { headers: { y: '456' } }).then(function (body) { | ||
expect(body).to.eql({ | ||
x: '123', | ||
y: '456' | ||
}) | ||
}) | ||
@@ -436,3 +477,3 @@ }) | ||
app.get('/', function (req, res) { | ||
res.send({from: 'server'}) | ||
res.send({ from: 'server' }) | ||
}) | ||
@@ -454,3 +495,3 @@ | ||
return http.get(baseurl).then(function (body) { | ||
expect(body).to.eql({from: 'cache'}) | ||
expect(body).to.eql({ from: 'cache' }) | ||
}) | ||
@@ -479,3 +520,3 @@ }) | ||
return client.get('/').then(function (response) { | ||
expect(response).to.eql({param: 'hi'}) | ||
expect(response).to.eql({ param: 'hi' }) | ||
}) | ||
@@ -494,3 +535,3 @@ }) | ||
return client.get('/').then(function (response) { | ||
expect(response).to.eql({param: 'hi'}) | ||
expect(response).to.eql({ param: 'hi' }) | ||
}) | ||
@@ -844,5 +885,5 @@ }) | ||
app.get('/', function (req, res) { | ||
res.set({'x-custom-header': 'header value'}) | ||
res.set({ 'x-custom-header': 'header value' }) | ||
res.status(234) | ||
res.send({data: 'data'}) | ||
res.send({ data: 'data' }) | ||
}) | ||
@@ -855,3 +896,3 @@ }) | ||
beforeEach(function () { | ||
return httpism.get(baseurl, {response: true}).then(function (_response) { | ||
return httpism.get(baseurl, { response: true }).then(function (_response) { | ||
response = _response | ||
@@ -874,3 +915,3 @@ }) | ||
it('contains the body', function () { | ||
expect(response.body).to.eql({data: 'data'}) | ||
expect(response.body).to.eql({ data: 'data' }) | ||
}) | ||
@@ -902,3 +943,3 @@ }) | ||
it('contains the body', function () { | ||
expect(body.body).to.eql({data: 'data'}) | ||
expect(body.body).to.eql({ data: 'data' }) | ||
}) | ||
@@ -908,3 +949,3 @@ }) | ||
it('returns the body', function () { | ||
expect(body).to.eql({data: 'data'}) | ||
expect(body).to.eql({ data: 'data' }) | ||
}) | ||
@@ -944,3 +985,3 @@ }) | ||
it('follows redirects by default', function () { | ||
return httpism.get(baseurl + '/redirect', {response: true}).then(function (response) { | ||
return httpism.get(baseurl + '/redirect', { response: true }).then(function (response) { | ||
expect(response.body).to.eql({ | ||
@@ -960,3 +1001,3 @@ path: '/path/' | ||
return httpism.get(baseurl + '/' + statusCode, {response: true}).then(function (response) { | ||
return httpism.get(baseurl + '/' + statusCode, { response: true }).then(function (response) { | ||
expect(response.body).to.eql({ | ||
@@ -979,3 +1020,3 @@ path: '/path/' | ||
it('follows a more than one redirect', function () { | ||
return httpism.get(baseurl + '/redirecttoredirect', {response: true}).then(function (response) { | ||
return httpism.get(baseurl + '/redirecttoredirect', { response: true }).then(function (response) { | ||
expect(response.body).to.eql({ | ||
@@ -1104,3 +1145,3 @@ path: '/path/' | ||
return httpism.get(baseurl + '/form', {response: true}).then(function (response) { | ||
return httpism.get(baseurl + '/form', { response: true }).then(function (response) { | ||
expect(response.body).to.eql({ | ||
@@ -1132,3 +1173,3 @@ name: 'Betty Boop', | ||
console.log(err) | ||
res.status(500).send({message: err.message}) | ||
res.status(500).send({ message: err.message }) | ||
} | ||
@@ -1142,3 +1183,3 @@ var response = {} | ||
var file = files[field][0] | ||
return middleware.streamToString(fs.createReadStream(file.path)).then(function (contents) { | ||
return streamToString(fs.createReadStream(file.path)).then(function (contents) { | ||
response[field] = { | ||
@@ -1291,3 +1332,3 @@ contents: contents, | ||
return httpism.post(baseurl + '/file', stream, {response: true}).then(function (response) { | ||
return httpism.post(baseurl + '/file', stream, { response: true }).then(function (response) { | ||
expect(response.headers['received-content-type']).to.equal('text/plain') | ||
@@ -1299,5 +1340,5 @@ expect(response.body).to.equal('received: some content') | ||
it('can download a stream', function () { | ||
return httpism.get(baseurl + '/file', {response: true}).then(function (response) { | ||
return httpism.get(baseurl + '/file', { response: true }).then(function (response) { | ||
expect(response.headers['content-type']).to.equal('application/blah') | ||
return middleware.streamToString(response.body).then(function (response) { | ||
return streamToString(response.body).then(function (response) { | ||
expect(response).to.equal('some content') | ||
@@ -1327,3 +1368,3 @@ }) | ||
expect(response.headers['content-type']).to.contain(contentType) | ||
return middleware.streamToString(response.body).then(function (response) { | ||
return streamToString(response.body).then(function (response) { | ||
expect(response).to.equal('some content') | ||
@@ -1463,4 +1504,4 @@ }) | ||
return httpism.get(baseurl, {proxy: proxyUrl}).then(function (body) { | ||
expect(body).to.eql({blah: 'blah'}) | ||
return httpism.get(baseurl, { proxy: proxyUrl }).then(function (body) { | ||
expect(body).to.eql({ blah: 'blah' }) | ||
expect(urlProxied).to.equal(baseurl) | ||
@@ -1560,4 +1601,4 @@ }) | ||
return httpism.get(baseurl, {proxy: secureProxyUrl}).then(function (body) { | ||
expect(body).to.eql({blah: 'blah'}) | ||
return httpism.get(baseurl, { proxy: secureProxyUrl }).then(function (body) { | ||
expect(body).to.eql({ blah: 'blah' }) | ||
expect(urlProxied).to.equal(baseurl) | ||
@@ -1591,3 +1632,3 @@ }) | ||
return next().then(function (res) { | ||
return middleware.streamToString(res.body).then(function (response) { | ||
return streamToString(res.body).then(function (response) { | ||
res.body = response | ||
@@ -1599,3 +1640,3 @@ return res | ||
return client.get(baseurl, {response: true}).then(function (response) { | ||
return client.get(baseurl, { response: true }).then(function (response) { | ||
expect(response.statusCode).to.equal(400) | ||
@@ -1622,3 +1663,3 @@ expect(JSON.parse(response.body)).to.eql({ | ||
return client.get(baseurl, {response: true}).then(function (response) { | ||
return client.get(baseurl, { response: true }).then(function (response) { | ||
expect(response.statusCode).to.equal(200) | ||
@@ -1661,3 +1702,3 @@ expect(response.body).to.eql({ | ||
return httpism.get(baseurl, {output: fs.createWriteStream(filename)}).then(function () { | ||
return httpism.get(baseurl, { output: fs.createWriteStream(filename) }).then(function () { | ||
expect(fs.readFileSync(filename, 'utf-8')).to.equal('contents') | ||
@@ -1676,3 +1717,3 @@ }) | ||
return httpism.get(baseurl, {output: fs.createWriteStream(filename)}).then(function () { | ||
return httpism.get(baseurl, { output: fs.createWriteStream(filename) }).then(function () { | ||
expect(fs.readFileSync(filename, 'utf-8')).to.equal('contents') | ||
@@ -1695,3 +1736,3 @@ }) | ||
var startTime = Date.now() | ||
return expect(httpism.get(baseurl, {timeout: 20})).to.eventually.be.rejectedWith('timeout').then(function () { | ||
return expect(httpism.get(baseurl, { timeout: 20 })).to.eventually.be.rejectedWith('timeout').then(function () { | ||
expect(Date.now() - startTime).to.be.within(20, 50) | ||
@@ -1714,3 +1755,3 @@ }).then(function () { | ||
res.set('x-version', version) | ||
res.send({version: version}) | ||
res.send({ version: version }) | ||
}) | ||
@@ -1731,3 +1772,3 @@ | ||
it('caches responses', function () { | ||
var http = httpism.client(cache({url: cachePath}), {response: true}) | ||
var http = httpism.client(cache({ url: cachePath }), { response: true }) | ||
return http.get(baseurl).then(function (response) { | ||
@@ -1766,3 +1807,3 @@ expect(response.headers['x-version']).to.eql('1') | ||
it('caches binary responses', function () { | ||
var http = httpism.client(cache({url: cachePath}), {response: true}) | ||
var http = httpism.client(cache({ url: cachePath }), { response: true }) | ||
return http.get(baseurl + '/binary').then(function (response) { | ||
@@ -1769,0 +1810,0 @@ expect(response.headers['x-version']).to.eql('1') |
Sorry, the diff of this file is too big to display
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
58
449
7
486524
13092
+ Addeddebug@3.2.74.1.1(transitive)
+ Addedip-regex@2.1.0(transitive)
+ Addedmime-db@1.38.0(transitive)
+ Addedmime-types@2.1.22(transitive)
+ Addedms@2.1.3(transitive)
+ Addedpsl@1.15.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedtough-cookie@3.0.1(transitive)
+ Addedunderscore@1.9.1(transitive)
- Removeddebug@3.1.0(transitive)
- Removedmime-db@1.33.0(transitive)
- Removedmime-types@2.1.18(transitive)
- Removedms@2.0.0(transitive)
- Removedpunycode@1.4.1(transitive)
- Removedtough-cookie@2.3.4(transitive)
- Removedunderscore@1.8.3(transitive)
Updateddebug@4.1.1
Updatedmime-types@2.1.22
Updatedtough-cookie@3.0.1
Updatedunderscore@1.9.1