Skip to content

Commit

Permalink
alvarcarto#106: fixed GET request cookies query params
Browse files Browse the repository at this point in the history
  • Loading branch information
grigorii-zander committed Aug 1, 2019
1 parent 098dff8 commit 1091975
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ viewport.hasTouch | boolean | `false` | Specifies if viewport supports touch eve
viewport.isLandscape | boolean | `false` | Specifies if viewport is in landscape mode.
cookies[0][name] | string | - | Cookie name (required)
cookies[0][value] | string | - | Cookie value (required)
cookies[0][url] | string | - | Cookie url
cookies[0][domain] | string | - | Cookie domain
cookies[0][url] | string | - | Cookie url (`url` OR `domain` required)
cookies[0][domain] | string | - | Cookie domain (`url` OR `domain` required)
cookies[0][path] | string | - | Cookie path
cookies[0][expires] | number | - | Cookie expiry in unix time
cookies[0][httpOnly] | boolean | - | Cookie httpOnly
Expand Down
1 change: 1 addition & 0 deletions src/http/render-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const postRender = ex.createRoute((req, res) => {

function getOptsFromQuery(query) {
const opts = {
cookies: query.cookies,
url: query.url,
attachmentName: query.attachmentName,
scrollPage: query.scrollPage,
Expand Down
42 changes: 39 additions & 3 deletions test/test-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,43 @@ describe('POST /api/render', () => {
})
);

it('cookies should exist on the page', () =>
it('GET /api/render: cookies should exist on the page', () =>
request(app)
.get('/api/render')
.query({
url: 'http://www.html-kit.com/tools/cookietester/',
'cookies[0][name]': 'url-to-pdf-test',
'cookies[0][value]': 'test successful',
'cookies[0][domain]': 'www.html-kit.com',
'cookies[1][name]': 'url-to-pdf-test-2',
'cookies[1][value]': 'test successful 2',
'cookies[1][domain]': 'www.html-kit.com',
})
.set('Connection', 'keep-alive')
.set('content-type', 'application/json')
.expect(200)
.expect('content-type', 'application/pdf')
.then((response) => {
if (DEBUG) {
console.log(response.headers);
console.log(response.body);
fs.writeFileSync('cookies-pdf-http-get.pdf', response.body, { encoding: null });
}

return getPdfTextContent(response.body);
})
.then((text) => {
if (DEBUG) {
fs.writeFileSync('./cookies-content-http-get.txt', text);
}

chai.expect(text).to.have.string('Number-of-cookies-received-2');
chai.expect(text).to.have.string('Cookie-named-url-to-pdf-test');
chai.expect(text).to.have.string('Cookie-named-url-to-pdf-test-2');
})
);

it('POST /api/render: cookies should exist on the page', () =>
request(app)
.post('/api/render')
.send({
Expand All @@ -162,14 +198,14 @@ describe('POST /api/render', () => {
if (DEBUG) {
console.log(response.headers);
console.log(response.body);
fs.writeFileSync('cookies-pdf.pdf', response.body, { encoding: null });
fs.writeFileSync('cookies-pdf-http-post.pdf', response.body, { encoding: null });
}

return getPdfTextContent(response.body);
})
.then((text) => {
if (DEBUG) {
fs.writeFileSync('./cookies-content.txt', text);
fs.writeFileSync('./cookies-content-http-post.txt', text);
}

chai.expect(text).to.have.string('Number-of-cookies-received-2');
Expand Down

1 comment on commit 1091975

@andriiholovko
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could please some one explain how to use cookies (ex. python requests) with this new functionals?

Please sign in to comment.