mirror of
https://github.com/lush2020/edgetunnel.git
synced 2026-03-23 16:38:34 +08:00
add support for http
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { serve } from 'https://deno.land/std@0.167.0/http/server.ts';
|
||||
|
||||
const userID = Deno.env.get('UUID');
|
||||
|
||||
const handler = async (request: Request): Promise<Response> => {
|
||||
@@ -35,47 +34,9 @@ ${userID ? 'has UUID env' : 'no UUID env'}
|
||||
hostname: serverAddress,
|
||||
});
|
||||
|
||||
// connection.write(
|
||||
// new TextEncoder().encode('GET http://www.baidu.com/ HTTP/1.1\r\n')
|
||||
// );
|
||||
// connection.write(new TextEncoder().encode('Host: www.baidu.com\r\n\r\n'));
|
||||
// connection.close();
|
||||
|
||||
// GET / HTTP/1.1
|
||||
// Host: www.baidu.com
|
||||
// User-Agent: curl/7.83.1
|
||||
// Accept: */*
|
||||
// const body2 = new ReadableStream({
|
||||
// start(controller) {
|
||||
// controller.enqueue(new TextEncoder().encode('GET / HTTP/1.1\r\n'));
|
||||
// controller.enqueue(new TextEncoder().encode('Host: www.baidu.com\r\n'));
|
||||
// controller.enqueue(
|
||||
// new TextEncoder().encode('User-Agent: curl/7.83.1\r\n')
|
||||
// );
|
||||
// controller.enqueue(new TextEncoder().encode('Accept: */*\r\n\r\n'));
|
||||
// // controller.close();
|
||||
// },
|
||||
// cancel() {},
|
||||
// });
|
||||
|
||||
// for await (const chunk of body2) {
|
||||
// connection.write(chunk);
|
||||
// }
|
||||
// request.body readablestream end casue socket to be end, this will casue socket send FIN package early
|
||||
// and casue deno can't get TCP pcakge.
|
||||
const proxyResp = request.body?.pipeThrough(connection);
|
||||
// const proxyResp = request.body
|
||||
// ?.pipeThrough(
|
||||
// new TransformStream({
|
||||
// async transform(chunk, controller) {
|
||||
// console.log('transform');
|
||||
// controller.enqueue(chunk);
|
||||
// },
|
||||
// async flush(controller) {
|
||||
// console.log('flush');
|
||||
// return new Promise((res) => setTimeout(res, 1000));
|
||||
// },
|
||||
// })
|
||||
// )
|
||||
// .pipeThrough(connection);
|
||||
return new Response(proxyResp, {
|
||||
status: 200,
|
||||
headers: {},
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import { serve } from 'https://deno.land/std@0.167.0/http/server.ts';
|
||||
|
||||
console.log('Current Deno version', Deno.version.deno);
|
||||
|
||||
const handler = async (request: Request): Promise<Response> => {
|
||||
const connection = await Deno.connect({
|
||||
port: 80,
|
||||
hostname: 'www.baidcu.com',
|
||||
hostname: 'www.baidu.com',
|
||||
});
|
||||
|
||||
// GET / HTTP/1.1
|
||||
// Host: www.baidu.com
|
||||
// User-Agent: curl/7.83.1
|
||||
// Accept: */*
|
||||
const body2 = new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue(new TextEncoder().encode('GET / HTTP/1.1\r\n'));
|
||||
@@ -18,23 +15,24 @@ const handler = async (request: Request): Promise<Response> => {
|
||||
new TextEncoder().encode('User-Agent: curl/7.83.1\r\n')
|
||||
);
|
||||
controller.enqueue(new TextEncoder().encode('Accept: */*\r\n\r\n'));
|
||||
controller.close(); // 注释这个就好用
|
||||
controller.close();
|
||||
},
|
||||
cancel() {},
|
||||
});
|
||||
|
||||
// 或者不用 pipeThrough, 直接write
|
||||
// for await (const chunk of body2) {
|
||||
// connection.write(chunk);
|
||||
// console.log('11');
|
||||
// }
|
||||
// const proxyResp = connection.readable;
|
||||
|
||||
// -----------
|
||||
const proxyResp = body2?.pipeThrough(connection);
|
||||
|
||||
return new Response(proxyResp, {
|
||||
for await (const chunk of proxyResp) {
|
||||
console.log('11');
|
||||
}
|
||||
return new Response('111', {
|
||||
status: 200,
|
||||
headers: {},
|
||||
headers: {
|
||||
'x-ray': 'xxxx',
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user