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

HACK: add support for using a proxy for wss connections #74

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

catern
Copy link

@catern catern commented Sep 1, 2020

For me this "solves" #73 but it's very hacky...

(let ((url-http-after-change-function)
(url-current-object url-as-http))
(url-https-proxy-connect plain-conn))
(sleep-for 0.5)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the sleep needed? Can we instead check plain-conn?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to wait until we get a response to the CONNECT issued by url-https-proxy-connect. The proper (and only) way to do this is with a process-filter. I was just too lazy to hook up that additional possible state into the websocket.el process filter...

(url-as-http (let ((url-as-http (copy-sequence url-struct)))
(setf (url-type url-as-http) (if (eq type 'plain) "http" "https"))
url-as-http))
(proxy (url-generic-parse-url (url-find-proxy-for-url url-as-http (url-host url-as-http)))))
(if (eq type 'plain)
(make-network-process :name name :buffer nil :host host
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work with http proxies? I'd guess you would need to make the host different if it is a proxy?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean by "http proxies" - the code I have here only works with proxies that talk plain HTTP without encryption. (The gnutls-negotiate later on is for TLS with the websocket server)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I wrote something that didn't make sense.

The way I read this, it doesn't look like it would go through a proxy for unencrypted websockets. The logic testing for proxies is only execute if type is not 'plain.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, this only works for wss:// at the moment. I didn't have a need for ws:// and didn't set up a testing environment for it. In theory it could be as simple as not doing the gnutls-negotiate.

(url-current-object url-as-http))
(url-https-proxy-connect plain-conn))
(sleep-for 0.5)
(gnutls-negotiate :process plain-conn :hostname host))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this all a standard sequence of actions for https proxy connections? How would we be sure this is correct?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know it's pretty standard - I figured this out mostly by reading url.el.

We certainly could add a test for this. I looked briefly at https://tinyproxy.github.io/ and it looks like it should support proxying websocket connections. I just didn't get around to it because I wanted to figure out quickly if I could get this working against the internal corporate proxy that I wanted to access.

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.

2 participants