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

Fix a websocket connection issue when running in the proxy mode #2089

Open
wants to merge 1 commit into
base: py3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/Ui/UiRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ def route(self, path):
if config.ui_restrict and self.env['REMOTE_ADDR'] not in config.ui_restrict:
return self.error403(details=False)

if self.env['REQUEST_METHOD'] == "CONNECT":
self.start_response("200 OK", [])
return ""

# Check if host allowed to do request
if not self.isHostAllowed(self.env.get("HTTP_HOST")):
return self.error403("Invalid host: %s" % self.env.get("HTTP_HOST"), details=False)
Expand Down Expand Up @@ -430,13 +434,8 @@ def renderWrapper(self, site, path, inner_path, title, extra_headers, show_loadi
inner_query_string = "?wrapper_nonce=%s" % wrapper_nonce

if self.isProxyRequest(): # Its a remote proxy request
if self.env["REMOTE_ADDR"] == "127.0.0.1": # Local client, the server address also should be 127.0.0.1
server_url = "http://127.0.0.1:%s" % self.env["SERVER_PORT"]
else: # Remote client, use SERVER_NAME as server's real address
server_url = "http://%s:%s" % (self.env["SERVER_NAME"], self.env["SERVER_PORT"])
homepage = "http://zero/" + config.homepage
else: # Use relative path
server_url = ""
homepage = "/" + config.homepage

user = self.getCurrentUser()
Expand Down Expand Up @@ -469,7 +468,6 @@ def renderWrapper(self, site, path, inner_path, title, extra_headers, show_loadi

return self.render(
"src/Ui/template/wrapper.html",
server_url=server_url,
inner_path=inner_path,
file_url=re.escape(file_url),
file_inner_path=re.escape(file_inner_path),
Expand Down
7 changes: 6 additions & 1 deletion src/Ui/UiServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ def __init__(self, *args, **kwargs):
self.args = args
self.kwargs = kwargs

def finalize_headers(self):
# Send no additional headers in response to the CONNECT method
if self.environ['REQUEST_METHOD'] == "CONNECT":
return
super(UiWSGIHandler, self).finalize_headers()

def run_application(self):
if "HTTP_UPGRADE" in self.environ: # Websocket request
try:
Expand All @@ -51,7 +57,6 @@ def handle(self):
super(UiWSGIHandler, self).handle()
del self.server.sockets[self.client_address]


class UiServer:

def __init__(self):
Expand Down
2 changes: 1 addition & 1 deletion src/Ui/media/Wrapper.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ class Wrapper
log: (args...) ->
console.log "[Wrapper]", args...

origin = window.server_url or window.location.href.replace(/(\:\/\/.*?)\/.*/, "$1")
origin = window.location.href.replace(/(\:\/\/.*?)\/.*/, "$1")

if origin.indexOf("https:") == 0
proto = { ws: 'wss', http: 'https' }
Expand Down
2 changes: 1 addition & 1 deletion src/Ui/media/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -1961,7 +1961,7 @@ $.extend( $.easing,

})();

origin = window.server_url || window.location.href.replace(/(\:\/\/.*?)\/.*/, "$1");
origin = window.location.href.replace(/(\:\/\/.*?)\/.*/, "$1");

if (origin.indexOf("https:") === 0) {
proto = {
Expand Down
1 change: 0 additions & 1 deletion src/Ui/template/wrapper.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ <h3>ZeroNet requires JavaScript support.</h3>If you use NoScript/Tor browser: Cl
file_inner_path = "{file_inner_path}"
permissions = {permissions}
show_loadingscreen = {show_loadingscreen}
server_url = '{server_url}'
script_nonce = '{script_nonce}'

if (typeof WebSocket === "undefined") {
Expand Down