From 10919750a30efc48c772bb66e6a2508e7f0aa88b Mon Sep 17 00:00:00 2001 From: Grigorii Zander Date: Thu, 1 Aug 2019 14:27:59 +0300 Subject: [PATCH] #106: fixed GET request cookies query params --- README.md | 4 ++-- src/http/render-http.js | 1 + test/test-all.js | 42 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 03bbd4db..3c39e770 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/http/render-http.js b/src/http/render-http.js index 2a5c2c2d..ec1653a3 100644 --- a/src/http/render-http.js +++ b/src/http/render-http.js @@ -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, diff --git a/test/test-all.js b/test/test-all.js index 8d36c92b..a440fa1c 100644 --- a/test/test-all.js +++ b/test/test-all.js @@ -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({ @@ -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');