Skip to content

Commit

Permalink
[websocketproxy] Set 'C' locale early during startup. In this way we
Browse files Browse the repository at this point in the history
don't rely on user locale and don't need to distribute zillion locales
when building a frozen distribution.
  • Loading branch information
Giuseppe Corbelli committed Mar 6, 2019
1 parent c136ea2 commit cc56f7b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions websockify/websocketproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'''

import signal, socket, optparse, time, os, sys, subprocess, logging, errno, ssl
import locale
try:
from socketserver import ForkingMixIn
except ImportError:
Expand Down Expand Up @@ -46,15 +47,15 @@ class ProxyRequestHandler(websockifyserver.WebSockifyRequestHandler):
< - Client send
<. - Client send partial
"""

def send_auth_error(self, ex):
self.send_response(ex.code, ex.msg)
self.send_header('Content-Type', 'text/html')
for name, val in ex.headers.items():
self.send_header(name, val)

self.end_headers()

def validate_connection(self):
if not self.server.token_plugin:
return
Expand Down Expand Up @@ -83,7 +84,7 @@ def auth_connection(self):
except (TypeError, AttributeError, KeyError):
# not a SSL connection or client presented no certificate with valid data
pass

try:
self.server.auth_plugin.authenticate(
headers=self.headers, target_host=self.server.target_host,
Expand Down Expand Up @@ -433,7 +434,7 @@ def select_ssl_version(version):
# It so happens that version names sorted lexicographically form a list
# from the least to the most secure
keys = list(SSL_OPTIONS.keys())
keys.sort()
keys.sort()
fallback = keys[-1]
logger = logging.getLogger(WebSocketProxy.log_prefix)
logger.warn("TLS version %s unsupported. Falling back to %s",
Expand All @@ -442,6 +443,9 @@ def select_ssl_version(version):
return SSL_OPTIONS[fallback]

def websockify_init():
# Get an unified locale so that we can avoid shipping tons of locales
# if we build a frozen distribution
locale.setlocale(locale.LC_ALL, 'C')
# Setup basic logging to stderr.
logger = logging.getLogger(WebSocketProxy.log_prefix)
logger.propagate = False
Expand Down

0 comments on commit cc56f7b

Please sign in to comment.