Behavior inconsistency with `request` re: `tough-cookie` integration
See original GitHub issueNormally I’d try to dig more for an explanation, but I’m a bit confounded here. I’m doing some cookie construction / management by hand via tough-cookie
to maintain sessions for my API calls, and it looks like request
and request-promise
are giving me two different behaviors, where request
works but request-promise
does not.
The problematic code is as follows
const request = require('request');
const requestPromise = require('request-promise');
const tough = require('tough-cookie');
let sessionCookie = new tough.Cookie({
key: "some_key",
value: "some_value",
domain: 'api.mydomain.com',
httpOnly: true,
maxAge: 31536000
});
let cookiejar = request.jar();
cookiejar.setCookie(sessionCookie, 'https://api.mydomain.com'); // does not throw an error
let sessionCookie2 = new tough.Cookie({
key: "some_key",
value: "some_value",
domain: 'api.mydomain.com',
httpOnly: true,
maxAge: 31536000
});
let cookiejar2 = requestPromise.jar();
cookiejar2.setCookie(sessionCookie2, 'https://api.mydomain.com'); // TypeError: str.trim is not a function
Is it just a version/dependency thing? Am I just abusing the concept of cookie jars beyond repair? From my package.json:
"request": "^2.81.0",
"request-promise": "^4.2.0",
"tough-cookie": "^2.3.2",
I’m leaving the request.jar()
patch in for now, but I’d love to know what’s going wrong exactly
Thanks in advance, Scotty
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:20 (6 by maintainers)
Top Results From Across the Web
Managing Difficult Employees and Disruptive Behaviors - SHRM
This toolkit looks at some of the most common disruptive employee behaviors, identifies the potential risks to the organization if the behavior is...
Read more >Tough Cookies - Scott Helme
Cookies are tiny pieces of data attached to requests that your browser sends. Their most important use is for authentication so that a...
Read more >Top 10 Most Common Spring Framework Mistakes - Toptal
Assess where your application might cause trouble and preemptively log all crucial data. If an error occurs, you will be grateful to have...
Read more >How to deal with difficult clients (and avoid them!) | Ignition Blog
One or two difficult clients are common in business, but as with most things in life, prevention is better than a cure. Try...
Read more >Data Consistency Checks - Slack Engineering
They are the single source of truth for our most critical business data, ... As we develop software, the business logic we apply...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Same here with this
Yet, replacing the last 2 lines with:
cookieJar.setCookie(cookieDetails.toString(), `https://${ domain }`);
seems to solve this. 🤨
toString(). It’s work for me