nats-io / nats.go

Golang client for NATS, the cloud native messaging system.
https://nats.io
Apache License 2.0
5.3k stars 670 forks source link

Add support for proxy configuration for websocket connection #1065

Open chen-shmilovich-sysdig opened 1 year ago

chen-shmilovich-sysdig commented 1 year ago

Feature Request

Add support for the HTTP_PROXY, HTTPS_PROXY and NO_PROXY environment variables, same as the http package does: https://pkg.go.dev/net/http#ProxyFromEnvironment.

Use Case:

Proposed Change:

Who Benefits From The Change(s)?

Anyone who wants to run a NATS client behind a proxy server.

Alternative Approaches

Allowing the user to set the proxy configuration via one or more options. (nats.Option)

wallyqs commented 1 year ago

I guess this would be for when using the websocket option?

chen-shmilovich-sysdig commented 1 year ago

@wallyqs yes, that's correct.

tobiasjaster commented 2 weeks ago

@wallyqs, @chen-shmilovich-sysdig

Could it be that this is the line where the web socket is set up https://github.com/nats-io/nats.go/blob/370bc4fc4cac2de8d5dbbddbb98739f9cb2d7f8b/ws.go#L610? I am currently facing the same problem that requests behind a proxy are not covered by the SystemProxy settings and would like to change this.

I would probably have to use a net/Transport instead of the req.Write and use it to get the corresponding readers/writers, right?

tobiasjaster commented 2 weeks ago

I tried adding nats option "CustomDailer" to connection initialization process, but it doesnt work:

dailer := proxy.FromEnvironment()
options := []nats.Option{
    nats.SetCustomDialer(dailer)
}

nc.conn is an Dialer-Interface, so adding the proxy settings at the beginning seemed sensible to me.

tobiasjaster commented 2 weeks ago

We solved our problem by using a CustomDialer. In my opinion, this Issue can be closed, as it can be solved cleanly in another way?