I have created perl NGINX module to server static files on the NGINX
(mainly images). For security reasons I am generating the AES:CBC
encrypted
url which I am decrypting on the NGINX and serving the file via NGINX
perl
module. The problem is that I am sometimes getting the bellow response
with
HTTP response code set to 000:
Sending the file to the client with sendfile:
25003 sendfile64(3, 15, [0], 5420) = 5420
So from above it turns out that there were no headers sent and thus the
status code probably defaulted to “000” on NGINX.
Adding the send_http_header before the $r->sendfile() solves the issue.
$r->send_http_header();
Now I have the correct HTTP status code, anyway the content type
defaults
to “application/octet-stream” which is configured as default content
type
on nginx. Well, is there a way to have NGINX correctly set the
Content-Type
after handling the request on perl content handler or should I make my
own
mapping and set the content-type myself in send_http_header ?
Now I have the correct HTTP status code, anyway the content type defaults
to “application/octet-stream” which is configured as default content type
on nginx. Well, is there a way to have NGINX correctly set the Content-Type
after handling the request on perl content handler or should I make my own
mapping and set the content-type myself in send_http_header ?
The Content-Type nginx set by itself is based on an extension as
seen in URI. As there is no extension in URIs you use, it uses
default type. If a default type isn’t what you want - you should
either set response type explicitly, or reconsider URIs used.
In your particular case, I would recommend you to use
$r->internal_redirect() to an internal location instead of trying
to send files yourself. (Or, alternatively, perl_set + rewrite
should also work.) It should be much easier than trying to send
files yourself from perl.