{"id":51133677,"url":"https://github.com/trananhtung/content-type","last_synced_at":"2026-06-25T15:01:46.370Z","repository":{"id":366610702,"uuid":"1276848406","full_name":"trananhtung/content-type","owner":"trananhtung","description":"Parse and format HTTP Content-Type / media-type headers (RFC 9110). A faithful Rust port of the content-type npm package. Zero deps, no_std.","archived":false,"fork":false,"pushed_at":"2026-06-22T14:45:28.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-06-22T16:16:43.284Z","etag":null,"topics":["content-type","http","media-type","no-std","rust"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trananhtung.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-22T10:51:43.000Z","updated_at":"2026-06-22T14:46:28.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/trananhtung/content-type","commit_stats":null,"previous_names":["trananhtung/content-type"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/trananhtung/content-type","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trananhtung%2Fcontent-type","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trananhtung%2Fcontent-type/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trananhtung%2Fcontent-type/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trananhtung%2Fcontent-type/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trananhtung","download_url":"https://codeload.github.com/trananhtung/content-type/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trananhtung%2Fcontent-type/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34780126,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-25T02:00:05.521Z","response_time":101,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["content-type","http","media-type","no-std","rust"],"created_at":"2026-06-25T15:01:45.470Z","updated_at":"2026-06-25T15:01:46.363Z","avatar_url":"https://github.com/trananhtung.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# content-type\n\n[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-)\n\n[![Crates.io](https://img.shields.io/crates/v/content-type.svg)](https://crates.io/crates/content-type)\n[![Documentation](https://docs.rs/content-type/badge.svg)](https://docs.rs/content-type)\n[![CI](https://github.com/trananhtung/content-type/actions/workflows/ci.yml/badge.svg)](https://github.com/trananhtung/content-type/actions/workflows/ci.yml)\n[![License](https://img.shields.io/crates/l/content-type.svg)](#license)\n\n**Parse and format HTTP `Content-Type` / media-type headers** (RFC 9110). A faithful\nRust port of the [`content-type`](https://www.npmjs.com/package/content-type) npm\npackage (v2.0.0): a lenient `parse` and a strict, validating `format`. Zero\ndependencies and `#![no_std]`.\n\n```rust\nuse content_type::{parse, format, ContentType};\n\nlet ct = parse(\"text/html; charset=utf-8\");\nassert_eq!(ct.type_, \"text/html\");\nassert_eq!(ct.get_parameter(\"charset\"), Some(\"utf-8\"));\n\nlet ct = ContentType::new(\"application/json\").with_parameter(\"charset\", \"utf-8\");\nassert_eq!(format(\u0026ct).unwrap(), \"application/json; charset=utf-8\");\n```\n\n## Why content-type?\n\nReading and writing the `Content-Type` header is a daily HTTP task — pulling out the\nmedia type and `charset`/`boundary`, or building one correctly (quoting parameter\nvalues that need it). This is the lightweight, string-in/string-out port of the\ncanonical JS implementation. For a richly-typed media-type model, see the `mime`\ncrate; reach for this when you want the simple `{ type, parameters }` round-trip.\n\n```toml\n[dependencies]\ncontent-type = \"0.1\"\n```\n\n## API\n\n| Item | Purpose |\n| --- | --- |\n| `parse(header)` | Parse into a `ContentType` (lenient, never errors) |\n| `parse_with(header, parse_parameters)` | …optionally skipping parameters |\n| `format(\u0026content_type)` | Serialize to a header string (validates) |\n| `ContentType { type_, parameters }` | `new`, `with_parameter`, `get_parameter` |\n\n## Behavior\n\n- `parse` lower-cases the media type and parameter names; parameter values keep their\n  case. When a name repeats, the first value wins. Quoted values are unescaped, and\n  text after a closing quote (up to the next `;`) is ignored.\n- `format` validates: the type must be `token/token`, parameter names must be tokens,\n  and values are emitted bare when they are tokens or quoted (and escaped) otherwise —\n  returning a `FormatError` if a value can't be represented.\n\n## Differences from the npm package\n\nTwo differences exist only for inputs that don't occur in real `Content-Type` headers,\nand both stem from JavaScript runtime behavior rather than the package's intent:\n\n- **Parameter order.** Parameters are kept in header order. The JS package returns a\n  plain object, and V8 iterates *integer-like* keys (e.g. `5`, `1`) first in ascending\n  order ahead of other keys — so for the (unheard-of) case of numeric parameter names,\n  iteration/format order can differ. The set of `(name, value)` pairs is always\n  identical (first occurrence wins).\n- **Unicode lower-casing.** The media type and parameter names are lower-cased with\n  Rust's Unicode lower-casing, which can differ from JS for context-sensitive cases\n  (Greek final sigma) in non-ASCII names. Standard ASCII headers are unaffected.\n\n## Contributors ✨\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the [emoji key](https://allcontributors.org/docs/en/emoji-key) for how each contribution is recognized, and open a PR or issue to get involved.\n\nThanks goes to these wonderful people:\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/trananhtung\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/30992229?v=4?s=100\" width=\"100px;\" alt=\"Tung Tran\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eTung Tran\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/trananhtung/content-type/commits?author=trananhtung\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#maintenance-trananhtung\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\n## License\n\nLicensed under either of [Apache-2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT) at\nyour option.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrananhtung%2Fcontent-type","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrananhtung%2Fcontent-type","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrananhtung%2Fcontent-type/lists"}