Skip to content

Add content_type for Response #3551

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Sanchoyzer
Copy link

Summary

I would like to suggest adding a little syntax sugar. It might be more convenient to use response.content_type instead of response.headers.get("Content-Type").
I hope I haven't forgotten any places where changes need to be made

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

@Sanchoyzer
Copy link
Author

Hey, @tomchristie , what do you think of this suggestion?

Return the Content-Type header.
"""
result = self.headers.get("Content-Type")
return str(result) if result else None
Copy link
Member

Choose a reason for hiding this comment

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

Why the str() cast? Isn't it str already?

Copy link
Author

Choose a reason for hiding this comment

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

It's not str, it's Any

class Headers(typing.MutableMapping[str, str]):
    def get(self, key: str, default: typing.Any = None) -> typing.Any:
        ...

@Kludex
Copy link
Member

Kludex commented May 30, 2025

I think this is not needed, but we can see what other maintainers think about it.

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.

2 participants