question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Behavior inconsistency with `request` re: `tough-cookie` integration

See original GitHub issue

Normally 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:closed
  • Created 6 years ago
  • Reactions:10
  • Comments:20 (6 by maintainers)

github_iconTop GitHub Comments

16reactions
guillaumegarcia13commented, Jun 15, 2018

Same here with this

const cookieJar = rp.jar();
const cookie: request.Cookie | string = request.cookie(cookieDetails.toString()) || '';
cookieJar.setCookie(cookie, `https://${ domain }`);

Yet, replacing the last 2 lines with: cookieJar.setCookie(cookieDetails.toString(), `https://${ domain }`);

seems to solve this. 🤨

8reactions
fXy-duringcommented, Aug 24, 2018

cookieJar.setCookie(cookie.toString(), https://${ domain });

toString(). It’s work for me

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found