Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Setting text/javascript encoding to utf8 with Jetty 10.0.16

Per the _javascript_ RFC, the `text/_javascript_` mime-type has an optional `charset` parameter.
The behavior is documented at https://datatracker.ietf.org/doc/html/rfc9239#name-charset-parameter

Essentially, if the charset is unspecified, then the encoding is UTF-8.

> the encoding is unfortunately not set to utf8 (like it is for the served json files).

For JSON, the charset parameter is not used.
Per spec, JSON is always UTF-8.
See: https://www.rfc-editor.org/rfc/rfc8259#section-8.1

In Jetty, the json encoding is specified as an assumed UTF-8.
See: https://github.com/eclipse/jetty.project/blob/jetty-10.0.16/jetty-http/src/main/resources/org/eclipse/jetty/http/encoding.properties
This means the `charset` parameter is not produced when generating the `Content-Type` header, and is ignored when parsing the `Content-Type` header.

 > Is there a way to enforce that without compiling a custom version of Jetty?

You can customize the in-place `MimeTypes` for a context.

Examples:

servletContextHandler.getMimeTypes().addMimeMapping("txt", "text/_javascript_;charset=UTF-8");
or
webappContext.getMimeTypes().addMimeMapping("txt", "text/_javascript_;charset=UTF-8");

or, If you have a WEB-INF/web.xml in your webapp, you can add a `<mime-mapping>` entry.

  <mime-mapping>
    <extension>js</extension>
    <mime-type>text/_javascript_;charset=UTF-8</mime-type>
  </mime-mapping>

Joakim Erdfelt / joakim@xxxxxxxxxxx


On Tue, Oct 3, 2023 at 5:02 AM Alexander Farber via jetty-users <jetty-users@xxxxxxxxxxx> wrote:
Hello,

I am using Jetty 10.0.16 and when it serves static _javascript_ files (I have Consts-en.js, Consts-de.js, Consts-fr.js, ...) the encoding is unfortunately not set to utf8 (like it is for the served json files).

Is there a way to enforce that without compiling a custom version of Jetty?

I have searched on the internet and also here:

# find /usr/share/java/jetty-home-10.0.16 -type f -iname \*.prop\*
/usr/share/java/jetty-home-10.0.16/modules/deprecated.properties
/usr/share/java/jetty-home-10.0.16/modules/demo.d/demo-realm.properties
/usr/share/java/jetty-home-10.0.16/modules/demo.d/demo-login.properties
/usr/share/java/jetty-home-10.0.16/modules/sessions/infinispan/remote/resources/hotrod-client.properties
/usr/share/java/jetty-home-10.0.16/modules/jolokia/jolokia-realm.properties
/usr/share/java/jetty-home-10.0.16/modules/logging/jul/resources/java-util-logging-bridge.properties
/usr/share/java/jetty-home-10.0.16/modules/logging/jul/resources/java-util-logging.properties
/usr/share/java/jetty-home-10.0.16/modules/logging/jetty/resources/jetty-logging.properties
/usr/share/java/jetty-home-10.0.16/etc/jdbcRealm.properties

Thank you for any hints
Alex


_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users

Back to the top