test http2 in worker

This commit is contained in:
zizifn
2023-02-02 12:24:56 +08:00
committed by zizifn
parent 6032e71119
commit 4a7f65e852
3 changed files with 20 additions and 2 deletions

2
.gitignore vendored
View File

@@ -44,4 +44,4 @@ Thumbs.db
**/.env
**/.dev.vars
**/wrangler.toml
wrangler.toml

View File

@@ -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<any, any, any>) {
try {

18
functions/http2.ts Normal file
View File

@@ -0,0 +1,18 @@
interface Env {
KV: KVNamespace;
}
export const onRequest: PagesFunction<Env> = 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' },
});
};