then-request
Advanced tools
Comparing version 2.1.0 to 2.1.1
@@ -84,3 +84,3 @@ 'use strict'; | ||
options.body = JSON.stringify(options.json); | ||
options.headers['content-type'] = 'application/json'; | ||
options.headers['Content-Type'] = 'application/json'; | ||
} | ||
@@ -118,3 +118,3 @@ | ||
for (var name in options.headers) { | ||
xhr.setRequestHeader(name.toLowerCase(), options.headers[name]); | ||
xhr.setRequestHeader(name, options.headers[name]); | ||
} | ||
@@ -121,0 +121,0 @@ |
@@ -85,3 +85,3 @@ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.request=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
options.body = JSON.stringify(options.json); | ||
options.headers['content-type'] = 'application/json'; | ||
options.headers['Content-Type'] = 'application/json'; | ||
} | ||
@@ -119,3 +119,3 @@ | ||
for (var name in options.headers) { | ||
xhr.setRequestHeader(name.toLowerCase(), options.headers[name]); | ||
xhr.setRequestHeader(name, options.headers[name]); | ||
} | ||
@@ -122,0 +122,0 @@ |
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.request=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
"use strict";function doRequest(e,t,o,r){var n=new Promise(function(n,s){function i(r){doRequest(e,t,{qs:o.qs,headers:o.headers,timeout:o.timeout}).nodeify(function(e,t){var a=e||t.statusCode>=400;if("function"==typeof o.retry&&(a=o.retry(e,t,r+1)),r>=(5|o.maxRetries)&&(a=!1),a){var u=o.retryDelay;"function"==typeof o.retryDelay&&(u=o.retryDelay(e,t,r+1)),u=u||200,setTimeout(function(){i(r+1)},u)}else e?s(e):n(t)})}var a=new window.XMLHttpRequest;if("string"!=typeof e)throw new TypeError("The method must be a string.");if("string"!=typeof t)throw new TypeError("The URL/path must be a string.");if("function"==typeof o&&(r=o,o={}),(null===o||void 0===o)&&(o={}),"object"!=typeof o)throw new TypeError("Options must be an object (or null).");if("function"!=typeof r&&(r=void 0),e=e.toUpperCase(),o.headers=o.headers||{},o.retry&&"GET"===e)return i(0);var u,d=!(!(u=/^([\w-]+:)?\/\/([^\/]+)/.exec(o.uri))||u[2]==window.location.host);if(d||(o.headers["X-Requested-With"]="XMLHttpRequest"),o.qs&&(t=handleQs(t,o.qs)),o.json&&(o.body=JSON.stringify(o.json),o.headers["content-type"]="application/json"),o.timeout){a.timeout=o.timeout;var f=Date.now();a.ontimeout=function(){var e=Date.now()-f,t=new Error("Request timed out after "+e+"ms");t.timeout=!0,t.duration=e,s(t)}}a.onreadystatechange=function(){if(4===a.readyState){var e={};a.getAllResponseHeaders().split("\r\n").forEach(function(t){var o=t.split(":");o.length>1&&(e[o[0].toLowerCase()]=o.slice(1).join(":").trim())});var o=new Response(a.status,e,a.responseText);o.url=t,n(o)}},a.open(e,t,!0);for(var p in o.headers)a.setRequestHeader(p.toLowerCase(),o.headers[p]);a.send(o.body?o.body:null)});return n.getBody=function(){return n.then(function(e){return e.getBody()})},n.nodeify(r)}var Promise=require("promise"),Response=require("http-response-object"),handleQs=require("./lib/handle-qs.js");module.exports=doRequest; | ||
"use strict";function doRequest(e,t,r,o){var n=new Promise(function(n,s){function i(o){doRequest(e,t,{qs:r.qs,headers:r.headers,timeout:r.timeout}).nodeify(function(e,t){var u=e||t.statusCode>=400;if("function"==typeof r.retry&&(u=r.retry(e,t,o+1)),o>=(5|r.maxRetries)&&(u=!1),u){var a=r.retryDelay;"function"==typeof r.retryDelay&&(a=r.retryDelay(e,t,o+1)),a=a||200,setTimeout(function(){i(o+1)},a)}else e?s(e):n(t)})}var u=new window.XMLHttpRequest;if("string"!=typeof e)throw new TypeError("The method must be a string.");if("string"!=typeof t)throw new TypeError("The URL/path must be a string.");if("function"==typeof r&&(o=r,r={}),(null===r||void 0===r)&&(r={}),"object"!=typeof r)throw new TypeError("Options must be an object (or null).");if("function"!=typeof o&&(o=void 0),e=e.toUpperCase(),r.headers=r.headers||{},r.retry&&"GET"===e)return i(0);var a,d=!(!(a=/^([\w-]+:)?\/\/([^\/]+)/.exec(r.uri))||a[2]==window.location.host);if(d||(r.headers["X-Requested-With"]="XMLHttpRequest"),r.qs&&(t=handleQs(t,r.qs)),r.json&&(r.body=JSON.stringify(r.json),r.headers["Content-Type"]="application/json"),r.timeout){u.timeout=r.timeout;var f=Date.now();u.ontimeout=function(){var e=Date.now()-f,t=new Error("Request timed out after "+e+"ms");t.timeout=!0,t.duration=e,s(t)}}u.onreadystatechange=function(){if(4===u.readyState){var e={};u.getAllResponseHeaders().split("\r\n").forEach(function(t){var r=t.split(":");r.length>1&&(e[r[0].toLowerCase()]=r.slice(1).join(":").trim())});var r=new Response(u.status,e,u.responseText);r.url=t,n(r)}},u.open(e,t,!0);for(var p in r.headers)u.setRequestHeader(p,r.headers[p]);u.send(r.body?r.body:null)});return n.getBody=function(){return n.then(function(e){return e.getBody()})},n.nodeify(o)}var Promise=require("promise"),Response=require("http-response-object"),handleQs=require("./lib/handle-qs.js");module.exports=doRequest; | ||
},{"./lib/handle-qs.js":2,"http-response-object":4,"promise":5}],2:[function(require,module,exports){ | ||
@@ -4,0 +4,0 @@ "use strict";function handleQs(r,s){r=r.split("?");var i=r[0],e=(r[1]||"").split("#")[0],t=r[1]&&r[1].split("#").length>1?"#"+r[1].split("#")[1]:"",n=parse(e);for(var a in s)n[a]=s[a];return e=stringify(n),""!==e&&(e="?"+e),i+e+t}var parse=require("qs").parse,stringify=require("qs").stringify;module.exports=handleQs; |
@@ -8,2 +8,3 @@ 'use strict'; | ||
var Response = require('http-response-object'); | ||
var caseless = require('caseless'); | ||
var handleQs = require('./lib/handle-qs.js'); | ||
@@ -39,2 +40,3 @@ | ||
options.headers = options.headers || {}; | ||
var headers = caseless(options.headers); | ||
@@ -49,3 +51,3 @@ // handle query string | ||
options.body = JSON.stringify(options.json); | ||
options.headers['content-type'] = 'application/json'; | ||
headers.set('Content-Type', 'application/json'); | ||
} | ||
@@ -56,4 +58,4 @@ | ||
assert(Buffer.isBuffer(body), 'body should be a Buffer or a String'); | ||
if (!Object.keys(options.headers).some(function (name) { return name.toLowerCase() === 'content-length'; })) { | ||
options.headers['content-length'] = body.length; | ||
if (!headers.has('Content-Length')) { | ||
headers.set('Content-Length', body.length); | ||
} | ||
@@ -60,0 +62,0 @@ |
{ | ||
"name": "then-request", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "A request library that returns promises, inspired by request", | ||
@@ -8,7 +8,8 @@ "keywords": [], | ||
"dependencies": { | ||
"promise": "^6.0.1", | ||
"caseless": "~0.9.0", | ||
"concat-stream": "^1.4.7", | ||
"qs": "^2.3.3", | ||
"http-basic": "^2.0.0", | ||
"http-response-object": "^1.0.1", | ||
"http-basic": "^2.0.0" | ||
"promise": "^6.0.1", | ||
"qs": "^2.3.3" | ||
}, | ||
@@ -34,3 +35,3 @@ "devDependencies": { | ||
"type": "git", | ||
"url": "https://github.com/then/request.git" | ||
"url": "https://github.com/then/then-request.git" | ||
}, | ||
@@ -37,0 +38,0 @@ "author": "ForbesLindesay", |
@@ -5,4 +5,4 @@ # then-request | ||
[![Build Status](https://img.shields.io/travis/then/request/master.svg)](https://travis-ci.org/then/request) | ||
[![Dependency Status](https://img.shields.io/gemnasium/then/request.svg)](https://gemnasium.com/then/request) | ||
[![Build Status](https://img.shields.io/travis/then/then-request/master.svg)](https://travis-ci.org/then/then-request) | ||
[![Dependency Status](https://img.shields.io/gemnasium/then/then-request.svg)](https://gemnasium.com/then/then-request) | ||
[![NPM version](https://img.shields.io/npm/v/then-request.svg)](https://www.npmjs.org/package/then-request) | ||
@@ -9,0 +9,0 @@ |
@@ -20,3 +20,2 @@ 'use strict'; | ||
XMLHttpRequest.prototype.setRequestHeader = function (name, value) { | ||
assert(name === name.toLowerCase(), 'All headers must be lower case'); | ||
this._headers[name] = value; | ||
@@ -23,0 +22,0 @@ }; |
@@ -16,3 +16,3 @@ 'use strict'; | ||
if (method === 'POST' && url === 'http://example.com') { | ||
assert(headers['content-type'] === 'application/json'); | ||
assert(headers['Content-Type'] === 'application/json'); | ||
assert(JSON.parse(body.toString()).foo === 'baz'); | ||
@@ -19,0 +19,0 @@ return new Response(200, {}, 'json body'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1327
137338
6
+ Addedcaseless@~0.9.0
+ Addedcaseless@0.9.0(transitive)