Skip to content

Conversation

aaronmaturen
Copy link
Contributor

Hey Friends,

I think I've got HTTP2 support for the three use cases working correctly:

HTTP -> HTTP2
HTTP2 -> HTTP
HTTP2 -> HTTP2

Any feedback would be appreciated.

Thanks for everyone's hard work on this great project!

@aaronmaturen
Copy link
Contributor Author

I realized that I forgot the example and tests that I had working locally. Unfortunately the HTTP2 module requires >= 0.12.0 which might be a requirement that isn't aligned with this project, but it is causing the 0.10.2 test to fail in travis-ci here.

@aaronmaturen aaronmaturen mentioned this pull request Dec 7, 2015
@indexzero
Copy link
Member

This actually looks pretty interesting. @dmai or @jcrugzz: comments?

@jcrugzz
Copy link
Contributor

jcrugzz commented Dec 8, 2015

@indexzero @aaronmaturen the reason I'm hesitant on this is due to the conversation I had with @indutny where http2 based on his implementation in node-spdy only requires the proper agent to be passed in to enable proxying via http2. So this really has to do with what we want to support.

Personally, I'm not a fan of of actually spinning up a server as part of http-proxy since that makes us biased on implementation in this case. But in terms of the actual bit that is proxying, I like @indutny's approach because it leverages the agent rather than requiring a separate http like library in order to make the request.

@donasaur
Copy link
Contributor

donasaur commented Dec 9, 2015

@indexzero ah, calling @dmai doesn't work on public git

Hm, I don't think it would be that bad if we supported the http2 library since the docs for that library saids that http2 has an api very similar to that of https and we support passing in options to https

I can see @jcrugzz 's point about not using a particular userland http2 module though, and those who have read up on HTTP2 already would most likely know how to use our provided interface to spin up a http2 web server w/o createProxyServer().listen() using the mentioned userland library or spdy

@muzuiget
Copy link

Any progressing? I get a problem using with http2 library molnarg/node-http2#158 (comment) And this PR fix the problem.

@aaronmaturen
Copy link
Contributor Author

Hi Friends,

@jcrugzz suggested that the node-spdy module by @indutny is a better way to spin up a new HTTP2 server. It made sense to me at the time, and it's fairly easy to get setup if you actually have an SSL cert to get past the browser security...

Here is a small example for HTTP2 -> HTTP proxying without any changes to http-proxy.

var spdy = require('spdy');
var httpProxy = require('http-proxy');
var fs = require('fs');
var http = require('http');

var options = {
  key: fs.readFileSync(__dirname + '/keys/privkey.pem'),
  cert: fs.readFileSync(__dirname + '/keys/cert.pem'),
  ca: fs.readFileSync(__dirname + '/keys/fullchain.pem'),

  spdy: {
    protocols: [ 'h2' ],
    plain: false,
    //'x-forwarded-for': true,
  }
};

var proxy = httpProxy.createProxyServer({});

proxy.on('proxyReq', function(proxyReq, req, res, options) {
  delete req.headers['transfer-encoding'];
});

var server = spdy.createServer(options, function(req, res) {
  console.log(req.url);
  proxy.web(req, res, {
    target: 'http://localhost:9002',
  });
});

server.listen(9000);

http.createServer(function (req, res) {
  res.writeHead(200, { 'Content-Type': 'application/json' });
  res.write(JSON.stringify(req.headers, true, 2));
  res.end();
}).listen(9002);

screenshot 2016-03-25 18 23 24

@tomByrer
Copy link

I hope this gets merged soon, or atleast added to an new branch.
BTW, IIRC Node v0.10 support will end in 2016-08, So Travis' error can be ignored.

@jcrugzz
Copy link
Contributor

jcrugzz commented Apr 21, 2016

@tomByrer please see the last response, there is nothing preventing you from using http2 using the node-spdy module which is a better way to do this.

@manast
Copy link

manast commented Sep 18, 2016

@aaronmaturen I am new to http2 so please indulge me. How would your example code work if the target server is also HTTP2, and what about things like push streams, would they also work? In other words, would be able to get all of the http2 features without loosing any?

@williamyorkl
Copy link

Hi Friends,

@jcrugzz suggested that the node-spdy module by @indutny is a better way to spin up a new HTTP2 server. It made sense to me at the time, and it's fairly easy to get setup if you actually have an SSL cert to get past the browser security...

Here is a small example for HTTP2 -> HTTP proxying without any changes to http-proxy.

var spdy = require('spdy');
var httpProxy = require('http-proxy');
var fs = require('fs');
var http = require('http');

var options = {
  key: fs.readFileSync(__dirname + '/keys/privkey.pem'),
  cert: fs.readFileSync(__dirname + '/keys/cert.pem'),
  ca: fs.readFileSync(__dirname + '/keys/fullchain.pem'),

  spdy: {
    protocols: [ 'h2' ],
    plain: false,
    //'x-forwarded-for': true,
  }
};

var proxy = httpProxy.createProxyServer({});

proxy.on('proxyReq', function(proxyReq, req, res, options) {
  delete req.headers['transfer-encoding'];
});

var server = spdy.createServer(options, function(req, res) {
  console.log(req.url);
  proxy.web(req, res, {
    target: 'http://localhost:9002',
  });
});

server.listen(9000);

http.createServer(function (req, res) {
  res.writeHead(200, { 'Content-Type': 'application/json' });
  res.write(JSON.stringify(req.headers, true, 2));
  res.end();
}).listen(9002);

screenshot 2016-03-25 18 23 24

hey bro, it seems that it doesn't work any more.... are there any solution so far in 2021?

1 similar comment
@williamyorkl
Copy link

Hi Friends,

@jcrugzz suggested that the node-spdy module by @indutny is a better way to spin up a new HTTP2 server. It made sense to me at the time, and it's fairly easy to get setup if you actually have an SSL cert to get past the browser security...

Here is a small example for HTTP2 -> HTTP proxying without any changes to http-proxy.

var spdy = require('spdy');
var httpProxy = require('http-proxy');
var fs = require('fs');
var http = require('http');

var options = {
  key: fs.readFileSync(__dirname + '/keys/privkey.pem'),
  cert: fs.readFileSync(__dirname + '/keys/cert.pem'),
  ca: fs.readFileSync(__dirname + '/keys/fullchain.pem'),

  spdy: {
    protocols: [ 'h2' ],
    plain: false,
    //'x-forwarded-for': true,
  }
};

var proxy = httpProxy.createProxyServer({});

proxy.on('proxyReq', function(proxyReq, req, res, options) {
  delete req.headers['transfer-encoding'];
});

var server = spdy.createServer(options, function(req, res) {
  console.log(req.url);
  proxy.web(req, res, {
    target: 'http://localhost:9002',
  });
});

server.listen(9000);

http.createServer(function (req, res) {
  res.writeHead(200, { 'Content-Type': 'application/json' });
  res.write(JSON.stringify(req.headers, true, 2));
  res.end();
}).listen(9002);

screenshot 2016-03-25 18 23 24

hey bro, it seems that it doesn't work any more.... are there any solution so far in 2021?

dav1d8 added a commit to dav1d8/node-http-proxy that referenced this pull request Mar 1, 2023
dav1d8 added a commit to dav1d8/node-http-proxy that referenced this pull request Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants