Skip to content

http: add xml support to http::mime_types::mappings #2725

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

Merged
merged 1 commit into from
Apr 8, 2025

Conversation

WillemKauf
Copy link
Contributor

It seems strange that xml isn't supported as a mime type here.

In particular, we expect all S3 REST error responses to be returned with a Content-Type header of application/xml, so being able to map the extension makes life a lot easier for testing with imposter http S3 servers/services.

It seems strange that `xml` isn't supported as a `mime` type here.
We expect all S3 REST error responses to be returned with a `Content-Type`
header of `application/xml`, so being able to map the extension here
makes life a lot easier for testing with imposter `http` S3 servers/services.
@avikivity
Copy link
Member

Perhaps we should load /etc/mime-types (and merge with the built-in set of mappings)

@xemul
Copy link
Contributor

xemul commented Apr 8, 2025

There's set_mime_type() that can be used to set whatever "raw" type you need. What's the exact issue you're facing? @WillemKauf

@nyh
Copy link
Contributor

nyh commented Apr 8, 2025

There's set_mime_type() that can be used to set whatever "raw" type you need. What's the exact issue you're facing? @WillemKauf

Note that although set_mime_type() exists, there are other methods which take only that fixed set of mime types, which is silly. So for example when in ScyllaDB Alternator I had the same problem - I wanted to use application/x-amz-json-1.0 but this wasn't one of the mime types on the list - I had to use a random other type, "json", in write_body()

                    rep->write_body("json", std::move(json_return_value._body_writer));

And then override it later with

                    rep->set_mime_type("application/x-amz-json-1.0");
                    rep->done();

This is ugly, and need to be rethought. I don't think adding one or 17 more mime types to the list really solves this problem.

@WillemKauf
Copy link
Contributor Author

What's the exact issue you're facing?

Similar to @nyh's problem above, using function_handler to mock HTTP responses doesn't allow for an application/xml Content-Type header, since rep->done(_type) is called.

I'm getting around this currently via a new impl for handler_base, but I think the mapping is worth adding to avoid having to do this.

@nyh
Copy link
Contributor

nyh commented Apr 8, 2025

I have an idea: What if when the mime type contains a slash, we use it without looking it up in any tables?
I don't see why Seastar needs to contain a long list of popular (and unpopular) mime types if the application can supply the full mime type.

@xemul
Copy link
Contributor

xemul commented Apr 8, 2025

I have an idea: What if when the mime type contains a slash, we use it without looking it up in any tables?

You mean the write_body() methods? Because if you use set_mime_type directly it doesn't look up any tables already. @nyh

@xemul
Copy link
Contributor

xemul commented Apr 8, 2025

I have an idea: What if when the mime type contains a slash, we use it without looking it up in any tables?

You mean the write_body() methods? Because if you use set_mime_type directly it doesn't look up any tables already. @nyh

Ah, it's the function_handler::done(). OK

@nyh
Copy link
Contributor

nyh commented Apr 8, 2025

I have an idea: What if when the mime type contains a slash, we use it without looking it up in any tables?

You mean the write_body() methods?

Yes, write_body() calls set_content_type() instead of set_mime_type() - and set_content_type() is the one that does the lookup and calls set_content_type().
Also done() calls set_content_type() instead of set_mime_type().

I claim that this distinction, between "content type" and "mime type" is simply unnecessary and even misleading (as the set_content_type() today specifies the extension not a MIME or HTTP Content-Type). As you can see in the MIME RFC 2045 section 5.1, https://datatracker.ietf.org/doc/html/rfc2045#section-5.1, a full MIME type always needs to look like type/subtype. E.g., application/json. A string without a slash, like "json", cannot be a full MIME type so it makes sense to look it up in some sort of shortcut table (a la Unix's /etc/mime.types).

I propose the following fix instead of this patch:

  1. Remove one of the two functions set_content_type() or set_mime_type() (both are reasonable names), call only the second one.
  2. Make the one function call the array lookup function only if there is no slash in the given type.

I think this fix will be very easy to do and will avoid a deluge of patches like this one each adding their favorite MIME type. I'll also use the new patch in ScyllaDB instead of an ugly workaround (as I explained above).

I'll open an issue asking for this.

@nyh
Copy link
Contributor

nyh commented Apr 8, 2025

Don't need to open an issue - I already opened one four years ago: #964
Amazing :-)
So if you follow my suggestion, your patch can also "Fixes #964".

@avikivity avikivity merged commit 043d72a into scylladb:master Apr 8, 2025
16 checks passed
@nyh
Copy link
Contributor

nyh commented Apr 8, 2025

I see that despite my recommendation, Avi merged this match.
I still claim that the list of extensions, whether or not it contains xml, is the wrong way to go, and we should do
#964

I'll send a patch to do 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.

4 participants