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

handle custom content types #2594

Closed
wants to merge 1 commit into from

Conversation

wuan
Copy link

@wuan wuan commented Dec 6, 2017

What do these changes do?

When using a custom content type like application/vnd.aiohttp-test+json the client now ignores content type parameters (e. g. an encoding setting) when checking for matching types.

Are there changes in behavior for the user?

Nothing expected here. Clients which include the parameters in content_type (as a workaround) should still work.

Related issue number

#2206 is somehow related

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> for example (588.bug)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

@wuan wuan force-pushed the handle_custom_content_types branch 4 times, most recently from 57f8bac to 5c59d7a Compare December 6, 2017 17:38
@codecov-io
Copy link

codecov-io commented Dec 6, 2017

Codecov Report

Merging #2594 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2594      +/-   ##
==========================================
+ Coverage   97.87%   97.87%   +<.01%     
==========================================
  Files          38       38              
  Lines        7304     7307       +3     
  Branches     1263     1263              
==========================================
+ Hits         7149     7152       +3     
  Misses         51       51              
  Partials      104      104
Impacted Files Coverage Δ
aiohttp/helpers.py 97.82% <100%> (+0.01%) ⬆️
aiohttp/client_reqrep.py 97.23% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update feaf021...1794690. Read the comment docs.

@asvetlov
Copy link
Member

asvetlov commented Dec 6, 2017

Sorry, I don't follow.
What problem do you want to solve?
What is Content-Type header for your server?

@wuan
Copy link
Author

wuan commented Dec 6, 2017

We are reading data via HTTP and get a response which has a Content-Type header in the form application/vnd.foo+json; encoding=utf-8.

To read JSON data from the response, the full content type has to be specified:

    data = response.json(content_type='application/vnd.foo+json; encoding=utf-8')

As json() already handles the encoding option according to the servers Content-Type header internally, it feels wrong to specify (and even fix) the encoding through the content type string. If the server leaves out that information some day it will even break the client.

This PR will allow us to use

    data = response.json(content_type='application/vnd.foo+json')

and still get a correct response with any of these Content-Type headers: application/vnd.foo+json; encoding=utf-8, application/vnd.foo+json; encoding=cp1251, application/vnd.foo+json

@wuan wuan force-pushed the handle_custom_content_types branch from 5c59d7a to 1794690 Compare December 6, 2017 19:56
@asvetlov
Copy link
Member

asvetlov commented Dec 8, 2017

In requests .json() implementation is pretty simple: it doesn't accept custom content type and encoding.

I have a strong temptation to drop these params from aiohttp client too.

@asvetlov
Copy link
Member

asvetlov commented Dec 8, 2017

Supporting all non-standard combinations for custom json protocol makes a mess.

@wuan
Copy link
Author

wuan commented Dec 12, 2017

I would be fine with dropping the content type verification.

@asvetlov
Copy link
Member

Let's close the PR as wontfix. 3bbe4d7 stresses a way for content type disabling

@asvetlov asvetlov closed this Feb 17, 2018
@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bot:chronographer:provided There is a change note present in this PR outdated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants