Skip to content
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

application/json;charset=utf-8 doesn't match expected text content type regex #671

Closed
ProjectZed opened this issue Aug 9, 2019 · 1 comment · Fixed by #673
Closed

application/json;charset=utf-8 doesn't match expected text content type regex #671

ProjectZed opened this issue Aug 9, 2019 · 1 comment · Fixed by #673

Comments

@ProjectZed
Copy link

ProjectZed commented Aug 9, 2019

Bug Report

Description

When an HTTP request comes back with a Content-Type header value of "application/json;charset=utf-8", logging the response Body#representationOfBytes fails to match with this content type because of the missing space.
https://www.rfc-editor.org/rfc/rfc2045#section-5.1 : The original spec outlining Content-Type header formatting doesn't explicitly declare whitespaces to be present before a parameter.
https://tools.ietf.org/html/rfc7231#section-3.1.1.1 : Updates to the spec do explicitly declare an optional whitespace be present before a parameter.

To Reproduce

Steps to reproduce the behavior:

  1. Write a client with:
    FuelManager.instance.addResponseInterceptor { LogResponseInterceptor.invoke(it) }
  2. Make a request to a server that responds with application/json;charset=utf-8 as the content type and a proper JSON body.
  3. Observe when logging the Body:... the actual body is not represented, instead it say (for example): Body: (1024 bytes of application/json;charset=utf-8)

I've copied the regex to a regex tester tool like https://regex101.com/ and tried to match with "application/json;charset=utf-8" but failed. Of course, testing with "application/json; charset=utf-8" passed. A quick modification to the regex allows for both: ^(?:text/.*|application/(?:csv|javascript|json|typescript|xml|x-yaml|x-www-form-urlencoded|vnd\.coffeescript)|.*\+(?:xml|json))(;(?: |)charset=.+)*$

Additionally, application/json media types are generally assumed to be encoded in utf-8 and often times, servers respond with Content-Type simply application/json.

Expected behavior

Logging the response Body should properly log the body opposed to "($lengthLabel of $actualContentType)"

Environment

Development Machine

  • Fuel version: 2.1.0
  • Kotlin version: 1.3.41

Additional Context

I'm writing an Android client which makes REST requests to a Spring Boot server. The MediaType enum: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/MediaType.html#APPLICATION_JSON_UTF8 does not include a space.

@SleeplessByte
Copy link
Collaborator

Can you open a PR to change the regex? It is correct that the space is not required per the spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants