Skip to content
Myr

feat: etag middleware (#119)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Yusuke Wada · committed by GitHub · parent bea8aef · Browse files · 6 files+166 added−17 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+166 added−17 removed

  • tests:+107 added−0 removed
  • other:+59 added−17 removed

6 files+166 added−17 removed

modified:examples/basic/index.js+4 added
modified:src/middleware/body-parse/body-parse.ts+2 added-17 removed
added:src/middleware/etag/etag.test.ts+60 added
added:src/middleware/etag/etag.ts+33 added
added:src/utils/body.test.ts+47 added
1import { parseBody } from './body'23describe('Parse Body Middleware', () => {4 it('should parse JSON', async () => {5 const payload = { message: 'hello hono' }6 const req = new Request('http://localhost/json', {7 method: 'POST',8 body: JSON.stringify(payload),9 headers: new Headers({ 'Content-Type': 'application/json' }),10 })11 expect(await parseBody(req)).toEqual(payload)12 })1314 it('should parse Text', async () => {15 const payload = 'hello'16 const req = new Request('http://localhost/text', {17 method: 'POST',18 body: 'hello',19 headers: new Headers({ 'Content-Type': 'application/text' }),20 })21 expect(await parseBody(req)).toEqual(payload)22 })2324 it('should parse Form', async () => {25 const formData = new URLSearchParams()26 formData.append('message', 'hello')27 const req = new Request('https://localhost/form', {28 method: 'POST',29 body: formData,30 headers: {31 'Content-Type': 'application/x-www-form-urlencoded',32 },33 })34 expect(await parseBody(req)).toEqual({ message: 'hello' })35 })3637 it('should parse Reponse body ', async () => {38 const payload = 'hello'39 const res = new Response(payload, {40 headers: {41 'Content-Type': 'text/plain',42 },43 })44 console.log(res.headers.get('Content-Type'))45 expect(await parseBody(res)).toEqual(payload)46 })47})
added:src/utils/body.ts+20 added