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 responses as JSON only if required to. #175

Merged
merged 1 commit into from Jun 6, 2017

Conversation

mostrows2
Copy link

A JSON response will have "application/json", and only if this is set should
the response content be decoded as such. Otherwise (until something smarter
comes along), on might as well return the raw response content (which
happens to be the correct thing to do for "text/plain" content).

A JSON response will have "application/json", and only if this is set should
the response content be decoded as such.  Otherwise (until something smarter
comes along), on might as well return the raw response content (which
happens to be the correct thing to do for "text/plain" content).
@coveralls
Copy link

Coverage Status

Coverage increased (+0.006%) to 97.449% when pulling 28ec4af on mostrows2:mostrows/non-json-response into 3d66a18 on Yelp:master.

Copy link
Contributor

@sjaensch sjaensch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! This change looks sensible to me.

content_value = response.json()
content_type = response.headers.get('content-type', '').lower()

if content_type.startswith(APP_JSON):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason you went with startswith instead of equality?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To opportunistically capture "application/json-rpc" should that ever occur? Admittedly this test may need to evolve over time since there are various other content types that could contain json. I don't feel strongly about this either way.

@sjaensch
Copy link
Contributor

sjaensch commented Jun 6, 2017

This might be a breaking change for users where the server isn't sending the correct content type header. I'm wondering if we should make this behavior configurable, i.e. add an option to make bravado-core behave the way it used to. The other option would be to ship this as-is and wait for user feedback. Thoughts?

@mostrows2
Copy link
Author

mostrows2 commented Jun 6, 2017 via email

@sjaensch
Copy link
Contributor

sjaensch commented Jun 6, 2017

Yeah, that sounds reasonable. Let's make sure we release this as a major version.

@sjaensch sjaensch merged commit e3441dc into Yelp:master Jun 6, 2017
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 this pull request may close these issues.

None yet

3 participants