How to change default character encoding configuration in Jetty app server from UTF-8 to ISO-8859-1 - utf-8

I want my application to support ISO-8859-1 fully in jetty server. But I am Unable to change the default character encoding to ISO-8859-1. Where do i need to set the encoding/charsets?
This is for jetty-distribution-9.4.12, running a struts web application. I have tried modifying the webdefault.xml for encoding mappings. But somehow it fails to take UTF-8 for encoding.
I am seeing an issue when giving a name to an XML resource with japanese chars(私のユーザー). jetty server always fails in taking this name to my resource. when I check in the request I see that the content type is UTF-8 and HTTP 1.1 spec.
I want my server to support in taking my resource name as 私のユーザー. In order to make this happen, I wanted to add that compatibility to the server.
However, with the little knowledge I have, done some research tried to do some configurations in the server but nothing seems to work.
Trial 1
Changing the web-default.xml with locale-encoding
<locale-encoding-mapping>
<locale>en</locale>
<encoding>ISO-8859-1</encoding>
</locale-encoding-mapping>
Trial 2
adding the encoding property to the JAVA_OPTIONS in jetty.sh file
JAVA_OPTIONS+=("-Dfile.encoding=UTF-8")
referred links
Jetty Character encoding issue
Jetty 9, character encoding UTF-8

Jetty uses the current HTTP/1.1 specs (yep, all of these specs talk about current HTTP/1.1 specific behavior)
RFC7230: HTTP/1.1: Message Syntax and Routing
RFC7231: HTTP/1.1: Semantics and Content
RFC7232: HTTP/1.1: Conditional Requests
RFC7233: HTTP/1.1: Range Requests
RFC7234: HTTP/1.1: Caching
RFC7235: HTTP/1.1: Authentication
I think the most relevant spec to your question is from RFC7231 - Appendix B: Updates from RFC2616
The default charset of ISO-8859-1 for text media types has been
removed; the default is now whatever the media type definition says.
Likewise, special treatment of ISO-8859-1 has been removed from the
Accept-Charset header field. (Section 3.1.1.3 and Section 5.3.3)
The idea of ISO-8859-1 being the default charset has long ago been deprecated, the only place you'll find ISO-8859-1 indicated as a default charset is in old specs that have now been labelled as "obsolete" (such as RFC2616).
Timeline:
The older HTTP/1.1 spec, RFC2616, was released in 1999.
The faults in RFC2616 were identified and a revised spec started being discussed in 2006.
The updated specs RFC7230 thru RFC7235 were release in June 2014.
All of the major browser vendors (Chrome, Firefox, Edge, Safari, etc..) updated that year to support RFC7230 and related specs.
Over the years since, the major browser have started to drop RFC2616 concepts and support, removing behaviors, and even quietly dropping features that are from other obsolete specs (eg: older Set-Cookie header syntax now result in a no-op on the browser side, with the cookie being dropped).
Today (Sept 2019):
The HTTP 1.1 protocol has a default character encoding of UTF-8.
The HTTP 1.1 document default character encoding is UTF-8.
The HTTP 2 protocol has a default character encoding of UTF-8.
The HTTP 2 document default character encoding is UTF-8.
What all Web Developers today are responsible for:
You MUST limit your HTTP 1.1 protocol usages (headers names, header values) to US-ASCII.
Header names should follow HTTP 1.1 token rules. (this is a subset of US-ASCII)
Header values that contain a character outside of US-ASCII 1, MUST be encoded first in UTF-8 and then the hex values percent-encoded for representation in the header value.
If you intend to send a ISO-8859-1 document as a response body, then you MUST indicate as such in the HTTP Response Content-Type header the mime-type and charset. (eg: Content-Type: text/html; charset=ISO-8859-1)
But seeing as you didn't indicate where in the HTTP exchange you are wanting to set this default character encoding, it's hard to express a detailed answer/solution to your issue. (eg: it could be a problem with your encoding of application/x-www-form-urlencoded request body content and its interaction with the Servlet spec? which can be fixed with an additional field in your HTML5 form btw)
1: This might seem harsh, but if you check RFC 7230: 3.2.4 Field Parsing you'll see that the existence of characters in the header fields of HTTP outside of US-ASCII will at best be dropped, or at worst be interpreted to be a obs-fold or obs-text character rendering the entire request as bad resulting in a (400 Bad Request).
Historically, HTTP has allowed field content with text in the
ISO-8859-1 charset [ISO-8859-1], supporting other charsets only
through use of [RFC2047] encoding. In practice, most HTTP header
field values use only a subset of the US-ASCII charset [USASCII].
Newly defined header fields SHOULD limit their field values to
US-ASCII octets. A recipient SHOULD treat other octets in field
content (obs-text) as opaque data.

Related

Why is expires header response set to future date with max-age=0?

I noticed an odd behaviour with the expires property in the HTTP response header sent by Google Cloud Storage.
Though, the cache-control is defined with max-age:0 for the file in the metadata (as visible in the screenshot), the expires property is set to a date one year in the future (second screenshot). Why is this date set to the future?
The problematic thing with this behaviour is, that the most recent Firefox versions (v.77 and v.78) seem to interprete the expires property, though it is stated in the documentation, that it will not if max-age is defined (see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expires). For livestream video playback with HLS, this behaviour leads to buffering after short time, because the manifest is cached by the browser. There is already a bug report on mozilla#bugzilla on this behaviour (see https://bugzilla.mozilla.org/show_bug.cgi?id=1648075).
Update
Further investigation showed, that Firefox is not the problem in this case, they just changed the interpretation of the header properties and stick to the documentation since v.77, where '=' is defined as needed character, not ':'. Obviously, other browsers (and FF up to v.76) interprete it also correctly with ':'.
Therefore, in our case the issue needs to be solved inside the service writing the files to our GCS.
It's hard to say why Google Cloud Storages is doing this. Perhaps the Expires is a default, while the Cache-Control is used for custom user settings? More likely, it's just an oversight.
The important point is that this behavior is allowed, and would be harmless with compliant browsers due to the explicit precedence of max-age:
If a response includes a Cache-Control field with the max-age directive (Section 5.2.2.8), a recipient MUST ignore the Expires field.
So the real issue is that Firefox is not conforming to the HTTP specification. Hopefully that bug will be fixed soon.

UTF-8 encoding Google Apps Email Settings API

I've been using Google Apps Email Settings API for a while but I came to a problem when I tried to insert aliases, signatures or any information with "ñ" or "Ñ". It adds garbage instead of those characters and it doesn't seem to respect the charset specified (utf-8) in the HTTP header nor the XML character encoding.
I have tried via my own python code and also using OAuth Playground[1] but it's been impossible to properly add the mentioned characters.
¿Any idea/suggestion?
Thanks in advance.
EDIT: It seems that the problem is not in the request but in the response. I have encoded it successfully in my code but it should be also fixed in OAuth Playground.
[1] https://developers.google.com/oauthplayground/
I have succesfully called Google API client methods using UTF8-encoded strings, so it is definitely an issue with your Python setup.
I would workaround this issue sending Unicode strings instead of UTF-8 encoded:
u'literal string' # This is unicode
'encoded utf-8 string'.decode('utf-8') # This is unicode
EDIT: Re-reading your answer it seems that you are making raw HTTP calls with hand-made XML documents. I can't understand why. If it's the way you want to go, take a look into Emails Settings API client code to learn how to build the XML documents.

Why is my de-chunked request missing the ending CRLF?

I've just spent the past 10 hours trying to figure out why my http request was failing when I did a
request.Content.ReadAsMultipartAsync().Result.Contents
It kept returning the error:
Unexpected end of MIME multipart stream. MIME multipart message is not complete.
After many hours of research, I finally discovered that the request did not have an ending CRLF, which apparently .Net needs to determine the end of the request. When I added my own CRLF, everything worked great.
In WireShark, I looked at one of the requests, I saw that the chunked request did have an ending CRLF, but the De-Chunked request did not.
So that leaves me with 2 questions.
Why is my request missing the ending CRLF, and
Is there any way to add it back before it gets to .Net so that .Net will process it correctly? Or, can I tell .Net to not look for the ending CRLF?
The two CRLFs that you circled in the last chunk of the chunked mode are part of the chunked transfer encoding, which specifies a CRLF after the number of bytes in each chunk (zero in the last chunk of the request/response entity) and an additional CRLF after the whole thing (see RFC 2616, section 3.6.1). MIME multipart (RFC 2046, section 5.1.1) does not require a CRLF after the last boundary, so the service you're receiving the entity from is not wrong when it doesn't add it. OTOH, the old .NET multipart parser was buggy in rejecting it. The ASP.NET team fixed the issue late last year, so you just need to use an up-to-date System.Net.Http.Formatting (ASP.NET WebApi client libraries 5.1.0 should be OK). If you absolutely can't use the up-to-date assembly, then, to work around the problem, I'd wrap the underlying stream with a special wrapper stream that supplies the trailing CRLF.

arabic url in codeigniter at internet explorer

I'm using codeigniter 2.1.1
when i run any url like :
www.mysite.com/search/عربي
$key = "عربي";
it worked with all browsers except internet explorer
and IE say: Undefined variable key
According to the standards (RFC1738), URLs can only contain ASCII characters. Non-ASCII characters must be encoded. This is a rare case of IE being more standards compliant than other browsers.
I believe you'll find if you use something like HTTP Watch that the other browsers are encoding them to send to the server anyway, just displaying the Unicode characters in the address bar...

How to test webservice for unicode handling

Are there test tools available to test if a webservice can handle unicode utf-8 encoded posts? How do I generate utf-8 encoded data?
The sad-but-true answer is that there is no way to know what encoding some program expects if they don't either document it, or provide encoding metadata in whatever protocol you're using.
As for generating utf-8, well, that depends on what programming language you're using.

Resources