Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP/2 on HTTP/1.1 Tunnel #23

Open
frank-trampe opened this issue Oct 9, 2019 · 4 comments
Open

HTTP/2 on HTTP/1.1 Tunnel #23

frank-trampe opened this issue Oct 9, 2019 · 4 comments
Assignees
Labels
question Further information is requested

Comments

@frank-trampe
Copy link

I apologize for making an issue if this turns out to be more of a question.

I'm trying to tunnel HTTP/2 over HTTP/1.1, but feeding an agent from the tunnel library to http2Client.request does not seem to do anything, and it seems that the agent gets ignored/discarded in HttpRequestManager.makeRequest. As an easy test, you can pass in a bad agent, and an HTTP/2 request still succeeds.

Is there some way presently to do that (HTTP/2 over HTTP/1.1)?

I am running version 1.3.3, by the way.

@hisco
Copy link
Owner

hisco commented Oct 17, 2019

Hey,

More information is required:

  • Which tunnel lib?
  • The server is using which protocol?
  • The agent you are using.. is it http1 / http2 agent?

Any other information can help to understand your issue, like code example.

@frank-trampe
Copy link
Author

I was using the "tunnel" tunnel library, which supports only HTTP/1.1. The end server uses HTTP/2. The proxies support only HTTP/1.1.

@hisco
Copy link
Owner

hisco commented Oct 30, 2019

Hey,

Please provide an example of your usage.

Thanks.

@hisco hisco self-assigned this Oct 30, 2019
@hisco hisco added the question Further information is requested label Oct 30, 2019
@frank-trampe
Copy link
Author

Here is some abbreviated code to give an idea. If it is not enough, I can put together a test environment.

const tunnel = require("tunnel");
const http2Client = require("http2-client");

function uri_split(uri) {
	var pieces = uri.match(/^([A-Za-z0-9]+):\/\/([A-Za-z0-9.-]+)(:([0-9]+))?(\/([A-Za-z0-9_+%&$=/.-]*)(\?([A-Za-z0-9_+%&$=/.-]*))?)?/);
	if (pieces)
		return {protocol: pieces[1], host: pieces[2], port: pieces[4],
				fullHost: pieces[2] + (pieces[3] || ""), path: pieces[6],
				query: pieces[8]};
	return null;
}

function agent_from_proxy(proxy, target) {
	var agent_options = {};
	if (typeof(proxy.host) == "string")
		agent_options.host = proxy.host;
	if (frankenlib.type_number_or_string_not_blank(proxy.port) && !isNaN(proxy.port))
		agent_options.port = proxy.port;
	if (typeof(proxy.user_name) == "string" && typeof(proxy.password) == "string")
		agent_options.proxyAuth = encodeURIComponent(proxy.user_name) +
			":" + encodeURIComponent(proxy.password);
	const uriPieces = frankenlib.uri_split(target);
	if (!uriPieces)
		return null;
	if (uriPieces.protocol.toLowerCase() == "https") {
		if (proxy.https_support)
			return tunnel.httpsOverHttps(agent_options);
		else
			return tunnel.httpsOverHttp(agent_options);
	} else {
		if (proxy.https_support)
			return tunnel.httpOverHttps(agent_options);
		else
			return tunnel.httpOverHttp(agent_options);
	}
	return null;
}

var request_options = {uri: "https://google.com"};
request_options.agent =
		agent_from_proxy({host: "arbitrary.proxy.com", request_options.uri);
http2Client.request(request_options, function (res) { ... });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants