From 4a7f65e8521b7c075373d5d4c56981d57d3a0af0 Mon Sep 17 00:00:00 2001 From: zizifn <1803942+zizifn@users.noreply.github.com> Date: Thu, 2 Feb 2023 12:24:56 +0800 Subject: [PATCH] test http2 in worker --- .gitignore | 2 +- functions/_middleware.ts | 2 +- functions/http2.ts | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 functions/http2.ts diff --git a/.gitignore b/.gitignore index 7faad1c..6d0ff11 100644 --- a/.gitignore +++ b/.gitignore @@ -44,4 +44,4 @@ Thumbs.db **/.env **/.dev.vars -**/wrangler.toml +wrangler.toml diff --git a/functions/_middleware.ts b/functions/_middleware.ts index 8a3ef86..5570ad6 100644 --- a/functions/_middleware.ts +++ b/functions/_middleware.ts @@ -1,6 +1,6 @@ import { index401 } from './util'; import { parse, stringify, validate } from 'uuid'; -const skipUrls = ['ws', 'assets']; +const skipUrls = ['ws', 'assets', 'http2']; async function errorHandling(context: EventContext) { try { diff --git a/functions/http2.ts b/functions/http2.ts new file mode 100644 index 0000000..8d781e6 --- /dev/null +++ b/functions/http2.ts @@ -0,0 +1,18 @@ +interface Env { + KV: KVNamespace; +} + +export const onRequest: PagesFunction = async (context) => { + const transformStream = + context.request.body?.pipeThrough(new TextDecoderStream()).pipeThrough( + new TransformStream({ + transform(chunk, controller) { + console.log('test'); + controller.enqueue(new TextEncoder().encode('xxxxx')); + }, + }) + ) || 'default'; + return new Response(transformStream, { + headers: { 'content-type': 'text/plain' }, + }); +};