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
fix: support non-lower-case Content-Type header provided by app #516
fix: support non-lower-case Content-Type header provided by app #516
Conversation
The changes in #511 change what headers get set by PDFKit and make all headers set by PDFKit lower-case. However, the changes also affect code depending on headers set by the app - which for Rack 2.x apps will be 'Content-Type'. To address this, the code should check if Content-Type is present and in that case use it, otherwise default to content-type. As the code also sets this header (changing the content type to 'application/pdf'), it should set the same header that the original value is retrieved from. So decide on the exact header name first, store it in the 'content_type_header' variable, and use it to index the headers dict. Fix #515.
@serene , please let me know whether happy to merge this PR or whether any changes and/or clarification are needed. |
@vladimir-mencl-eresearch Please add a test that covers this case |
As rack 3.x outright rejects mixed case headers, this test has to be marked as pending - but passes (without the pending flag) with rack 2.x.
Hi @serene , Thanks, I've just added the tests. Note that as rack 3.x outright rejects mixed case headers, the test for the mixed case scenario had to be marked as pending - but passes (without the Cheers, |
Hi @serene , I've made the Please let me know whether you're happy with this. Cheers, |
I got bitten by this too, I'm also setting |
Hi @exviva , Yes, that's correct, the code now checks for and updates the content-disposition header under the lower-case name If you set that from your app, the easiest would be to update the app to set the header lowercase. I made this PR because Rack 2.x apps do not set the content-type header explicitly and Rack 2.x implicitly sets it as While the trick I used hear could also be extended to Content-Disposition, if you control it from within the app, it might be easiest to change it in the app. Please let me know if it works for you. Cheers, |
Gotcha, thanks a lot @vladimir-mencl-eresearch! |
The changes in #511 change what headers get set by PDFKit and make all headers set by PDFKit lower-case.
However, the changes also affect code depending on headers set by the app - which for Rack 2.x apps will be 'Content-Type'.
To address this, the code should check if
Content-Type
is present and in that case use it, otherwise default to content-type.As the code also sets this header (changing the content type to
'application/pdf'
), it should set the same header that the original value is retrieved from.So decide on the exact header name first, store it in the
content_type_header
variable, and use it to index the headers dict.Fix #515.