-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ignore response if already sent by raw level outgoing API. (#153)
- Loading branch information
Showing
6 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { X_ALREADY_SENT } from './response/constants' | ||
export const RESPONSE_ALREADY_SENT = new Response(null, { | ||
headers: { [X_ALREADY_SENT]: 'true' }, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const X_ALREADY_SENT = 'x-hono-already-sent' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Hono } from 'hono' | ||
import request from 'supertest' | ||
import type { HttpBindings } from '../../src/' | ||
import { createAdaptorServer } from '../../src/server' | ||
import { RESPONSE_ALREADY_SENT } from '../../src/utils/response' | ||
|
||
describe('RESPONSE_ALREADY_SENT', () => { | ||
const app = new Hono<{ Bindings: HttpBindings }>() | ||
app.get('/', (c) => { | ||
const { outgoing } = c.env | ||
outgoing.writeHead(200, { 'Content-Type': 'text/plain' }) | ||
outgoing.end('Hono!') | ||
return RESPONSE_ALREADY_SENT | ||
}) | ||
const server = createAdaptorServer(app) | ||
|
||
it('Should return 200 response - GET /', async () => { | ||
const res = await request(server).get('/') | ||
expect(res.status).toBe(200) | ||
expect(res.headers['content-type']).toMatch('text/plain') | ||
expect(res.text).toBe('Hono!') | ||
}) | ||
}) |