From 311a02c31e03b23cc66e662cce63e6c19d4bc662 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Sat, 9 Jul 2016 22:39:20 +0200 Subject: re-request credentials after sending token and use threading mixin --- server.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'server.py') diff --git a/server.py b/server.py index 4b72f83..32f022a 100755 --- a/server.py +++ b/server.py @@ -6,6 +6,7 @@ import argparse import functions import logging from http.server import BaseHTTPRequestHandler, HTTPServer +from socketserver import ThreadingMixIn logging.basicConfig(level=logging.INFO) @@ -21,6 +22,10 @@ def send_token(conf, username, orig_uri): functions.send_message(conf.jid, conf.password, username, message) +class ThreadingSimpleServer(ThreadingMixIn, HTTPServer): + pass + + class RequestHandler(BaseHTTPRequestHandler): def do_GET(self): global LAST_REQUEST_TIME, CACHE @@ -38,6 +43,7 @@ class RequestHandler(BaseHTTPRequestHandler): LAST_REQUEST_TIME = time.time() send_token(conf, username, self.headers['X-Original-URI']) self.send_response(401, "Token sent, retry") + self.send_header("WWW-Authenticate", "Basic realm=\"xmppmessage auth\"") else: self.send_response(429, 'Too Many Requests') else: @@ -47,7 +53,7 @@ class RequestHandler(BaseHTTPRequestHandler): self.send_response(200, "OK go forward") else: logging.info("Denied %s", username) - self.send_response(401, "Authentication failed, username or password wrong") + self.send_response(403, "Authentication failed, username or password wrong") else: self.send_response(401) self.send_header("WWW-Authenticate", "Basic realm=\"xmppmessage auth\"") -- cgit v1.2.1