# Content-Type with charset

**URL:** <https://www.ruby-forum.com/t/content-type-with-charset/198076>\
**Category:** NGINX\
**Created:** [October 26, 2010, 2:32am UTC](https://www.ruby-forum.com/t/content-type-with-charset/198076 "2010-10-26T02:32:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [October 26, 2010, 2:32am UTC](https://www.ruby-forum.com/t/content-type-with-charset/198076/1 "2010-10-26T02:32:58Z")

</div>

Hello,

I have a case where the origin server behind nginx returns this header:  
Content-Type: application/javascript; charset: UTF-8

Which seems to be valid according for HTTP/1.0 [1] and HTTP/1.1 [2]  
rfcs.

I have gzip\_types set to application/javascript, but the added charset  
part seems to throw off ngx\_http\_test\_content\_type()

This simple patch included below seems to fix it, but it’s not exactly  
production ready.

Is there another way to make this work ?

Thank you,

Matthieu.

[1] [http://www.ietf.org/rfc/rfc1945.txt](http://www.ietf.org/rfc/rfc1945.txt)  
[2] [HTTP/1.1: Header Field Definitions](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html)

----------------------- PATCH -------------------------

— tmp/tmpHfGmfb-meld/src/http/ngx\_http\_core\_module.c  
+++ home/mtourne/Dev/nginx/src/http/ngx\_http\_core\_module.c  
@@ -1652,11 +1659,15 @@  
hash = 0;

```
     for (i = 0; i < len; i++) {

```

- 

```
       if (r->headers_out.content_type.data[i] == ';') {

```

- 

```
           break;

```

- 

```
       }
       c = ngx_tolower(r->headers_out.content_type.data[i]);
       hash = ngx_hash(hash, c);
       lowcase[i] = c;
   }

```

- 

```
   len = r->headers_out.content_type_len = i;
   r->headers_out.content_type_hash = hash;

```

}

–  
Matthieu T.

---

<div class="post-metadata">

**Author:** ![Matthieu\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@Matthieu\_T](https://www.ruby-forum.com/u/Matthieu_T)\
**Post date:** [October 26, 2010, 10:03am UTC](https://www.ruby-forum.com/t/content-type-with-charset/198076/2 "2010-10-26T10:03:24Z")

</div>

Hello!

On Mon, Oct 25, 2010 at 05:31:35PM -0700, Matthieu T. wrote:

> Hello,
> 
> I have a case where the origin server behind nginx returns this header:  
> Content-Type: application/javascript; charset: UTF-8
> 
> Which seems to be valid according for HTTP/1.0 [1] and HTTP/1.1 [2] rfcs.

This doesn’t looks valid. Valid one will look like

Content-Type: application/javascript; charset=UTF-8

Parameters should be in form 'attribute “=” value, see here:

> **[RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1 | RFC Editor](https://www.rfc-editor.org/info/rfc2616/)**
>
> HTTP has been in use by the World-Wide Web global information initiative since 1990. This specification defines the protocol referred to as "HTTP/1.1", and is an update to RFC 2068. \[STANDARDS-TRACK\]

> **[RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1 | RFC Editor](https://www.rfc-editor.org/info/rfc2616/)**
>
> HTTP has been in use by the World-Wide Web global information initiative since 1990. This specification defines the protocol referred to as "HTTP/1.1", and is an update to RFC 2068. \[STANDARDS-TRACK\]

> I have gzip\_types set to application/javascript, but the added charset  
> part seems to throw off ngx\_http\_test\_content\_type()
> 
> This simple patch included below seems to fix it, but it’s not exactly  
> production ready.
> 
> Is there another way to make this work ?

Valid charset specifications should work as is. Other parameters  
will confuse content type testing, but this isn’t believed to be  
widely used.

Maxim D.

---

<div class="post-metadata">

**Author:** ![Matthieu\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@Matthieu\_T](https://www.ruby-forum.com/u/Matthieu_T)\
**Post date:** [October 26, 2010, 10:12am UTC](https://www.ruby-forum.com/t/content-type-with-charset/198076/3 "2010-10-26T10:12:12Z")

</div>

Ive seen other applications drop the quotes too maybe nginx should be  
less  
strict?

---

<div class="post-metadata">

**Author:** ![Matthieu\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@Matthieu\_T](https://www.ruby-forum.com/u/Matthieu_T)\
**Post date:** [October 26, 2010, 6:36pm UTC](https://www.ruby-forum.com/t/content-type-with-charset/198076/4 "2010-10-26T18:36:39Z")

</div>

Hello!

On Tue, Oct 26, 2010 at 07:10:52PM +1100, SplitIce wrote:

> Ive seen other applications drop the quotes too maybe nginx should be less  
> strict?

ENOPARSE

nginx accepts what is allowed per HTTP specs, including  
quoted-string as value.

Quoting already provided links:

> > [RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1 | RFC Editor](http://tools.ietf.org/html/rfc2616#section-3.7)  
> > [RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1 | RFC Editor](http://tools.ietf.org/html/rfc2616#section-3.6)

Maxim D.

p.s. Please do not top-post. Thank you.
