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

Access-Control-Allow-Origin erros using the send method #26

Closed
PedroPMS opened this issue Feb 28, 2021 · 6 comments
Closed

Access-Control-Allow-Origin erros using the send method #26

PedroPMS opened this issue Feb 28, 2021 · 6 comments

Comments

@PedroPMS
Copy link

Hello,

I have been using this library as part of a project in conjunction with phpwkhtmltopdf library.

Whenever I use the send method after creating the pdf, a cors error occurs because there is no Access-Control-Allow-Origin header, an alternative would be interesting to be able to include some headers before the response to the client. The same to phpwkhtmltopdf.

@mikehaertl
Copy link
Owner

mikehaertl commented Mar 1, 2021

Would an extra parameter $headers help? The signature of the send method would then be:

send($filename = null, $contentType = null, $inline = false, $headers = array())

This way you could also override some of the default headers like Cache-Control, etc.

@PedroPMS
Copy link
Author

PedroPMS commented Mar 1, 2021

Yes, this will be fantastic!

mikehaertl added a commit that referenced this issue Mar 1, 2021
@mikehaertl
Copy link
Owner

@PedroPMS I've prepared a MR for this change. Could you maybe help test it and check if it works for you? You'd have to check this standalone outside of phpwkthmltopdf, though.

The new features:

  • Pass headers as 4th arg to send() in the form ['Header-name' => 'header value', ...]
  • Define default headers in File::$defaultHeaders
    But be careful here: don't override default values, instead add them like File::$defaultHeaders['MyHeader'] => 'Some value';
  • Override auto-generated headers like ['Content-Length' => 12345, ...]
  • Suppress auto-generated headers with ['Content-Length' => false, ...]

@PedroPMS
Copy link
Author

PedroPMS commented Mar 1, 2021

I did some tests and it worked very well. Either using defaultHeaders or passing to the send method.

image
image

Thank you very much!

@PedroPMS
Copy link
Author

PedroPMS commented Mar 1, 2021

Override and suppress auto-generated also worked very well.

@mikehaertl
Copy link
Owner

@PedroPMS I've released 1.2.1 containing this change. I've also opened a MR over at phpwkhtmltopdf: mikehaertl/phpwkhtmltopdf#367

As it's hard to test these things with phpunit, maybe you could help again? It would be great if you could comment on the issue there: mikehaertl/phpwkhtmltopdf#366

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