WebAssembly / WASI

WebAssembly System Interface
Other
4.92k stars 258 forks source link

Stream `media_type` should be Option<String> #491

Open badeend opened 2 years ago

badeend commented 2 years ago

input_media_type and output_media_type mention:

Returns */* if the Media Type is unknown.

As far as I know, in the world of HTTP the string "*/*" is only used as a wildcard in places where a content type filter is expected (Accept header), indicating any content type will do. It is never used as a content type accompanying actual data. For these scenario's where the content type is unknown, "application/octet-stream" is generally used.

Additionally, according to RFC-7231 the content type should preferably not be set at all:

A sender that generates a message containing a payload body SHOULD generate a Content-Type header field in that message unless the intended media type of the enclosed representation is unknown to the sender. If a Content-Type header field is not present, the recipient MAY either assume a media type of "application/octet-stream" or examine the data to determine its type.

That leads me to think input_media_type & output_media_type should be changed to be an Option type returning None if the content type is unknown. Alternative solution would be to return an empty string, or "application/octet-stream". But not "*/*".

References:

sunfishcode commented 2 years ago

I've transferred this from wasi-io to the main WASI repo, as wasi-io is being subsumed by the wit stream type. The wit-stream type doesn't have a built in concept of a media_type, however this is functionality that WASI could add an API to support.