hisco / http2-client

Transparently make http request to both http1 / http2 server.
https://www.npmjs.com/package/http2-client
MIT License
33 stars 14 forks source link

HTTP/2 on HTTP/1.1 Tunnel #23

Open frank-trampe opened 4 years ago

frank-trampe commented 4 years ago

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 commented 4 years ago

Hey,

More information is required:

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

frank-trampe commented 4 years ago

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 commented 4 years ago

Hey,

Please provide an example of your usage.

Thanks.

frank-trampe commented 4 years ago

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) { ... });