Skip to content

Commit 78ffc73

Browse files
ci: apply automated fixes
1 parent bc22304 commit 78ffc73

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

docs/guides/best-practices.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ app.get('/api/users', async (c) => {
144144
// GOOD: Use middleware when HEAD needs different behavior
145145
app.use('/api/resource', async (c, next) => {
146146
await next()
147-
147+
148148
// Add HEAD-specific headers after the handler
149149
if (c.req.method === 'HEAD') {
150150
c.header('X-HEAD-Processed', 'true')
@@ -174,7 +174,7 @@ app.on('HEAD', '/api/users', (c) => {
174174

175175
- **Avoid expensive operations in GET handlers if you expect many HEAD requests**: Use middleware to detect HEAD and skip body generation
176176
- **Cache headers work identically**: HEAD responses respect the same caching rules as GET
177-
- **Middleware compatibility**: Most middleware works with HEAD, but body-processing middleware (like compression) automatically skips HEAD requests [2](#2-1)
177+
- **Middleware compatibility**: Most middleware works with HEAD, but body-processing middleware (like compression) automatically skips HEAD requests [2](#2-1)
178178

179179
### Testing HEAD Requests
180180

@@ -183,9 +183,11 @@ app.on('HEAD', '/api/users', (c) => {
183183
it('handles HEAD requests correctly', async () => {
184184
const getRes = await app.request('/api/users')
185185
const headRes = await app.request('/api/users', { method: 'HEAD' })
186-
186+
187187
expect(headRes.status).toBe(getRes.status)
188-
expect(headRes.headers.get('X-Total-Count')).toBe(getRes.headers.get('X-Total-Count'))
188+
expect(headRes.headers.get('X-Total-Count')).toBe(
189+
getRes.headers.get('X-Total-Count')
190+
)
189191
expect(headRes.body).toBe(null)
190192
})
191193
```
@@ -203,30 +205,36 @@ If you're upgrading from Hono v3, remove any `app.head()` routes as they're no l
203205
- If you need completely different logic for HEAD vs GET, consider using different endpoints rather than trying to override the framework's HEAD handling
204206

205207
Wiki pages you might want to explore:
208+
206209
- [Hono Application Class and HonoBase (honojs/hono)](/wiki/honojs/hono#2.1)
207210

208211
### Citations
209212

210213
**File:** src/hono-base.ts (L406-410)
214+
211215
```typescript
212-
// Handle HEAD method
213-
if (method === 'HEAD') {
214-
return (async () =>
215-
new Response(null, await this.#dispatch(request, executionCtx, env, 'GET')))()
216-
}
216+
// Handle HEAD method
217+
if (method === 'HEAD') {
218+
return (async () =>
219+
new Response(
220+
null,
221+
await this.#dispatch(request, executionCtx, env, 'GET')
222+
))()
223+
}
217224
```
218225

219226
**File:** src/middleware/compress/index.ts (L46-46)
227+
220228
```typescript
221229
ctx.req.method === 'HEAD' || // HEAD request
222230
```
223231

224232
**File:** docs/MIGRATION.md (L34-34)
233+
225234
```markdown
226235
- Hono - `app.head()` is no longer used. `app.get()` implicitly handles the HEAD method.
227236
```
228237

229-
230238
### If you want to use RPC features
231239

232240
The code above works well for normal use cases.

0 commit comments

Comments
 (0)