{"id":41178505,"url":"https://github.com/aohorodnyk/mimeheader","last_synced_at":"2026-01-22T20:02:04.138Z","repository":{"id":45437635,"uuid":"377672224","full_name":"aohorodnyk/mimeheader","owner":"aohorodnyk","description":"Library to work with MimeHeaders and other mime types. Library supports wildcards and parameters.","archived":false,"fork":false,"pushed_at":"2024-05-31T01:37:45.000Z","size":48,"stargazers_count":24,"open_issues_count":2,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-06-18T21:38:15.439Z","etag":null,"topics":["accept","accept-header","accept-header-parser","accept-parser","go","go-accept-header","go-http-header","go-library","go-mimetype","go-mod","go-module","go-package","golang","mime-parser","mime-type","mimetype","mimetype-parser"],"latest_commit_sha":null,"homepage":"https://aohorodnyk.com/post/2021-07-03-mime-headers/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aohorodnyk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-17T01:34:30.000Z","updated_at":"2024-06-18T21:38:15.440Z","dependencies_parsed_at":"2022-08-28T10:21:58.933Z","dependency_job_id":null,"html_url":"https://github.com/aohorodnyk/mimeheader","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/aohorodnyk/mimeheader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aohorodnyk%2Fmimeheader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aohorodnyk%2Fmimeheader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aohorodnyk%2Fmimeheader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aohorodnyk%2Fmimeheader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aohorodnyk","download_url":"https://codeload.github.com/aohorodnyk/mimeheader/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aohorodnyk%2Fmimeheader/sbom","scorecard":{"id":200863,"data":{"date":"2025-08-11","repo":{"name":"github.com/aohorodnyk/mimeheader","commit":"d558c2af0f1b953e999019246e575da6126c42a2"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.4,"checks":[{"name":"Code-Review","score":0,"reason":"Found 1/13 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/go.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/aohorodnyk/mimeheader/go.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/go.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/aohorodnyk/mimeheader/go.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/aohorodnyk/mimeheader/go.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/aohorodnyk/mimeheader/go.yml/main?enable=pin","Info:   0 out of   3 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 4 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-16T22:47:57.568Z","repository_id":45437635,"created_at":"2025-08-16T22:47:57.568Z","updated_at":"2025-08-16T22:47:57.568Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28670295,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T19:36:09.361Z","status":"ssl_error","status_checked_at":"2026-01-22T19:36:05.567Z","response_time":144,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["accept","accept-header","accept-header-parser","accept-parser","go","go-accept-header","go-http-header","go-library","go-mimetype","go-mod","go-module","go-package","golang","mime-parser","mime-type","mimetype","mimetype-parser"],"created_at":"2026-01-22T20:01:55.940Z","updated_at":"2026-01-22T20:02:04.132Z","avatar_url":"https://github.com/aohorodnyk.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mime header\n[![Go (tests and linters)](https://github.com/aohorodnyk/mimeheader/actions/workflows/go.yml/badge.svg)](https://github.com/aohorodnyk/mimeheader/actions/workflows/go.yml) ![GitHub](https://img.shields.io/github/license/aohorodnyk/mimeheader) ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/aohorodnyk/mimeheader/Go) ![GitHub issues](https://img.shields.io/github/issues/aohorodnyk/mimeheader) ![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/aohorodnyk/mimeheader)\n\n## RFC reference\nImplementation of mime types and [Accept header support (RFC 2616 Sec 14.1)](https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1).\n\n## Motivation\nThis library created to help people to parse media type data, like headers, and store and match it.\nThe main features of the library are to:\n* Save a type as a structure (it can help pass mime type as an argument to a function or use as a field of a structure)\n* Match mime types by a wildcard. It can be helpful for Accept header negotiation\n* MUST be covered by tests to provide guarantees it works well\n* Zero dependencies\n\n## Examples\n### Match a header with text\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/aohorodnyk/mimeheader\"\n)\n\n// Content-Type - application/json;q=0.9;p=2\nfunc parse(contentType string) {\n\tmtype, err := mimeheader.ParseMediaType(contentType)\n\n\tfmt.Println(err)                                 // nil\n\tfmt.Println(mtype.MatchText(\"application/json; param=1\")) // true\n\tfmt.Println(mtype.MatchText(\"application/xml; param=1\"))  // false\n\tfmt.Println(mtype.MatchText(\"*/plain; param=1\"))          // false\n\tfmt.Println(mtype.MatchText(\"text/plain; param=1\"))       // false\n}\n```\n\n### Match accept header\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/aohorodnyk/mimeheader\"\n)\n\n// Accept - application/json;q=1.0,*/*;q=1.0; param=wild,image/png;q=1.0;param=test\nfunc parse(acceptHeader string) {\n\tah := mimeheader.ParseAcceptHeader(acceptHeader)\n\n\tfmt.Println(ah.Negotiate([]string{\"application/json;param=1\", \"image/png\"}, \"text/javascript\")) // image/png, image/png, true\n}\n```\n\n### Accept header HTTP middleware\n[OWASP](https://cheatsheetseries.owasp.org/cheatsheets/REST_Security_Cheat_Sheet.html#send-safe-response-content-types) suggests using this middleware in all applications.\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"log\"\n\t\"net/http\"\n\n\t\"github.com/aohorodnyk/mimeheader\"\n)\n\nfunc main() {\n\tr := http.NewServeMux()\n\n\tr.HandleFunc(\"/\", acceptHeaderMiddleware([]string{\"application/json\", \"text/html\"})(handlerTestFunc))\n\n\terr := http.ListenAndServe(\":8080\", r)\n\tif err != nil {\n\t\tlog.Fatalln(err)\n\t}\n}\n\nfunc acceptHeaderMiddleware(acceptMimeTypes []string) func(http.HandlerFunc) http.HandlerFunc {\n\treturn func(next http.HandlerFunc) http.HandlerFunc {\n\t\treturn func(rw http.ResponseWriter, r *http.Request) {\n\t\t\theader := r.Header.Get(\"Accept\")\n\t\t\tah := mimeheader.ParseAcceptHeader(header)\n\n\t\t\t// We do not need default mime type.\n\t\t\t_, mtype, m := ah.Negotiate(acceptMimeTypes, \"\")\n\t\t\tif !m {\n\t\t\t\t// If not matched accept mim type, return 406.\n\t\t\t\trw.WriteHeader(http.StatusNotAcceptable)\n\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// Add matched mime type to context.\n\t\t\tctx := context.WithValue(r.Context(), \"resp_content_type\", mtype)\n\t\t\t// New requet from new context.\n\t\t\trc := r.WithContext(ctx)\n\n\t\t\t// Call next middleware or handler.\n\t\t\tnext(rw, rc)\n\t\t}\n\t}\n}\n\nfunc handlerTestFunc(rw http.ResponseWriter, r *http.Request) {\n\tmtype := r.Context().Value(\"resp_content_type\").(string)\n\trw.Write([]byte(mtype))\n}\n```\n\nRequests example\n```http request\nGET http://localhost:8080/\nAccept: text/*; q=0.9,application/json; q=1;\n\n# HTTP/1.1 200 OK\n# Date: Sat, 03 Jul 2021 19:14:58 GMT\n# Content-Length: 16\n# Content-Type: text/plain; charset=utf-8\n# Connection: close\n\n# application/json\n\n###\n\nGET http://localhost:8080/\nAccept: text/*; q=1,application/json; q=1;\n\n# HTTP/1.1 200 OK\n# Date: Sat, 03 Jul 2021 19:15:51 GMT\n# Content-Length: 16\n# Content-Type: text/plain; charset=utf-8\n# Connection: close\n\n# application/json\n\n###\nGET http://localhost:8080/\nAccept: text/html; q=1,application/*; q=1;\n\n# HTTP/1.1 200 OK\n# Date: Sat, 03 Jul 2021 19:16:15 GMT\n# Content-Length: 9\n# Content-Type: text/plain; charset=utf-8\n# Connection: close\n\n# text/html\n\n###\nGET http://localhost:8080/\nAccept: text/*; q=1,application/*; q=0.9;\n\n# HTTP/1.1 200 OK\n# Date: Sat, 03 Jul 2021 19:16:48 GMT\n# Content-Length: 9\n# Content-Type: text/plain; charset=utf-8\n# Connection: close\n\n# text/html\n\n###\nGET http://localhost:8080/\nAccept: text/plain; q=1,application/xml; q=1;\n\n# HTTP/1.1 406 Not Acceptable\n# Date: Sat, 03 Jul 2021 19:17:28 GMT\n# Content-Length: 0\n# Connection: close\n```\n\n## Current benchmark results\n```\n$ go test -bench=.\ngoos: darwin\ngoarch: arm64\npkg: github.com/aohorodnyk/mimeheader\nBenchmarkParseAcceptHeaderLong-8                        \t  595474\t      1979 ns/op\t    1672 B/op\t      16 allocs/op\nBenchmarkParseAcceptHeaderThreeWithWights-8             \t  879034\t      1364 ns/op\t    1480 B/op\t      14 allocs/op\nBenchmarkParseAcceptHeaderOne-8                         \t 4268950\t       279.7 ns/op\t     232 B/op\t       7 allocs/op\nBenchmarkParseAcceptHeaderAndCompareLong-8              \t  295642\t      4052 ns/op\t    2344 B/op\t      34 allocs/op\nBenchmarkParseAcceptHeaderAndCompareThreeWithWights-8   \t  408138\t      2943 ns/op\t    1992 B/op\t      28 allocs/op\nBenchmarkParseAcceptHeaderAndCompareOne-8               \t 1399750\t       856.0 ns/op\t     411 B/op\t      13 allocs/op\nPASS\nok  \tgithub.com/aohorodnyk/mimeheader\t9.252s\n```\n\n## Contributing\nAll contributions have to follow the [CONTRIBUTING.md document](https://github.com/aohorodnyk/uid/blob/main/CONTRIBUTING.md)\nIf you have any questions/issues/feature requests do not hesitate to create a ticket.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faohorodnyk%2Fmimeheader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faohorodnyk%2Fmimeheader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faohorodnyk%2Fmimeheader/lists"}