>
> I have problems that my UTF8 file is displayed wrongly in the browser -
>
>   https://wordsbyfarber.com/Consts-ru.js
>

That is because the document itself is saved in the "windows-1252" charset.
No amount of fiddling with the `Content-Type` will fix that.
You'll have to fix your source document to be UTF-8 first.

Joakim Erdfelt / joa...@webtide.com


On Tue, Oct 3, 2023 at 9:35 AM Alexander Farber via jetty-users <
jetty-users@eclipse.org> wrote:

> Thank you Joakim for the extensive answer, however -
>
> On Tue, Oct 3, 2023 at 2:23 PM Joakim Erdfelt via jetty-users <
> jetty-users@eclipse.org> wrote:
>
>> 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.
>>
>> 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>
>>
>
> I have problems that my UTF8 file is displayed wrongly in the browser -
>
>   https://wordsbyfarber.com/Consts-ru.js
>
> The browser displays pairs of junk characters instead of cyrillic letters
> and from my (limited) experience having ";charset=utf8" in the header would
> help it.
>
> So I have followed your suggestion and have extended the
> src/main/webapp/WEB-INF/web.xml with:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app metadata-complete="false"
>          version="3.1"
>          xmlns="http://xmlns.jcp.org/xml/ns/javaee";
>          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
> http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd";>
>     <servlet>
>         <servlet-name>WordsServlet</servlet-name>
>         <servlet-class>de.afarber.WordsServlet</servlet-class>
>     </servlet>
>     <servlet-mapping>
>         <servlet-name>WordsServlet</servlet-name>
>         <url-pattern>/</url-pattern>
>     </servlet-mapping>
>     <mime-mapping>
>         <extension>js</extension>
>         <mime-type>text/javascript;charset=UTF-8</mime-type>
>     </mime-mapping>
> </web-app>
>
> Unfortunately the URL still returns the headers without "UTF-8" in there:
>
> HTTP/1.1 200 OK
> last-modified: Tue, 03 Oct 2023 09:52:40 GMT
> content-type: text/javascript
> accept-ranges: bytes
> vary: Accept-Encoding
> content-encoding: gzip
> server: Jetty(10.0.16)
> connection: close
>
> Best regards
> Alex
>
> _______________________________________________
> jetty-users mailing list
> jetty-users@eclipse.org
> To unsubscribe from this list, visit
> https://www.eclipse.org/mailman/listinfo/jetty-users
>
_______________________________________________
jetty-users mailing list
jetty-users@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/jetty-users

Reply via email to