Support CONNECT method
What is the feature you are proposing?
I'm trying to build an MITM proxy using Hono, but Hono misses the CONNECT method, which the MITM proxy requires.
You can use app.on
You can use
app.on
It doesn't work. Considering code
import { Hono } from 'hono';
const app = new Hono();
app.on('CONNECT', '*', async (c) => {
console.log('HTTP CONNECT:', c.req.method, c.req.url);
});
export default {
port: 8080,
fetch: app.fetch,
};
Set export http_proxy=http://127.0.0.1:8080
Then try curl -v https://github.com, you will get 400 bad request, and the console doesn't log.
Sorry, please try to rewrite to lower case
Sorry, please try to rewrite to lower case
same result
Hmm
Can you intercept request? (Use app.all)
Can you intercept request? (Use app.all)
That's my first attempt.
If so, I don't think it is possible to do that with Hono. This is true for other libraries as well.
That's why it's a feature request.
Hi @ianzone
I'm not so familiar with MITM proxy, but supporting the CONNECT method is out of Hono's score. Hono is built with just Web Standard API, but it does not support the CONNECT method. This is the reason.
Hey there! 👋 I ran into a similar issue and I found a workaround.
So like others have mentioned in the thread, it makes sense that Hono doesn't support CONNECT because this method is not supported by Request and fetch. It is also unavailable in cloudflare. Meaning it would deviate a lot from how other HTTP methods are handled in Hono.
Ok so now, if you are running hono with Node, here's how you can add support for CONNECT:
import type { Server } from 'node:http';
import { createAdaptorServer } from '@hono/node-server';
import { Hono } from 'hono';
const app = new Hono();
const server = createAdaptorServer(app) as Server;
server.on('connect', (req, clientSocket, head) => {
// extract host and port from `req.url`
});
(For more info see https://nodejs.org/api/http.html#event-connect_1)