Comparing version 0.0.1 to 0.0.2
32
index.js
@@ -343,2 +343,34 @@ /** | ||
// Cookie Holder | ||
result.cookies = {}; | ||
// Cookie Sugar Method | ||
result.cookie = function (name) { | ||
return result.cookies[name]; | ||
}; | ||
// Set-Cookie Parsing | ||
var cookies = response.headers['set-cookie']; | ||
if (cookies && is(cookies).a(Array)) { | ||
for (var index in cookies) { | ||
var entry = cookies[index]; | ||
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] || ''); | ||
}); | ||
} | ||
} | ||
} | ||
// Cookie header parser... for some reason there are two...? | ||
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] || ''); | ||
}); | ||
} | ||
// Response | ||
@@ -345,0 +377,0 @@ result.response = response; |
{ | ||
"name": "unirest", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Lightweight HTTP Request library.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -76,3 +76,3 @@ # Unirest for Node.js | ||
Returns a [Request](#Request) object with the `method` option set to `GET` | ||
Returns a [Request](#request) object with the `method` option set to `GET` | ||
@@ -84,3 +84,3 @@ ```js | ||
### head | ||
Returns a [Request](#Request) object with the `method` option set to `HEAD` | ||
Returns a [Request](#request) object with the `method` option set to `HEAD` | ||
@@ -92,3 +92,3 @@ ```js | ||
### post | ||
Returns a [Request](#Request) object with the `method` option set to `POST` | ||
Returns a [Request](#request) object with the `method` option set to `POST` | ||
@@ -101,3 +101,3 @@ ```js | ||
Returns a [Request](#Request) object with the `method` option set to `PATCH` | ||
Returns a [Request](#request) object with the `method` option set to `PATCH` | ||
@@ -109,3 +109,3 @@ ```js | ||
### delete | ||
Returns a [Request](#Request) object with the `method` option set to `DELETE` | ||
Returns a [Request](#request) object with the `method` option set to `DELETE` | ||
@@ -607,3 +607,2 @@ ```js | ||
# Response | ||
@@ -618,2 +617,3 @@ | ||
- `headers` (`Object`) - Header details | ||
- `cookies` (`Object`) - Cookies from `set-cookies`, and `cookie` headers. | ||
- `response` (`Object`) - Original Response from `mikeal/request` library. | ||
@@ -642,2 +642,17 @@ | ||
- `forbidden` (`Boolean`) - Status Code `403`? | ||
- `error` (`Boolean` | `Object`) - Dependant on status code range. | ||
- `error` (`Boolean` | `Object`) - Dependant on status code range. | ||
## response.cookie(name) | ||
Sugar method for retrieving a cookie from the `response.cookies` object. | ||
```js | ||
var CookieJar = unirest.jar(); | ||
CookieJar.add(unirest.cookie('another cookie=23')); | ||
unirest.get('http://google.com').jar(CookieJar).end(function (response) { | ||
// Except google trims the value passed :/ | ||
console.log(response.cookie('another cookie')); | ||
}); | ||
``` |
@@ -45,2 +45,12 @@ var should = require("should"); | ||
}); | ||
it('should correctly handle cookie data.', function (done) { | ||
var CookieJar = unirest.jar(); | ||
CookieJar.add(unirest.cookie('another cookie=23')); | ||
unirest.get('http://google.com').jar(CookieJar).end(function (response) { | ||
response.cookie('another cookie').should.exist; | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -47,0 +57,0 @@ |
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
43709
749
650