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

Update mime crate #738

Closed
mitsuhiko opened this issue Feb 29, 2016 · 10 comments
Closed

Update mime crate #738

mitsuhiko opened this issue Feb 29, 2016 · 10 comments

Comments

@mitsuhiko
Copy link
Contributor

This is more of a suggestion than a bug, but it would appear that modelling mimetypes as anything other than raw strings is ridiculous overkill. Maybe some alternative method can be found where they are represented as a tuple (mimetype, attributes) instead?

@ghost
Copy link

ghost commented Feb 29, 2016

This enforces the typing system on it, the same goes for many parts of Hyper. It's actually a great feature, that ensures no cases are forgotten, and will make the compiler yell at you for any typo.

@mitsuhiko
Copy link
Contributor Author

@MichaelZapataScality I fail to see how that ensures no cases are forgotten. Can you clarify what you mean by that?

@ghost
Copy link

ghost commented Feb 29, 2016

On a match? (It may be a bad example though, what I really meant was that you could only get in parts of code dealing with a signature like fn foo(bar: Mime) when you are sure that this is a mimetype, making the signature totally explicit/reliable)

@mitsuhiko
Copy link
Contributor Author

I fail to see how match is helping though. First of all if something is Ext or not is pretty random at the moment. For instance you ned to use ext for all common vendor mimetypes. Secondly because of ext you can already not handle all. But ultimately you can make up completely bogus mimetypes with the current system anyways (for instance nobody stops you from making an image/json).

A tuple mime type would still be a separate type.

@seanmonstar
Copy link
Member

I agree, the mime crate needs some work. I've been working on a re-working of it, where a Mime just has several Name values. the Name struct is wrapper around str that provides some syntax guarantees, such that a Name only includes characters allowed by the spec. Otherwise, all the current variants I've converted into constants, so mime::Json still exists and can be used in match expressions.

@seanmonstar seanmonstar modified the milestone: 1.0 May 24, 2016
@seanmonstar seanmonstar changed the title Mime Library is Overkill Update mime crate Jul 13, 2016
@seanmonstar
Copy link
Member

The work-in-progress rewrite: https://github.com/hyperium/mime.rs/tree/ng

  • Needs something to determine when a parameter can be case-insensitive, such as Charset.
  • Operator overloads are cute, but may be the devil.
  • Some optimization could be added to reduce the amount of Strings allocated during parsing (such as comparing to a list of common constants).

@puhrez
Copy link
Contributor

puhrez commented Jul 15, 2016

👀

@crawford
Copy link

crawford commented Dec 4, 2016

But ultimately you can make up completely bogus mimetypes with the current system anyways (for instance nobody stops you from making an image/json).

@mitsuhiko IANA regulates the MIME types, so they would be the ones stopping you. You could make something follow the same string format that MIME types use, but it would not be a MIME type. That's what the type system guarantees.

@mitsuhiko
Copy link
Contributor Author

@crawford the type system does not guarnatee that at all. As mentioned the type system allows me to construct image/json which is not a registered mimetype.

@seanmonstar
Copy link
Member

So it's been a while, but I finally got around to having a redesign I think I like. See hyperium/mime#50

@seanmonstar seanmonstar removed this from the 1.0 milestone Dec 10, 2017
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

4 participants