-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3 Problems in WARequest>>#bodyDecoded #1357
Comments
We discussed this with @JoachimTuchel and I proposed than instead of falling back to a default codec if no charset is specified in the content type, we could fall back to the request context codec, which will likely be UTF-8. Something like: WARequest>>#bodyDecoded
"Comment TBD."
| contentType charSet |
contentType := self contentType.
charSet := contentType isNil ifFalse: [contentType charSet].
^ charSet isNil
ifTrue: [self requestContext codec
ifNil: [WAIllegalStateException signal: 'no character set of request body can not be determined']
ifNotNil: [:requestCodec | body isNil ifFalse: [requestCodec decode: body]]]
ifFalse: [self bodyDecodeUsing: charSet] |
Getting back to this old issue/question... First off:
About using a default fallback then. From the spec (https://www.rfc-editor.org/rfc/rfc9110.html#field.content-type):
In the situation that no 'Content-Type' header was present, we would also default to the fallback, but I think that should not be allowed to happen. I suggest to only fallback to the encoding of the adaptor (i.e. the requestContext codec) if a 'Content-Type' header was present with a non-binary media type (text/plain, text/html,...). So, only use a default charSet in the case of non-binary mediatypes. I think we will want to error if the specified mimetype is "non-decodable" anyway, rather than silently trying to decode something that will not make sense. What do you think @eMaringolo ? |
Suggestion: bodyDecoded
"Answer the body decoded using the character set in the request header. Answer nil if no body is present. Signal an error if no character set is present in the request header."
| contentType charSet |
contentType := self contentType.
contentType ifNil: [ WAIllegalStateException signal: 'Content type of request body cannot be determined.' ].
charSet := contentType charSet.
^ charSet
ifNil: [
self requestContext codec
ifNil: [ WAIllegalStateException signal: 'Character set of request body cannot be determined.' ]
ifNotNil: [ :requestCodec | body ifNotNil: [ requestCodec decode: body ] ] ]
ifNotNil: [ self bodyDecodeUsing: charSet ] |
Just assuming a character set / encoding when one was not provided and the contents is not binary will just open a back door to introduce the kind of encoding problems we have been trying to fix for year. |
I think there are 3 Problems with
WARequest>>bodyDecoded
"**_no_** character set of request body can **_not_** be determined"
The text was updated successfully, but these errors were encountered: