Code Monkey home page Code Monkey logo

Comments (8)

ronag avatar ronag commented on July 20, 2024 1

It doesn't work unless you add .end() to http2.request(...). Is this on purpose?

No. end() is called inside onProxyConnect. It might be that http2.request doesn't implement the flow:

req.'socket' => socket.'connect' => onProxyConnect.

from node-http2-proxy.

ronag avatar ronag commented on July 20, 2024 1

Oh, it doesn't emit the socket event because it waits for the first write / end.

The whole purpose here is that we don't read/write until we know we have successfully connected, so that we can safely retry requests that contain a stream body.

from node-http2-proxy.

ronag avatar ronag commented on July 20, 2024

fixed in e0b9324

from node-http2-proxy.

szmarczak avatar szmarczak commented on July 20, 2024
const http = require('http');
const proxy = require('http2-proxy');
const http2 = require('http2-wrapper');

const server = http.createServer();

const defaultWebHandler = (error, request, response) => {
	if (error) {
		console.error(error);

		response.statusCode = 500;
		response.end(error.stack);
	}
};

server.listen(8000, error => {
	if (error) {
		throw error;
	}

	server.on('request', (req, res) => {
		proxy.web(req, res, {
			hostname: 'example.com',
			port: 443,
			onReq: (request, options) => {
				return http2.request(options, response => {
					const {headers} = response;

					// `http2-proxy` doesn't automatically remove pseudo-headers
					for (const name in headers) {
						if (name.startsWith(':')) {
							delete headers[name];
						}
					}
				});
			}
		}, defaultWebHandler);
	});

	console.log(`Listening on port ${server.address().port}`);
});

It doesn't work unless you add .end() to http2.request(...). Is this on purpose?

from node-http2-proxy.

szmarczak avatar szmarczak commented on July 20, 2024

You're right. There's no connect event on the socket. I think I know how to fix this. Thanks for pointing out :)

from node-http2-proxy.

szmarczak avatar szmarczak commented on July 20, 2024

There's no connect event because it's already connected. I think that http2-proxy doesn't cover this edge-case. Hmm, it does.

from node-http2-proxy.

szmarczak avatar szmarczak commented on July 20, 2024

Wait... For some reason it doesn't emit the socket event at all. Welp.

from node-http2-proxy.

szmarczak avatar szmarczak commented on July 20, 2024

Oh, it doesn't emit the socket event because the wrapper waits for the first write / end.

from node-http2-proxy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.