| 1 |
# mime_guess  [](https://crates.io/crates/mime_guess) |
| 2 |
|
| 3 |
MIME/MediaType guessing by file extension. |
| 4 |
Uses a static map of known file extension -> MIME type mappings. |
| 5 |
|
| 6 |
**Returning Contributors: New Requirements for Submissions Below** |
| 7 |
|
| 8 |
##### Required Rust Version: 1.33 |
| 9 |
|
| 10 |
#### [Documentation](https://docs.rs/mime_guess/) |
| 11 |
|
| 12 |
### Versioning |
| 13 |
|
| 14 |
Due to a mistaken premature release, `mime_guess` currently publicly depends on a pre-1.0 `mime`, |
| 15 |
which means `mime` upgrades are breaking changes and necessitate a major version bump. |
| 16 |
Refer to the following table to find a version of `mime_guess` which matches your version of `mime`: |
| 17 |
|
| 18 |
| `mime` version | `mime_guess` version | |
| 19 |
|----------------|----------------------| |
| 20 |
| `0.1.x, 0.2.x` | `1.x.y` | |
| 21 |
| `0.3.x` | `2.x.y` | |
| 22 |
|
| 23 |
#### Note: MIME Types Returned Are Not Stable/Guaranteed |
| 24 |
The media types returned for a given extension are not considered to be part of the crate's |
| 25 |
stable API and are often updated in patch (`x.y.z + 1`) releases to be as correct as possible. MIME |
| 26 |
changes are backported to previous major releases on a best-effort basis. |
| 27 |
|
| 28 |
Note that only the extensions of paths/filenames are inspected in order to guess the MIME type. The |
| 29 |
file that may or may not reside at that path may or may not be a valid file of the returned MIME type. |
| 30 |
Be wary of unsafe or un-validated assumptions about file structure or length. |
| 31 |
|
| 32 |
An extension may also have multiple applicable MIME types. When more than one is returned, the first |
| 33 |
is considered to be the most "correct"--see below for elaboration. |
| 34 |
|
| 35 |
Contributing |
| 36 |
----------- |
| 37 |
|
| 38 |
#### Adding or correcting MIME types for extensions |
| 39 |
|
| 40 |
Is the MIME type for a file extension wrong or missing? Great! |
| 41 |
Well, not great for us, but great for you if you'd like to open a pull request! |
| 42 |
|
| 43 |
The file extension -> MIME type mappings are listed in `src/mime_types.rs`. |
| 44 |
**The list is sorted lexicographically by file extension, and all extensions are lowercase (where applicable).** |
| 45 |
The former is necessary to support fallback to binary search when the |
| 46 |
`phf-map` feature is turned off, and for the maintainers' sanity. |
| 47 |
The latter is only for consistency's sake; the search is case-insensitive. |
| 48 |
|
| 49 |
Simply add or update the appropriate string pair(s) to make the correction(s) needed. |
| 50 |
Run `cargo test` to make sure the library continues to work correctly. |
| 51 |
|
| 52 |
#### Important! Citing the corrected MIME type |
| 53 |
|
| 54 |
When opening a pull request, please include a link to an official document or RFC noting |
| 55 |
the correct MIME type for the file type in question **in the commit message** so |
| 56 |
that the commit history can be used as an audit trail. |
| 57 |
|
| 58 |
Though we're only guessing here, we like to be as correct as we can. |
| 59 |
It makes it much easier to vet your contribution if we don't have to search for corroborating material. |
| 60 |
|
| 61 |
#### Multiple MIME types per extension |
| 62 |
As of `2.0.0`, multiple MIME types per extension are supported. The first MIME type in the list for |
| 63 |
a given extension should be the most "correct" so users who only care about getting a single MIME |
| 64 |
type can use the `first*()` methods. |
| 65 |
|
| 66 |
The definition of "correct" is open to debate, however. In the author's opinion this should be |
| 67 |
whatever is defined by the latest IETF RFC for the given file format, or otherwise explicitly |
| 68 |
supercedes all others. |
| 69 |
|
| 70 |
If an official IANA registration replaces an older "experimental" style media type, please |
| 71 |
place the new type before the old type in the list, but keep the old type for reference: |
| 72 |
|
| 73 |
``` |
| 74 |
- ("md", &["text/x-markdown"]), |
| 75 |
+ ("md", &["text/markdown", "text/x-markdown"]), |
| 76 |
``` |
| 77 |
|
| 78 |
#### Changes to the API or operation of the crate |
| 79 |
|
| 80 |
We're open to changes to the crate's API or its inner workings, breaking or not, if it improves the overall operation, efficiency, or ergonomics of the crate. However, it would be a good idea to open an issue on the repository so we can discuss your proposed changes and decide how best to approach them. |
| 81 |
|
| 82 |
|
| 83 |
License |
| 84 |
------- |
| 85 |
|
| 86 |
MIT (See the `LICENSE` file in this repository for more information.) |