Skip to content

[DO-NOT-REVIEW] http: generalize reply's Content-Type setting #2743

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 2 commits into
base: master
Choose a base branch
from

Conversation

tchaikov
Copy link
Contributor

for testing the change on top of #2729

nyh and others added 2 commits April 14, 2025 10:05
For setting a content type on a reply in the HTTP server, we had two
different methods - one set_mime_type() which accepted only full MIME
types (e.g., "text/html"), and one set_content_type() which took a
file extension (e.g, "html") and looked it up in a short map we had,
like a tiny version of /etc/mime.types.

But some reply methods like write_body() and done() only called
set_content_type() meaning they could only set content types from that
short list of known types - and not any general MIME type.
This forced Seastar users to jump through hoops to use additional mime
types - for example to call write_body() on a wrong type and then call
set_mime_type() to override it, or patch the extension map to add more
and more types to it.

This patch fixes this problem for good: With this patch, we no longer
have two different reply methods - there is just one, set_content_type().
The name set_mime_type() remains a deprecated alias.
The merged set_content_type() can recognize *either* a full-fledged MIME
type like "text/html", or if there is no slash in the name - it is looked
up in the list of extensions (e.g., "html").

While doing this, I also changed the set_content_type() from taking
a "const sstring&" like in the old days, to the more modern
std::string_view. I believe this will not cause problems for
applications, as a const sstring& can be implicitly converted into an
std::string_view so old code should continue to compile.

Fixes scylladb#964
Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
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