Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include custom cookies in request #54

Closed
chips5k opened this issue Mar 20, 2017 · 7 comments
Closed

Include custom cookies in request #54

chips5k opened this issue Mar 20, 2017 · 7 comments

Comments

@chips5k
Copy link
Contributor

chips5k commented Mar 20, 2017

Hi, not sure where else to post this, but i need the ability to include a cookie when phantom js requests a file. I can see how i might do this by modifying your source code (which i'd rather not do), but i cannot work out where/how and in what format to supply cookies in the initial conversion function.

Below is the code i am using, i'd assumed i could just pass a cookies property in the options object. Tried several different formats, and tried to trace through your code but had no luck.

conversion({
url: request.post.location',
// waitForJS: true,
// waitForJSVarName: 'ready_to_print'
}, function(err, pdf) {
console.log(pdf.logs);
console.log(pdf.numberOfPages);
pdf.stream.pipe(response);
});

Tried:

cookie: [[name, value]]
cookie: [{name: name, value: value}]
cookie: ["name=value"]

None of the above worked.

I've looked at phantomjs itself which recommends using addCookie methods, but since i dont have access to the phantom objects themselves, im not sure how to go about this (again without modifying the code).

thanks!

Callem.

@pofider
Copy link
Owner

pofider commented Mar 20, 2017

Hi,

you are right. This requires extending this package. Don't you want to try to implement this and send PR?

  1. Extend the conversion function options parameter with cookies object
  2. Iterate over the object properties in the phantomjs script and call addCookie
  3. The unit test could simply just add cookie, write it to console.log and assert the correct value is in the output.
  4. Update readme

The PR would be basically the same as this one - https://github.com/pofider/phantom-html-to-pdf/pull/46/files
You would probably only use object instead of array to pass cookies.

What you think?

@chips5k
Copy link
Contributor Author

chips5k commented Mar 20, 2017 via email

@chips5k
Copy link
Contributor Author

chips5k commented Mar 21, 2017 via email

@pofider
Copy link
Owner

pofider commented Mar 21, 2017

Ok, sure....

The final scripts distributed to npm are created in npm prepublish or during npm tests.
=> The state of git master vs npm latest is currently the same except some minor changes done to readme which were not released yet.

@chips5k
Copy link
Contributor Author

chips5k commented Mar 21, 2017 via email

@chips5k
Copy link
Contributor Author

chips5k commented Mar 21, 2017 via email

@pofider
Copy link
Owner

pofider commented Mar 23, 2017

Released in 0.5.0, big thanks to @chips5k for contribution

@pofider pofider closed this as completed Mar 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants