Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions SimpleHTTPAuthServer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ def do_authhead(self):

def do_GET(self):
''' Present frontpage with user authentication. '''
if self.headers.getheader('Authorization') is None:
if self.headers.get('Authorization') is None:
self.do_authhead()
self.wfile.write('no auth header received')
elif self.headers.getheader('Authorization') == 'Basic '+ self.KEY:
elif self.headers.get('Authorization') == 'Basic '+ self.KEY.decode("utf-8"):
SimpleHTTPRequestHandler.do_GET(self)
else:
self.do_authhead()
self.wfile.write(self.headers.getheader('Authorization'))
self.wfile.write(self.headers.get('Authorization'))
self.wfile.write('not authenticated')

def serve_https(https_port=80, https=True, start_dir=None, handler_class=SimpleHTTPAuthHandler):
Expand Down Expand Up @@ -92,7 +92,7 @@ def main():
print("", file=sys.stderr)
sys.exit(1)

SimpleHTTPAuthHandler.KEY = base64.b64encode(args.key)
SimpleHTTPAuthHandler.KEY = base64.b64encode(args.key.encode('utf-8'))

serve_https(int(args.port), https=args.https,
start_dir=args.dir, handler_class=SimpleHTTPAuthHandler)
Expand Down