lit icon indicating copy to clipboard operation
lit copied to clipboard

Is there any option for HTTPS proxy?

Open 9chu opened this issue 9 years ago • 10 comments

It's hard for my network to access to "github-cloud.s3.amazonaws.com", which causes the command "lit make lit://luvit/luvit" fail. And it seems that the environment variable "HTTPS_PROXY" doesn't work for lit. So, is there any solution to make lit using HTTPS proxy? thanks.

9chu avatar Feb 03 '16 10:02 9chu

This feature can be added, what kind of proxy is it?

creationix avatar Feb 03 '16 15:02 creationix

Just an HTTP/HTTPS proxy. I am now using proxychains to solve this problem under ubuntu. It's better if lit could pull from a Git repository through an HTTP proxy directly :)

9chu avatar Feb 03 '16 15:02 9chu

ok, I'll see about adding support for HTTPS_PROXY, if you have links for the protocol that would help (or at least an example of what the value contains with your auth details scrubbed out)

creationix avatar Feb 03 '16 20:02 creationix

like @9chu , would be great to make lit work behind a corporate proxy ;-)

lduboeuf avatar Nov 28 '16 10:11 lduboeuf

That's great! Thanks a lot.

9chu avatar Nov 28 '16 13:11 9chu

So is this a proxy using CONNECT in http and the the proxy doing plain TCP proxy? https://en.wikipedia.org/wiki/HTTP_tunnel#HTTP_CONNECT_tunneling

What does the value of the HTTPS_PROXY environment variable look like? I assume it's a local url of some sort (or at least host and optional port)

creationix avatar Nov 28 '16 17:11 creationix

https_proxy and http_proxy are set to http://proxyurl:8080 scheme but are not used by lit i guess when doing lit install works fine if use proxychain

lduboeuf avatar Nov 29 '16 12:11 lduboeuf

thanks, I'll see what it takes to implement this. It shouldn't be too hard.

creationix avatar Nov 30 '16 16:11 creationix

I attempted a proxy implementation a while back over the top of coro-http. It might not be the best way to do it, but I figure it might be of some potential use as a reference.

For some reason it's getting a 400 response when trying to connect to https://luvit.io through a proxy now (it used to work), but it still works for other sites (e.g. https://www.google.com)

--[[lit-meta
  name = "squeek502/coro-http-proxy"
  version = "1.0.0"
  dependencies = {
    "creationix/[email protected]",
    "luvit/[email protected]",
  }
]]

local http = require('coro-http')

local function request(method, url, headers, body, proxy)
  local requestURI = http.parseUrl(url)

  if proxy then
    local proxyURI = http.parseUrl(proxy)
    proxyURI.host = proxyURI.host:match("^[^:]+")
    local connection = http.getConnection(proxyURI.host, proxyURI.port, proxyURI.tls)
    local read, write = connection.read, connection.write

    local authorityForm = requestURI.host .. ':' .. requestURI.port
    local req = {
      method = 'CONNECT',
      path = authorityForm,
      {"Host", authorityForm}
    }

    write(req)

    local res = read()
    if not res then
      if not connection.socket:is_closing() then
        connection.socket:close()
      end
      -- If we get an immediate close on a reused socket, try again with a new socket.
      -- TODO: think about if this could resend requests with side effects and cause
      -- them to double execute in the remote server.
      if connection.reused then
        return request(method, url, headers, body, proxy)
      end
      error("Connection closed")
    end

    if res.code == 200 then
      connection.host = requestURI.host
      connection.port = requestURI.port
      connection.tls = requestURI.tls
      connection.reset()
      http.saveConnection(connection)
    else
      error("Tunnel socket recieved unexpected response code: " .. res.code)
    end
  end

  return http.request(method, url, headers, body)
end

return {
  request = request,
}

The test (the proxy is just some random one from a public proxy list):

local httpProxy = require('coro-http-proxy')
local http = require('coro-http')

require('tap')(function(test)

  test("proxy request", function()
    coroutine.wrap(function()
      local res, body = httpProxy.request("GET", "https://www.google.com", nil, nil, "http://97.77.104.22:3128")
      assert(res.code == 200, res.code)
      assert(body ~= nil)

      if res.keepAlive then
        local connection = http.getConnection("www.google.com", 443, true)
        assert(connection.reused)
        connection.socket:close()
      end
    end)()
  end)

end)

squeek502 avatar Nov 30 '16 22:11 squeek502

Hi all, Are there any news regarding the issue of using lit behind a http proxy ?

tbmale avatar Feb 20 '18 14:02 tbmale