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

Add automatic response type detection #29

Open
nslaughter opened this issue Jan 14, 2021 · 0 comments
Open

Add automatic response type detection #29

nslaughter opened this issue Jan 14, 2021 · 0 comments

Comments

@nslaughter
Copy link
Member

Is your feature request related to a problem? Please describe.
We have html, json, and text responses. We should automate setting of .conent_type attribute by reading from values of these attributes.

Describe the solution you'd like
If a user sets resp.text then the .content_type should be application/text. Likewise if resp.json has a value then the appropriate value can be set in .content_type for that.

Describe alternatives you've considered

  • We could follow starlette here and differentiate JSONResponse, HTMLResponse,... But these types distinctions are actually quite narrow. The HTMLResponse is just a Response with .media_type: str = "text/html". The JSONResponse on the other hand also adds a .render function that handles encoding.
  • On the other hand, httpx and request compatible APIs encode more in the top-level as enumerable string typed fields.
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

No branches or pull requests

1 participant