Welcome! Log In Create A New Profile

Advanced

Re: Invalid content types served when using alias

Vladimir Shebordaev
October 25, 2012 10:20PM
Hi!

Well, just in case, this inlined version of ngx_http_set_exten()
function seems to set r->exten in non-intrusive way when it is
not known from URI but can be obtained from the file redirect path

Index: src/http/modules/ngx_http_static_module.c
===================================================================
--- src/http/modules/ngx_http_static_module.c (revision 4892)
+++ src/http/modules/ngx_http_static_module.c (working copy)
@@ -224,6 +224,24 @@
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}

+ if (!r->exten.len) {
+ last = path.data + path.len - 1;
+ while (last > path.data + 1) {
+ if (last[-1] == '.' && last[-2] != '/') {
+
+ r->exten.data = last;
+ r->exten.len = path.len - (last - path.data);
+
+ break;
+
+ } else if (last[-1] == '/') {
+ break;
+ }
+
+ last--;
+ }
+ }
+
if (ngx_http_set_content_type(r) != NGX_OK) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}

This way, the MIME type guessed from the file redirect extension
is sent to client instead of the default one, when it is not
known from the original URI.

Otherwise, I'd suggest to update an 'alias' directive
documentation to explicitly state that the default MIME type is
used when it can not be guessed from the original location URI
even if it is a file alias.

Hope it helps.

Regards,
Vladimir

On 24.10.2012 18:32, Maxim Dounin wrote:
> Hello!
>
> On Wed, Oct 24, 2012 at 05:59:33PM +0400, Vladimir Shebordaev wrote:
>
>> Hi!
>>
>> On 24.10.2012 03:50, Tom van der Woerdt wrote:
>>> Hi all,
>>>
>>> I'm using nginx' locations to serve a javascript file on '/client' :
>>>
>>> location = /client {
>>> expires epoch;
>>> alias /path/to/a/file.js;
>>> }
>>>
>>> Works fine, with one major exception: it gets an octet-stream
>>> Content-Type header.
>>
>> This is due to a bug in static module, it doesn't properly set
>> r->exten in this case, so the redirect gets default mime-type.
>
> As already explained by Igor, this is not a bug, but intentional
> behaviour.
>
> Extension as seen in the URI is used to determine mime type, not
> one on the file system (which might not be present at all).
>
>>
>> Please try this patch
>>
>> Index: src/http/modules/ngx_http_static_module.c
>> ===================================================================
>> --- src/http/modules/ngx_http_static_module.c (revision 4892)
>> +++ src/http/modules/ngx_http_static_module.c (working copy)
>> @@ -224,6 +224,9 @@
>> return NGX_HTTP_INTERNAL_SERVER_ERROR;
>> }
>>
>> + r->uri = path;
>> + ngx_http_set_exten(r);
>> +
>> if (ngx_http_set_content_type(r) != NGX_OK) {
>> return NGX_HTTP_INTERNAL_SERVER_ERROR;
>> }
>
> The patch is completely incorrect. While it might work for you in
> this particular case, it
>
> a) Breaks the behaviour which is expected to work (in contrast to
> the above), e.g. like this:
>
> location = /foo.js {
> alias /path/to/a/file;
> }
>
> b) Breaks unrelated things like the $uri variable.
>
>

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Invalid content types served when using alias

Tom van der Woerdt 2793 October 23, 2012 07:50PM

Re: Invalid content types served when using alias

wandenberg 1130 October 23, 2012 11:08PM

Re: Invalid content types served when using alias Attachments

Tom van der Woerdt 875 October 24, 2012 05:00AM

Re: Invalid content types served when using alias

wandenberg 923 October 24, 2012 06:02AM

Re: Invalid content types served when using alias Attachments

Tom van der Woerdt 761 October 24, 2012 06:06AM

Re: Invalid content types served when using alias

wandenberg 1053 October 24, 2012 07:46AM

Re: Invalid content types served when using alias Attachments

Tom van der Woerdt 732 October 24, 2012 07:54AM

Re: Invalid content types served when using alias

wandenberg 967 October 24, 2012 08:00AM

Re: Invalid content types served when using alias Attachments

Tom van der Woerdt 954 October 24, 2012 08:04AM

Re: Invalid content types served when using alias

Igor Sysoev 887 October 24, 2012 10:08AM

Re: Invalid content types served when using alias

Vladimir Shebordaev 754 October 24, 2012 10:00AM

Re: Invalid content types served when using alias

Tom van der Woerdt 670 October 24, 2012 10:24AM

Re: Invalid content types served when using alias

Maxim Dounin 639 October 24, 2012 10:34AM

Re: Invalid content types served when using alias

Vladimir Shebordaev 622 October 24, 2012 03:40PM

Re: Invalid content types served when using alias

Vladimir Shebordaev 778 October 25, 2012 10:20PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 203
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready