Re: [jetty-users] Setting text/javascript encoding to utf8 with Jetty 10.0.16

2023-10-03 Thread Alexander Farber via jetty-users
Thank you, Joakim - your second suggestion has worked well for me:

 webapps/root.xml

http://www.eclipse.org/jetty/configure_9_0.dtd;>

/


index.html




/var/www/html/wordsbyfarber.com
true




js
text/javascript;charset=utf-8




Now I get the following response headers and the file is displayed with
correct international characters in the Microsoft Edge browser:

HTTP/1.1 200 OK
last-modified: Tue, 03 Oct 2023 09:52:40 GMT
content-type: text/javascript;charset=utf-8
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


Re: [jetty-users] Setting text/javascript encoding to utf8 with Jetty 10.0.16

2023-10-03 Thread Joakim Erdfelt via jetty-users
Here's an alternate way to set it up.

My jetty-base ...

[demo-jersey-2]$ tree -F
demo-jersey-2/
├── resources/
│   └── jetty-logging.properties
├── start.d/
│   ├── deploy.ini
│   └── http.ini
└── webapps/
└── jersey.war


This is pretty much all defaults on Jetty.
I have enabled the modules http,deploy only.
If I start this jetty-base and check a javascript, I see what you see.

$ curl --dump-header - -o /dev/null
http://localhost:8080/jersey/js/engine.js
  % Total% Received % Xferd  Average Speed   TimeTime Time
 Current
 Dload  Upload   Total   SpentLeft
 Speed
  0 00 00 0  0  0 --:--:-- --:--:-- --:--:--
  0
HTTP/1.1 200 OK
Last-Modified: Sat, 19 Dec 2020 23:24:00 GMT
Content-Type: text/javascript
Accept-Ranges: bytes
Content-Length: 2669
Server: Jetty(10.0.16)

100  2669  100  26690 0  31086  0 --:--:-- --:--:-- --:--:--
31400


Now if I add a webapps/jetty.xml that has the following contents ...


https://www.eclipse.org/jetty/configure_10_0.dtd;>

  /jersey
  /jersey.war
  

  js
  text/javascript;charset=UTF-8

  



Which makes the jetty-base look like this ...

[demo-jersey-2]$ tree -F
demo-jersey-2/
├── resources/
│   └── jetty-logging.properties
├── start.d/
│   ├── deploy.ini
│   └── http.ini
└── webapps/
├── jersey.war
└── jersey.xml


Now when I start this jetty-base and access the same javascript, I see this
...

$ curl --dump-header - -o /dev/null
http://localhost:8080/jersey/js/engine.js
  % Total% Received % Xferd  Average Speed   TimeTime Time
 Current
 Dload  Upload   Total   SpentLeft
 Speed
  0 00 00 0  0  0 --:--:-- --:--:-- --:--:--
  0
HTTP/1.1 200 OK
Last-Modified: Sat, 19 Dec 2020 23:24:00 GMT
Content-Type: text/javascript;charset=utf-8
Accept-Ranges: bytes
Content-Length: 2669
Server: Jetty(10.0.16)

100  2669  100  26690 0  30899  0 --:--:-- --:--:-- --:--:--
31034


Which includes the charset.

Joakim Erdfelt / joa...@webtide.com
___
jetty-users mailing list
jetty-users@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/jetty-users


Re: [jetty-users] Setting text/javascript encoding to utf8 with Jetty 10.0.16

2023-10-03 Thread Joakim Erdfelt via jetty-users
>
> 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
>> `` entry.
>>
>>   
>> js
>> text/javascript;charset=UTF-8
>>   
>>
>
> 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:
>
> 
>   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;>
> 
> WordsServlet
> de.afarber.WordsServlet
> 
> 
> WordsServlet
> /
> 
> 
> js
> text/javascript;charset=UTF-8
> 
> 
>
> 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


Re: [jetty-users] Setting text/javascript encoding to utf8 with Jetty 10.0.16

2023-10-03 Thread Alexander Farber via jetty-users
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
> `` entry.
>
>   
> js
> text/javascript;charset=UTF-8
>   
>

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:


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;>

WordsServlet
de.afarber.WordsServlet


WordsServlet
/


js
text/javascript;charset=UTF-8



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


Re: [jetty-users] Setting text/javascript encoding to utf8 with Jetty 10.0.16

2023-10-03 Thread Joakim Erdfelt via jetty-users
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
`` entry.

  
js
text/javascript;charset=UTF-8
  

Joakim Erdfelt / joa...@webtide.com


On Tue, Oct 3, 2023 at 5:02 AM Alexander Farber via jetty-users <
jetty-users@eclipse.org> 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@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


[jetty-users] Setting text/javascript encoding to utf8 with Jetty 10.0.16

2023-10-03 Thread Alexander Farber via jetty-users
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@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/jetty-users