What is the default character encoding for sent requests in Wildfly?
Setting the encoding in contentType header of a request would insure that it will be used?
Thanks,
Tiberiu
You are talking about two different encodings
Request encoding: This is the encoding of parameters in the URL for example. By default is UTF-8 but if you want to change it to ISO-8859-1 (for example) it can be done with <http-listener url-charset="ISO-8859-1" .../> in your configuration file under the undertow subsystem.
Content Type encoding: This is the encoding that you are saying your files have and this is controlled by Content-Type http header and the charset parameter. Content-Type: text/html; charset=ISO-8859-1
Related
A zapier web hook has been set up to catch JSON sent to it.
The issue is that if the JSON contains any non-standard characters, e.g. accented characters, the hook never catches the data (no error is displayed, it just doesn't log anything).
Id the catch hook is switched to a 'catch raw hook' then the data is received, but I then don't know how to transform the raw data into JSON for future steps. With the catch raw hook the data caught is e.g. as follows (with a special char ø in the name value):
raw_body
[{"id":2426,"name":"James Hømmett"}]
headers__http_host
hooks.zapier.com
headers__http_x_request_id
b8578a4455fea95c3287e939e304752c
headers__http_x_real_ip
[redacted IP address]
headers__http_x_forwarded_for
[redacted IP address]
headers__http_x_forwarded_host
hooks.zapier.com
headers__http_x_forwarded_port
443
headers__http_x_forwarded_proto
https
headers__http_x_scheme
https
headers__http_x_original_forwarded_for
[redacted IP address]
headers__content_length
559
headers__http_accept_encoding
gzip,deflate
headers__content_type
application/json; charset=utf-8
headers__http_user_agent
Apache-HttpClient/4.5.13 (Java/11.0.9.1)
As you can see charset=utf8 is specified in the content-type header.
The JSON validates with jsonlint.com
Any ideas?
If you're on a paid account, you can add a Code by Zapier step that returns JSON.parse(inputData.raw_body), so that the data is available in future steps.
But, not handling non-ascii characters is likely a bug, so it's worth reaching out to support if you haven't already: https://zapier.com/contact
I'm trying to send json data as a response body in grails. I've tried setting the Content-Type header to application/json using the following methods:
render (status: httpServletResponse, text: responseToRender as JSON, contentType: "application/json")
Each time the resulting header is as follows:
Content-Type: application/json;charset=utf-8
How do I get rid of the charset=UTF-8 postfix?
You can not get rid of the charset postfix.
You can change it with the charset parameter defined here:
https://docs.grails.org/latest/ref/Controllers/render.html
You can also provide no information by just handing json to render, such as:
response.setContentType("application/json")
render JsonOutput.toJson(responseToRender);
However, this will default to the standard encoding required by HTTP 1.1 which is ISO-8859-1. therefore your result would be application/json;charset=ISO-8859-1
https://www.w3.org/International/articles/http-charset/index.en
So, if you somehow need to use this parameter, you may use .split(";")[0] to access only the first part.
Is there any default media type when the query is not specified with any supported media types in RESTCONF ?
No. There is no standard default. This is server implementation dependent, so do not rely on it.
From draft-ietf-netconf-restconf-17, Section 5.3, Message Encoding:
The server MUST support the "Accept" header field and "406 Not
Acceptable" status-line, as defined in [RFC7231]. The response
output content encoding formats that the client will accept are
identified with the Accept header field in the request. If it is not
specified, the request input encoding format SHOULD be used, or the
server MAY choose any supported content encoding format.
If there was no request input, then the default output encoding is
XML or JSON, depending on server preference. File extensions encoded
in the request are not used to identify format encoding.
And from draft-ietf-netconf-restconf-17, Section 7.1, Error Response Message:
The client SHOULD specify the desired encoding(s) for response
messages by specifying the appropriate media-type(s) in the Accept
header. If the client did not specify an Accept header, then the
same structured syntax name suffix used in the request message SHOULD
be used, or the server MAY choose any supported message encoding
format. If there is no request message the server MUST select
"application/yang-data+xml" or "application/yang-data+json",
depending on server preference.
The final RFC stood by the draft, just as #predi said:
On Message Encoding, Section 5.2:
If there was no request input, then the default output encoding is
XML or JSON, depending on server preference. File extensions encoded
in the request are not used to identify format encoding.
And Error Message Response, Section 7.1
If the client did not specify an "Accept" header, then the same
structured syntax name suffix used in the request message SHOULD be
used, or the server MAY choose any supported message-encoding
format. If there is no request message, the server MUST select
"application/yang-data+xml" or "application/yang-data+json",
depending on server preference.
This is kind of related to this post. I am trying to post some form data using TIdHTTP and TIdMultiPartFormDataStream, but when monitoring the communication using Wireshark, each form field gets a content-Type: text/plain attached to it and for some reason the server that I am sending these stuff to does not like it. Is there a way that I can make sure only the name and value is sent?
The Content-Transfer was also being added and I was able to remove that using:
aFieldItem := PostStream.AddFormField(fName, fValue);
aFieldItem.ContentTransfer := '';
but I cannot find any way to get rid of content type.
At this moment the data that is being sent looke like this (in Wireshark)
Boundary: \r\n----------051715151353026\r\n
Encapsulated multipart part: (text/plain)
Content-Disposition: form-data; name="description"\r\n
Content-Type: text/plain\r\n
Line-based text data: text/plain
\r\n
Testing new AW Mobile
and I want it to look like:
Boundary: \r\n------WebKitFormBoundary32hCBG8zkGMBpxqL\r\n
Encapsulated multipart part:
Content-Disposition: form-data; name="description"\r\n
Data (21 bytes)
Data: 0d0a5465737420616e6420747261636520636f6d6d
Length: 21
Thank you
Sam
HTML5 Section 4.10.22.7 alters how RFC 2388 applies to webform submissions:
The parts of the generated multipart/form-data resource that correspond to non-file fields must not have a Content-Type header specified. Their names and values must be encoded using the character encoding selected above (field names in particular do not get converted to a 7-bit safe encoding as suggested in RFC 2388).
This is different from RFC 2388:
As with all multipart MIME types, each part has an optional "Content-Type", which defaults to text/plain.
Your server is clearly expecting the HTML5 behavior.
The Content-Type header on each MIME part added to TIdMultipartFormDataStream is hard-coded and cannot be removed without altering TIdMultipartFormDataStream's source code can be omitted by setting the TIdFormDataField.ContentType property to a space character (not a blank string, like the ContentTransfer property allows):
aFieldItem := PostStream.AddFormField(fName, fValue);
aFieldItem.ContentTransfer := '';
aFieldItem.ContentType := ' '; // <-- here
If you set the ContentType property to a blank string, it will set the Content-Type header to application/octet-stream, but assigning a space character instead has a side effect of omitting the header when the property setter parses the new value.
That being said, I have already made some changes to TIdMultipartFormDataStream to account for this change in webform submission in HTML5, but I have not finalized and released it yet.
On Net::HTTP.Get request to a URL with accept-encoding header set as gzip, how do I check if the response is gzipped, before calling Zlib unzipping on it?
Found the answer, doing a response['Content-Encoding'] returns gzip if the response is Gzip encoded and nil otherwise. Discovered the param value by inspecting the browser HTTP response headers.