-
-
Notifications
You must be signed in to change notification settings - Fork 599
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
feat(context): add Context-Type types to c.header
#3255
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3255 +/- ##
==========================================
+ Coverage 96.23% 96.25% +0.01%
==========================================
Files 151 151
Lines 15197 15261 +64
Branches 2643 2668 +25
==========================================
+ Hits 14625 14689 +64
Misses 572 572 ☔ View full report in Codecov by Sentry. |
Great feature! I'll review this later. |
Hi @nakasyou I propose the following changes. diff --git a/src/context.ts b/src/context.ts
index 2a03cebb..9e1345e4 100644
--- a/src/context.ts
+++ b/src/context.ts
@@ -20,7 +20,10 @@ import type {
} from './utils/types'
import type { BaseMime } from './utils/mime'
-type HeaderRecord = Record<ResponseHeader, string | string[]> | Record<string, string | string[]>
+type HeaderRecord =
+ | Record<ResponseHeader, string | string[]>
+ | Record<'Content-Type', BaseMime>
+ | Record<string, string | string[]>
/**
* Data type can be a string, ArrayBuffer, or ReadableStream.
@@ -314,6 +317,7 @@ type ResponseHeadersInit =
| [string, string][]
| Record<string, string>
| Record<ResponseHeader, string>
+ | Record<'Content-Type', BaseMime>
| Headers
interface ResponseInit {
diff --git a/src/utils/mime.ts b/src/utils/mime.ts
index d9a54cc4..f6df4853 100644
--- a/src/utils/mime.ts
+++ b/src/utils/mime.ts
@@ -79,7 +79,6 @@ export type BaseMime =
| 'video/3gpp2'
| 'model/gltf+json'
| 'model/gltf-binary'
- | (string & {})
const baseMimes: Record<string, BaseMime> = {
aac: 'audio/aac', With this PR, it can infer other patterns, not only the |
@yusukebe OK, I changed it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Good! I'll release the new patch version that includes this feature. Thank you for your great idea! |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [hono](https://hono.dev/) ([source](https://togithub.com/honojs/hono)) | [`4.5.4` -> `4.5.5`](https://renovatebot.com/diffs/npm/hono/4.5.4/4.5.5) | [![age](https://developer.mend.io/api/mc/badges/age/npm/hono/4.5.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/hono/4.5.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/hono/4.5.4/4.5.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/hono/4.5.4/4.5.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>honojs/hono (hono)</summary> ### [`v4.5.5`](https://togithub.com/honojs/hono/releases/tag/v4.5.5) [Compare Source](https://togithub.com/honojs/hono/compare/v4.5.4...v4.5.5) #### What's Changed - fix(jsx): allow null, undefined, and boolean to be returned from function component by [@​usualoma](https://togithub.com/usualoma) in [https://github.com/honojs/hono/pull/3241](https://togithub.com/honojs/hono/pull/3241) - feat(context): Add types for `c.header` by [@​nakasyou](https://togithub.com/nakasyou) in [https://github.com/honojs/hono/pull/3221](https://togithub.com/honojs/hono/pull/3221) - fix(jsx): fix draggable type to accept boolean by [@​yasuaki640](https://togithub.com/yasuaki640) in [https://github.com/honojs/hono/pull/3253](https://togithub.com/honojs/hono/pull/3253) - feat(context): add Context-Type types to `c.header` by [@​nakasyou](https://togithub.com/nakasyou) in [https://github.com/honojs/hono/pull/3255](https://togithub.com/honojs/hono/pull/3255) - fix(serve-static): supports directory contains `.` and not end `/` by [@​yusukebe](https://togithub.com/yusukebe) in [https://github.com/honojs/hono/pull/3256](https://togithub.com/honojs/hono/pull/3256) **Full Changelog**: honojs/hono@v4.5.4...v4.5.5 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on Monday" in timezone America/Chicago, Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View the [repository job log](https://developer.mend.io/github/autoblocksai/cli). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4yMC4xIiwidXBkYXRlZEluVmVyIjoiMzguMjAuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
I added a Content-Type type helper to
c.header
.I'm sure you can type mime-types easily than before.
The author should do the following, if applicable
bun run format:fix && bun run lint:fix
to format the code