File tree Expand file tree Collapse file tree 3 files changed +23
-7
lines changed Expand file tree Collapse file tree 3 files changed +23
-7
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,22 @@ const html = template(templateData);
125
125
const pdf = await htmlPdf .create (html, options);
126
126
```
127
127
128
+ ### HTTP Headers
129
+
130
+ Specify additional headers you wish to send with your request via ` CreateOptions.extraHTTPHeaders ` .
131
+
132
+ ``` js
133
+ const options: HtmlPdf .CreateOptions = {
134
+ port: 9222 , // port Chrome is listening on
135
+ extraHTTPHeaders: {
136
+ ' Authorization' : ' Bearer 123' ,
137
+ ' X-Custom-Test-Header' : ' This is great!' ,
138
+ },
139
+ };
140
+
141
+ const pdf = await HtmlPdf .create (' https://httpbin.org/headers' , options);
142
+ ```
143
+
128
144
### Custom Headers and Footers
129
145
130
146
_ Note: Requires Chrome 65 or later._
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " html-pdf-chrome" ,
3
- "version" : " 0.5 .0" ,
3
+ "version" : " 0.6 .0" ,
4
4
"description" : " HTML to PDF converter via Chrome/Chromium" ,
5
5
"main" : " lib/src/index.js" ,
6
6
"scripts" : {
Original file line number Diff line number Diff line change @@ -121,21 +121,21 @@ describe('HtmlPdf', () => {
121
121
expect ( pdf . getRawTextContent ( ) ) . to . startWith ( 'Cookies:status=Passed!' ) ;
122
122
} ) ;
123
123
124
- it ( 'should generate a PDF and send extra http headers' , async ( ) => {
124
+ it ( 'should generate a PDF and send extra HTTP headers' , async ( ) => {
125
125
const options : HtmlPdf . CreateOptions = {
126
126
port,
127
127
extraHTTPHeaders : {
128
- 'X-Custom-Test-Header1' : 'Passed1! ' ,
129
- 'X-Custom-Test-Header2' : 'Passed2 !' ,
128
+ 'Authorization' : 'Bearer 123 ' ,
129
+ 'X-Custom-Test-Header' : 'Passed1 !' ,
130
130
} ,
131
131
} ;
132
132
133
- const result = await HtmlPdf . create ( 'http ://httpbin.org/headers' , options ) ;
133
+ const result = await HtmlPdf . create ( 'https ://httpbin.org/headers' , options ) ;
134
134
const pdf = await getParsedPdf ( result . toBuffer ( ) ) ;
135
135
const rawTextContent = pdf . getRawTextContent ( ) ;
136
136
137
- expect ( rawTextContent ) . to . contain ( 'X-Custom-Test-Header1 ' ) . and . to . contain ( 'Passed1! ' ) ;
138
- expect ( rawTextContent ) . to . contain ( 'X-Custom-Test-Header2 ' ) . and . to . contain ( 'Passed2 !' ) ;
137
+ expect ( rawTextContent ) . to . contain ( 'Authorization ' ) . and . to . contain ( 'Bearer 123 ' ) ;
138
+ expect ( rawTextContent ) . to . contain ( 'X-Custom-Test-Header ' ) . and . to . contain ( 'Passed1 !' ) ;
139
139
} ) ;
140
140
141
141
it ( 'should proxy console messages' , async ( ) => {
You can’t perform that action at this time.
0 commit comments