Skip to content

SpringEncoder Charset determination is too simple #357

@ghost

Description

Story

A user writes a MessageConverter implementation that they wish to use via SpringEncoder. This message converter produces binary payloads.

Attempts to do so, however, have the request treated as though it were in the UTF8 charset, regardless of the actual content. This causes the request to be encoded and interpreted incorrectly. This holds true even if the custom converter specifies a charset parameter in the request content type(s) that it supports!

Steps to Reproduce

  1. Create a new MessageConverter that is not derived from ByteArrayMessageConverter or ProtobufHttpMessageConverter. The converter should produce a binary request (non-text contents) with a suitable request content type, such as application/octet-stream.
  2. Configure a SpringEncoder with this message converter.
  3. Attempt to send a request with a body consisting of content converted by this message converter.
  4. Observe that the request is treated as being in UTF8 encoding.

Cause

The logic in question begins on line 128 of SpringEncoder.

Proposed Solution

Two potential solutions (not mutually exclusive) would be:

  1. Honor any request content types set by the MessageConverter. If the converter sets a content type with a charset parameter, use that as the encoding for the Request.Body instance.
  2. Extend SpringEncoder such that a message converter may be configured with a charset override (i.e. "whenever calling this converter, assume a specific charset for the body encoding".
  3. Failing the above, at least limit the default behavior to cases where it would make sense. Treating a request with a content type of application/octet-stream as being in UTF8 is not a safe assumption. (Same goes for most if not all of the non-text types + subtypes.)

Please let me know if anything is unclear or if you need more information.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions