+2
-1
@@ -23,3 +23,3 @@ | ||
| // Returns a copy str trimmed and without trainling semicolon. | ||
| // Returns a copy str trimmed and without trailing semicolon. | ||
| function cleanCookieString(str) { | ||
@@ -57,2 +57,3 @@ return str.trim().replace(/\x3B+$/, ''); | ||
| if (!header) return {}; | ||
| if (typeof header === 'string' || header instanceof String) header = header.split(';'); | ||
| header = Array.isArray(header) ? header : [header]; | ||
@@ -59,0 +60,0 @@ |
+5
-4
@@ -548,3 +548,2 @@ ////////////////////////////////////////// | ||
| if (utils.host_and_ports_match(headers.location, uri)) { | ||
| config.previous_resp_cookies = resp.cookies; | ||
@@ -555,10 +554,12 @@ // if follow_set_cookies is true, insert cookies in the next request's headers. | ||
| var request_cookies = cookies.read(config.headers['cookie']); | ||
| config.previous_resp_cookies = resp.cookies; | ||
| if (Object.keys(request_cookies).length || Object.keys(resp.cookies || {}).length) { | ||
| config.headers['cookie'] = cookies.write(extend(request_cookies, resp.cookies)); | ||
| } | ||
| } else { | ||
| // set response cookies if present, otherwise remove header | ||
| if (resp.cookies && Object.keys(resp.cookies).length) | ||
| config.headers['cookie'] = cookies.write(resp.cookies); | ||
| else | ||
| // if (resp.cookies && Object.keys(resp.cookies).length) | ||
| // config.headers['cookie'] = cookies.write(resp.cookies); | ||
| // else | ||
| delete config.headers['cookie']; | ||
@@ -565,0 +566,0 @@ } |
+1
-1
| { | ||
| "name": "needle", | ||
| "version": "3.4.0", | ||
| "version": "3.4.1", | ||
| "description": "The leanest and most handsome HTTP client in the Nodelands.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
+1
-1
@@ -365,3 +365,3 @@ Needle | ||
| - `follow_set_cookies` : Sends the cookies received in the `set-cookie` header as part of the following request, *if hosts match*. `false` by default. | ||
| - `follow_set_cookies` : Sends the cookies received in the `set-cookie` header as part of the following request, *if hosts match*, along with the original request cookies (if provided). `false` by default. | ||
| - `follow_set_referer` : Sets the 'Referer' header to the requested URI when following a redirect. `false` by default. | ||
@@ -368,0 +368,0 @@ - `follow_keep_method` : If enabled, resends the request using the original verb instead of being rewritten to `get` with no data. `false` by default. |
+41
-6
@@ -268,2 +268,37 @@ var needle = require('../'), | ||
| describe('with multiple original request cookies', function() { | ||
| var opts = { | ||
| follow_set_cookies: true, | ||
| follow_max: 4, | ||
| cookies: { 'xxx': 123, 'yyy': 456 } | ||
| }; | ||
| it('request cookie is passed passed to redirects, and response cookies are added too', function(done) { | ||
| needle.get('localhost:' + testPort + '/0', opts, function(err, resp) { | ||
| requestCookies.should.eql([ | ||
| "xxx=123; yyy=456", | ||
| "xxx=123; yyy=456; wc=!'*+#()&-./0123456789:<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~; bc=Y29va2llCg==; FOO=123", | ||
| "xxx=123; yyy=456; wc=!\'*+#()&-./0123456789:<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~; bc=Y29va2llCg==; FOO=123; fc=%20%3B%22%5C%2C; nc=12354342", | ||
| "xxx=123; yyy=456; wc=!\'*+#()&-./0123456789:<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~; bc=Y29va2llCg==; FOO=BAR; fc=%20%3B%22%5C%2C; nc=12354342", | ||
| "xxx=123; yyy=456; wc=!\'*+#()&-./0123456789:<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~; bc=Y29va2llCg==; FOO=BAR; fc=%20%3B%22%5C%2C; nc=12354342" | ||
| ]) | ||
| done(); | ||
| }); | ||
| }); | ||
| it('response cookies are passed as well', function(done) { | ||
| needle.get('localhost:' + testPort + '/0', opts, function(err, resp) { | ||
| resp.cookies.should.have.property(WEIRD_COOKIE_NAME); | ||
| resp.cookies.should.have.property(BASE64_COOKIE_NAME); | ||
| resp.cookies.should.have.property(FORBIDDEN_COOKIE_NAME); | ||
| resp.cookies.should.have.property(NUMBER_COOKIE_NAME); | ||
| resp.cookies.should.have.property('FOO'); | ||
| resp.cookies.FOO.should.eql('BAR'); // should overwrite previous one | ||
| done(); | ||
| }); | ||
| }); | ||
| }) | ||
| describe('without original request cookie', function() { | ||
@@ -291,8 +326,8 @@ | ||
| needle.get('localhost:' + testPort + '/0', opts, function(err, resp) { | ||
| // resp.cookies.should.have.property(WEIRD_COOKIE_NAME); | ||
| // resp.cookies.should.have.property(BASE64_COOKIE_NAME); | ||
| // resp.cookies.should.have.property(FORBIDDEN_COOKIE_NAME); | ||
| // resp.cookies.should.have.property(NUMBER_COOKIE_NAME); | ||
| // resp.cookies.should.have.property('FOO'); | ||
| // resp.cookies.FOO.should.eql('BAR'); // should overwrite previous one | ||
| resp.cookies.should.have.property(WEIRD_COOKIE_NAME); | ||
| resp.cookies.should.have.property(BASE64_COOKIE_NAME); | ||
| resp.cookies.should.have.property(FORBIDDEN_COOKIE_NAME); | ||
| resp.cookies.should.have.property(NUMBER_COOKIE_NAME); | ||
| resp.cookies.should.have.property('FOO'); | ||
| resp.cookies.FOO.should.eql('BAR'); // should overwrite previous one | ||
| done(); | ||
@@ -299,0 +334,0 @@ }); |
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 6 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 6 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
328724
0.63%6231
0.5%71
1.43%