Comparing version 0.2.1 to 0.2.2
17
index.js
@@ -372,2 +372,7 @@ /** | ||
} else { | ||
function setCookie (cookie) { | ||
var crumbs = cookie.split('='); | ||
result.cookies[Unirest.trim(crumbs[0])] = Unirest.trim(crumbs.slice(1).join('=') || ''); | ||
} | ||
// Set-Cookie Parsing | ||
@@ -381,6 +386,3 @@ var cookies = response.headers['set-cookie']; | ||
if (is(entry).a(String) && does(entry).contain(';')) { | ||
entry.split(';').forEach(function (cookie) { | ||
var crumbs = cookie.split('='); | ||
result.cookies[Unirest.trim(crumbs[0])] = Unirest.trim(crumbs[1] || ''); | ||
}); | ||
entry.split(';').forEach(setCookie); | ||
} | ||
@@ -390,10 +392,7 @@ } | ||
// Cookie header parser... for some reason there are two...? | ||
// Sometimes you get this header. | ||
cookies = response.headers['cookie']; | ||
if (cookies && is(cookies).a(String)) { | ||
cookies.split(';').forEach(function (cookie) { | ||
var crumbs = cookie.split('='); | ||
result.cookies[Unirest.trim(crumbs[0])] = Unirest.trim(crumbs[1] || ''); | ||
}); | ||
cookies.split(';').forEach(setCookie); | ||
} | ||
@@ -400,0 +399,0 @@ } |
{ | ||
"name": "unirest", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Lightweight HTTP Request library.", | ||
@@ -34,7 +34,19 @@ "main": "index.js", | ||
], | ||
"author": "Nijiko Yonskai <nijiko@mashape.com>", | ||
"author": { | ||
"name": "Nijiko Yonskai", | ||
"email": "nijiko@mashape.com" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/Mashape/unirest-nodejs/issues" | ||
} | ||
}, | ||
"readme": "# Unirest for Node.js [![Build Status](https://travis-ci.org/Mashape/unirest-nodejs.png?branch=master)](https://travis-ci.org/Mashape/unirest-nodejs)\n\nUnirest is a set of lightweight HTTP libraries available in multiple languages.\n\nCreated with love by [nijikokun](http://github.com/nijikokun) @ [mashape.com](http://mashape.com)\n\n## Installing\n\nTo utilize unirest for node.js install the the `npm` module:\n\n```js\nnpm install unirest\n```\n\nAfter installing the `npm` package you can now start simplifying requests like so:\n\n```js\nvar unirest = require('unirest');\n```\n\n## Creating Requests\n\nYou're probably wondering how by using **Unirest** makes creating requests easier. Besides automatically supporting gzip, and parsing responses, lets start with a basic working example:\n\n```js\nunirest.post('http://httpbin.org/post')\n.headers({ 'Accept': 'application/json' })\n.send({ \"parameter\": 23, \"foo\": \"bar\" })\n.end(function (response) {\n console.log(response.body);\n});\n```\n\n## Uploading Files\n\nTransferring file data has been simplified:\n\n```js\nunirest.post('http://httpbin.org/post')\n.headers({ 'Accept': 'application/json' })\n.field('parameter', 'value') // Form field\n.attach('file', '/tmp/file') // Attachment\n.end(function (response) {\n console.log(response.body);\n});\n```\n\n## Custom Entity Body\n\n```js\nunirest.post('http://httpbin.org/post')\n.headers({ 'Accept': 'application/json' })\n.send(new Buffer([1,2,3]))\n.end(function (response) {\n console.log(response.body);\n});\n```\n\n# Unirest\n\nA request can be initiated by invoking the appropriate method on the unirest object, then calling `.end()` to send the request. Alternatively you can send the request directly by providing a callback along with the url.\n\n## unirest(method [, uri, headers, body, callback])\n\n- `method` - Request type (GET, PUT, POST, etc...)\n- `uri` - _Optional_; When declared the method will return a [Request](#request) object. \n Otherwise it will return the method below with `method` set to the method given.\n- `headers` (`Object`) - _Optional_; Will be aliased to unirest\\[method] `headers` argument when `uri` is present.\n- `body` (`Mixed`) - _Optional_; Will be aliased to unirest\\[method] `body` argument when `uri` is present.\n- `callback` (`Function`) - _Optional_; Will be aliased to unirest\\[method] `callback` argument when `uri` is present.\n\n## unirest\\[method](url [, headers, body, callback])\n\n- `method` - Request type, pre-defined methods, see below.\n- `url` - Request location.\n- `headers` (`Object` | `Function`) - _Optional_; When `Object` headers are passed along to the `Request.set()` method, \n when `Function` this argument is used as the `callback`.\n- `body` (`Mixed` | `Function`) - _Optional_; When `body` is not a `Function` it will be passed along to `Request.send()` method,\n otherwise when a `Function` it will be used as the `callback`.\n- `callback` (`Function`) - _Optional_; Calls end with given argument, otherwise `Request` is returned.\n\nAll arguments above, with the exclusion of `url`, will accept a `Function` as the `callback`. \nWhen no `callback` is present, the [Request](#request) object will be returned.\n\n### get\n\nReturns a [Request](#request) object with the `method` option set to `GET`\n\n```js\nvar Request = unirest.get('http://httpbin.org/get');\n```\n\n### head\nReturns a [Request](#request) object with the `method` option set to `HEAD`\n\n```js\nvar Request = unirest.head('http://httpbin.org/get');\n```\n\n### post\nReturns a [Request](#request) object with the `method` option set to `POST`\n\n```js\nvar Request = unirest.post('http://httpbin.org/post');\n```\n\n### patch\n\nReturns a [Request](#request) object with the `method` option set to `PATCH`\n\n```js\nvar Request = unirest.patch('http://httpbin.org/patch');\n```\n\n### delete\nReturns a [Request](#request) object with the `method` option set to `DELETE`\n\n```js\nvar Request = unirest.delete('http://httpbin.org/delete');\n```\n\n## unirest.jar()\n\nCreates a container to store multiple cookies, i.e. a cookie jar.\n\n```js\nvar CookieJar = unirest.jar();\nCookieJar.add(unirest.cookie('some value'));\nunirest.get('http://httpbin.org/get').jar(CookieJar);\n```\n\n## unirest.cookie(String)\n\nCreates a cookie, see above for example.\n\n## unirest.request\n\n`mikeal/request` library (the underlying layer of unirest-nodejs) for direct use.\n\n# Request\n\nProvides simple and easy to use methods for manipulating the request prior to being sent. This object is created when a \nUnirest Method is invoked. This object contains methods that are chainable like other libraries such as jQuery and popular \nrequest module Superagent (which this library is modeled after slightly).\n\n**Example**\n\n```js\nvar Request = unirest.post('http://httpbin.org/post');\n\nRequest.headers({\n 'Accepts': 'application/json'\n}).end(function (response) {\n ...\n});\n```\n\n## Request Methods\n\nRequest Methods differ from Option Methods (See Below) in that these methods transform, or handle the data in a sugared way, where as Option Methods require a more _hands on_ approach.\n\n#### Request.auth(Object) or (user, pass, sendImmediately)\n\nAccepts either an `Object` containing `user`, `pass`, and optionally `sendImmediately`.\n\n- `user` (`String`) - Authentication Username\n- `pass` (`String`) - Authentication Password\n- `sendImmediately` (`String`) - _Optional_; Defaults to `true`; Flag to determine whether Request should send the basic authentication header along with the request. Upon being _false_, Request will retry with a _proper_ authentication header after receiving a `401` response from the server (which must contain a `WWW-Authenticate` header indicating the required authentication method)\n\n**Object**\n\n```js\nRequest.auth({\n user: 'Nijiko',\n pass: 'insecure',\n sendImmediately: true\n});\n```\n\n**Arguments**\n\n```\nRequest.auth('Nijiko', 'insecure', true);\n```\n\n#### Request.header(Object) or (field, value)\n\n**Suggested Method for setting Headers**\n\nAccepts either an `Object` containing `header-name: value` entries,\nor `field` and `value` arguments. Each entry is then stored in a two locations, one in the case-sensitive `Request.options.headers` and the other on a private `_headers` object that is case-insensitive for internal header lookup.\n\n- `field` (`String`) - Header name, such as `Accepts`\n- `value` (`String`) - Header value, such as `application/json` \n\n**Object**\n\n```js\nRequest.set({\n 'Accepts': 'application/json'\n, 'User-Agent': 'Unirest Node.js'\n})\n```\n\n**Arguments**\n\n```\nRequest.set('Accepts', 'application/json');\n```\n\n#### Request.part(Object)\n\n**Experimental**\n\nSimiliar to `Request.multipart()` except it only allows one object to be passed at a time and does the pre-processing on necessary `body` values for you.\n\nEach object is then appended to the `Request.options.multipart` array.\n\n```js\nRequest.part({\n 'content-type': 'application/json'\n, body: { foo: 'bar' }\n}).part({\n 'content-type': 'text/html'\n, body: '<strong>Hello World!</strong>'\n});\n```\n\n#### Request.query(Object) or (String)\n\nWhen `Object` is passed value is processed as a `querystring` representation, otherwise we directly use the `String` passed and append it to `Request.options.url`. If `Request.options.url` has a trailing `?` already, we append it with `& + value` otherwise we append as `? + value`\n\n```js\nunirest.post('http://httpbin.org/get')\n.query('name=nijiko')\n.query({\n pet: 'spot'\n})\n.end(function (response) {\n console.log(response);\n});\n```\n\n#### Request.send(Object | String)\n\nEase of use method for setting the body without having to worry about processing the data for popular formats such as `JSON`, `Form Encoded`, otherwise the `body` is set on `Request.options` as the given value.\n\nBy default sending strings with no `Content-Type` preset will set `Content-Type` to `application/x-www-form-urlencoded`, and multiple calls will be concatenated with `&`. Otherwise multiple calls will be appended to the previous `body` value.\n\n**JSON**\n\n```js\nunirest.post('http://httpbin.org/post')\n.type('json')\n.send({\n foo: 'bar',\n hello: 3\n})\n.end(function (response) {\n console.log(response.body);\n})\n```\n\n**FORM Encoded**\n\n```js\n// Body would be:\n// name=nijiko&pet=turtle\nunirest.post('http://httpbin.org/post')\n.send('name=nijiko')\n.send('pet=spot')\n.end(function (response) {\n console.log(response.body);\n});\n```\n\n**HTML / Other**\n\n```js\nunirest.post('http://httpbin.org/post')\n.set('Content-Type', 'text/html')\n.send('<strong>Hello World!</strong>')\n.end(function (response) {\n console.log(response.body);\n});\n```\n\n#### Request.type(String)\n\nSets the header `Content-Type` through either lookup for extensions (`xml`, `png`, `json`, etc...) using `mime` or using the full value such as `application/json`. \n\nUses `Request.header()` to set header value.\n\n```js\nRequest.type('application/json') // Content-Type: application/json\nRequest.type('json') // Content-Type: application/json\nRequest.type('html') // Content-Type: text/html\n…\n```\n\n## Request Form Methods\n\nThe following methods are sugar methods for attaching files, and form fields. Instead of handling files and processing them yourself Unirest can do that for you.\n\n#### Request.attach(Object) or (name, path)\n\n`Object` should consist of `name: 'path'` otherwise use `name` and `path`.\n\n- `name` (`String`) - File field name\n- `path` (`String` | `Object`) - File value, A `String` will be parsed based on its value. If `path` contains `http` or `https` Request will handle it as a `remote file`, otherwise if it contains `://` and not `http` or `https` it will consider it to be a `direct file path`. If no `://` is found it will be considered a `relative file path`. An `Object` is directly set, so you can do pre-processing if you want without worrying about the string value.\n\n**Object**\n\n```js\nunirest.post('http://httpbin.org/post')\n.headers({ 'Accept': 'application/json' })\n.field({\n 'parameter': 'value'\n})\n.attach({\n 'file': 'dog.png'\n, 'relative file': fs.createReadStream(path.join(__dirname, 'dog.png'),\n, 'remote file': unirest.request('http://google.com/doodle.png')\n})\n.end(function (response) {\n console.log(response.body);\n})\n```\n\n**Arguments**\n\n```js\nunirest.post('http://httpbin.org/post')\n.headers({ 'Accept': 'application/json' })\n.field('parameter', 'value') // Form field\n.attach('file', 'dog.png') // Attachment\n.attach('remote file', fs.createReadStream(path.join(__dirname, 'dog.png')) // Same as above.\n.attach('remote file', unirest.request('http://google.com/doodle.png'))\n.end(function (response) {\n console.log(response.body);\n});\n```\n\n#### Request.field(Object) or (name, value)\n\n`Object` should consist of `name: 'value'` otherwise use `name` and `value`\n\nSee `Request.attach` for usage.\n\n## Request.options\n\nThe _options_ `object` is where almost all of the request settings live. Each option method sugars to a field on this object to allow for chaining and ease of use. If \nyou have trouble with an option method and wish to directly access the _options_ object\nyou are free to do so.\n\nThis object is modeled after the `request` libraries options that are passed along through its constructor.\n\n* `url` (`String` | `Object`) - Url, or object parsed from `url.parse()`\n* `qs` (`Object`) - Object consisting of `querystring` values to append to `url` upon request.\n* `method` (`String`) - Default `GET`; HTTP Method.\n* `headers` (`Object`) - Default `{}`; HTTP Headers.\n* `body` (`String` | `Object`) - Entity body for certain requests.\n* `form` (`Object`) - Form data.\n* `auth` (`Object`) - See `Request.auth()` below.\n* `multipart` (`Object`) - _Experimental_; See documentation below.\n* `followRedirect` (`Boolean`) - Default `true`; Follow HTTP `3xx` responses as redirects.\n* `followAllRedirects` (`Boolean`) - Default `false`; Follow **Non**-GET HTTP `3xx` responses as redirects.\n* `maxRedirects` (`Number`) - Default `10`; Maximum number of redirects before aborting.\n* `encoding` (`String`) - Encoding to be used on `setEncoding` of response data.\n* `timeout` (`Number`) - Number of milliseconds to wait before aborting.\n* `proxy` (`String`) - See `Request.proxy()` below.\n* `oauth` (`Object`) - See `Request.oauth()` below.\n* `hawk` (`Object`) - See `Request.hawk()` below\n* `strictSSL` (`Boolean`) - Default `true`; See `Request.strictSSL()` below.\n* `secureProtocol` (`String`) - See `Request.secureProtocol()` below.\n* `jar` (`Boolean` | `Jar`) - See `Request.jar()` below.\n* `aws` (`Object`) - See `Request.aws()` below.\n* `httpSignature` (`Object`) - See `Request.httpSignature()` Below.\n* `localAddress` (`String`) - See `Request.localAddress()` Below.\n* `pool` && `pool.maxSockets` - Advanced agent technology, that is supported.\n\n## Request Option Methods\n\n#### Request.url(String)\n\nSets `url` location of the current request on `Request.options` to the given `String`\n\n```js\nRequest.url('http://httpbin.org/get');\n```\n\n#### Request.method(String)\n\nSets `method` value on `Request.options` to the given value.\n\n```js\nRequest.method('HEAD');\n```\n\n#### Request.form(Object)\n\nSets `form` object on `Request.options` to the given object.\n\nWhen used `body` is set to the object passed as a `querystring` representation and the `Content-Type` header to `application/x-www-form-urlencoded; charset=utf-8`\n\n```js\nRequest.form({\n key: 'value'\n});\n```\n\n#### Request.multipart(Array)\n\n**Experimental**\n\nSets `multipart` array containing multipart-form objects on `Request.options` to be sent along with the Request.\n\nEach objects property with the exclusion of `body` is treated as a header value. Each `body` value must be pre-processed if necessary when using this method.\n\n```js\nRequest.multipart([{\n 'content-type': 'application/json'\n, body: JSON.stringify({\n foo: 'bar'\n })\n}, {\n 'content-type': 'text/html'\n, body: '<strong>Hello World!</strong>'\n}]);\n```\n\n#### Request.maxRedirects(Number)\n\nSets `maxRedirects`, the number of redirects the current Request will follow, on `Request.options` based on the given value.\n\n```js\nRequest.maxRedirects(6)\n```\n\n#### Request.followRedirect(Boolean)\n\nSets `followRedirect` flag on `Request.options` for whether the current Request should follow HTTP redirects based on the given value.\n\n```js\nRequest.followRedirect(true);\n```\n\n#### Request.timeout(Number)\n\nSets `timeout`, number of milliseconds Request should wait for a response before aborting, on `Request.options` based on the given value.\n\n```js\nRequest.timeout(2000)\n```\n\n#### Request.encoding(String)\n\nSets `encoding`, encoding to be used on setEncoding of response data if set to null, the body is returned as a Buffer, on `Request.options` based on given value.\n\n```js\nRequest.encoding('utf-8')\n```\n\n#### Request.strictSSL(Boolean)\n\nSets `strictSSL` flag to require that SSL certificates be valid on `Request.options` based on given value.\n\n```js\nRequest.strictSSL(true);\n``` \n\n#### Request.httpSignature(Object)\n\nSets `httpSignature` \n\n#### Request.proxy(String)\n\nSets `proxy`, HTTP Proxy to be set on `Request.options` based on value.\n\n```js\nRequest.proxy('http://localproxy.com');\n```\n\n#### Request.secureProtocol(String)\n\nSets the secure protocol to use:\n\n```js\nRequest.secureProtocol('SSLv2_method');\n// or \nRequest.secureProtocol('SSLv3_client_method');\n```\n\nSee [openssl.org](https://www.openssl.org/docs/ssl/SSL_CTX_new.html) for all possible values.\n\n#### Request.aws(Object)\n\nSets `aws`, AWS Signing Credentials, on `Request.options`\n\n```js\nRequest.aws({ \n key: 'AWS_S3_KEY'\n, secret: 'AWS_S3_SECRET'\n, bucket: 'BUCKET NAME'\n});\n```\n\n#### Request.oauth(Object)\n\nSets `oauth`, list of oauth credentials, on `Request.options` based on given object.\n\n```js\nvar Request = unirest.get('https://api.twitter.com/oauth/request_token');\n\nRequest.oauth({\n callback: 'http://mysite.com/callback/'\n, consumer_key: 'CONSUMER_KEY'\n, consumer_secret: 'CONSUMER_SECRET'\n}).end(function (response) {\n var access_token = response.body;\n \n Request = unirest.post('https://api.twitter.com/oauth/access_token');\n Request.oauth({\n consumer_key: 'CONSUMER_KEY'\n , consumer_secret: 'CONSUMER_SECRET'\n , token: access_token.oauth_token\n , verifier: token: access_token.oauth_verifier\n }).end(function (response) {\n var token = response.body;\n \n Request = unirest.get('https://api.twitter.com/1/users/show.json');\n Request.oauth({\n consumer_key: 'CONSUMER_KEY'\n , consumer_secret: 'CONSUMER_SECRET'\n , token: token.oauth_token\n , token_secret: token.oauth_token_secret\n }).query({\n screen_name: token.screen_name\n , user_id: token.user_id\n }).end(function (response) {\n console.log(response.body);\n });\n })\n});\n```\n\n#### Request.hawk(Object)\n\nSets `hawk` object on `Request.options` to the given object.\n\nHawk requires a field `credentials` as seen in their [documentation](https://github.com/hueniverse/hawk#usage-example), and below.\n\n```js\nRequest.hawk({\n credentials: {\n key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn'\n , algorithm: 'sha256'\n , user: 'Steve'\n }\n});\n```\n\n#### Request.localAddress(String)\n\nSets `localAddress`, local interface to bind for network connections, on `Request.options`\n\n```js\nRequest.localAddress('127.0.0.1');\nRequest.localAddress('1.2.3.4');\n```\n\n#### Request.jar(Boolean) or Request.jar(Jar)\n\nSets `jar`, cookie container, on `Request.options`. When set to `true` it stores cookies for future usage.\n\nSee `unirest.jar` for more information on how to use `Jar` argument.\n\n## Request Aliases\n\n#### Request.set\n\n**Alias** for `Request.header()`\n\n#### Request.headers\n\n**Alias** for `Request.header()`\n\n#### Request.redirects\n\n**Alias** for `Request.maxRedirects()`\n\n#### Request.redirect\n\n**Alias** for `Request.followRedirect()`\n\n#### Request.ssl\n\n**Alias** for `Request.strictSSL()`\n\n#### Request.ip\n\n**Alias** for `Request.localAddress()`\n\n#### Request.complete\n\n**Alias** for `Request.end()`\n\n#### Request.as.json\n\n**Alias** for `Request.end()`\n\n#### Request.as.binary\n\n**Alias** for `Request.end()`\n\n#### Request.as.string\n\n**Alias** for `Request.end()`\n\n# Response\n\nUpon ending a request, and recieving a Response the object that is returned contains a number of helpful properties to ease coding pains.\n\n## General\n\n\n- `body` (`Mixed`) - Processed body data\n- `raw_body` (`Mixed`) - Unprocessed body data\n- `headers` (`Object`) - Header details\n- `cookies` (`Object`) - Cookies from `set-cookies`, and `cookie` headers.\n- `httpVersion` (`String`) - Server http version. (e.g. 1.1)\n- `httpVersionMajor` (`Number`) - Major number (e.g. 1)\n- `httpVersionMinor` (`Number`) - Minor number (e.g. 1)\n- `url` (`String`) - Dependant on input, can be empty.\n- `domain` (`String` | `null`) - Dependant on input, can be empty.\n- `method` (`String` | `null`) - Method used, dependant on input.\n- `client` (`Object`) - Client Object. Detailed information regarding the Connection and Byte throughput.\n- `connection` (`Object`) - Client Object. Specific connection object, useful for events such as errors. **Advanced**\n- `socket` (`Object`) Client Object. Socket specific object and information. Most throughput is same across all three client objects.\n- `request` (`Object`) - Initial request object.\n- `setEncoding` (`Function`) - Set encoding type.\n\n## Status Information\n\n- `code` (`Number`) - Status Code, i.e. `200`\n- `status` (`Number`) - Status Code, same as above.\n- `statusType` (`Number`) - Status Code Range Type\n - `1` - Info\n - `2` - Ok\n - `3` - Miscellaneous\n - `4` - Client Error\n - `5` - Server Error\n- `info` (`Boolean`) - Status Range Info?\n- `ok` (`Boolean`) - Status Range Ok?\n- `clientError` (`Boolean`) - Status Range Client Error?\n- `serverError` (`Boolean`) - Status Range Server Error?\n- `accepted` (`Boolean`) - Status Code `202`?\n- `noContent` (`Boolean`) - Status Code `204` or `1223`?\n- `badRequest` (`Boolean`) - Status Code `400`?\n- `unauthorized` (`Boolean`) - Status Code `401`?\n- `notAcceptable` (`Boolean`) - Status Code `406`?\n- `notFound` (`Boolean`) - Status Code `404`?\n- `forbidden` (`Boolean`) - Status Code `403`?\n- `error` (`Boolean` | `Object`) - Dependant on status code range.\n\n## response.cookie(name)\n\nSugar method for retrieving a cookie from the `response.cookies` object.\n\n\n```js\nvar CookieJar = unirest.jar();\nCookieJar.add(unirest.cookie('another cookie=23'));\n\nunirest.get('http://google.com').jar(CookieJar).end(function (response) {\n // Except google trims the value passed :/\n console.log(response.cookie('another cookie'));\n});\n```\n", | ||
"readmeFilename": "README.md", | ||
"homepage": "https://github.com/Mashape/unirest-nodejs", | ||
"_id": "unirest@0.2.1", | ||
"dist": { | ||
"shasum": "5a3a78fe7e4de415b54a36890a79b94465940fa8" | ||
}, | ||
"_from": "unirest@0.2.1", | ||
"_resolved": "https://registry.npmjs.org/unirest/-/unirest-0.2.1.tgz" | ||
} |
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
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
68359
1
788