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
PDF file rendered in browser as HTML file #140
Comments
Hi @SserwangaV! Odd indeed. Not sure why the That said, using the "Elements" tab of the inspector can be a little misleading. If you right click the page and choose "View page source", you'll see the actual code being transmitted. The inspecter will create dummy elements to show how the DOM is actually represented internally. You can see this at work if you look at a page like this: https://nitrogenproject.com/demos/viewsource?module=demos_simplecontrols In the inspector, it's creating html, head, body, and pre tags, while if you just do "View Source," it'll just show the raw code. So I wouldn't be alarmed that nitrogen is injecting HTML into your page. Now as for why Further, you can inspect the response in the "Network" tab, and from the "Headers" tab, you'll see what Content-Type is being received by the browser. |
"View page source" shows a blank display (is empty). The response headers are attached. The Content-Type is set to text/html. I expected the Content-Type to be set to application/pdf because I set it as Content-Disposition seems to be set properly. To set it, I used The console error is attached |
I'm still quite stumped here. This is behind an nginx proxy. What is your webserver? Yaws? Is it possible that there is something going on with nginx that's changing the content-type? If you access the nitrogen server directly with a script like this: curl -o /dev/null -s -D headers.txt "http://127.0.0.1:8000/path/to/file"
cat headers.txt That should return the headers of the requested file as they are returned from Nitrogen and passed to nginx. If Nitrogen is returning the proper value, perhaps nginx is doing something with the file? |
It is Nitrogen on Yaws proxied behind Nginx. Without the Nginx proxy, the content-type is set properly to application/pdf. It is the Nginx that modifies it to text/html. I've used The file content-type varies and files binaries are referenced from the database using keys rather than the file names with extensions. File names and extensions (used to determine the content-type upon serving the file) are kept in the database as file metadata. File path takes this format |
Alright, that helps to clarify some things. If nginx is changing the headers, then this is fully an nginx configuration issue (of which I'm no expert). You could try adding the proxy_hide_header Content-Type;
proxy_pass_header Content-Type; |
Tried it, however, it didn't work. I've a local instance of the application on my laptop and on this one Nginx doesn't modify the content-type. It only does it on the one in production. I'm likely to think the nginx version could be an issue. |
I have this code that reads a PDF file as an Erlang binary and sends it to the browser
What disturbs me is that it's rendered as an HTML file! Some time back the same code could render it properly.
The text was updated successfully, but these errors were encountered: