diff options
Diffstat (limited to 'day7/http_handler.py')
| -rw-r--r-- | day7/http_handler.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/day7/http_handler.py b/day7/http_handler.py index 8fd27bc..6db918c 100644 --- a/day7/http_handler.py +++ b/day7/http_handler.py @@ -2,6 +2,7 @@ from socket import socket, AF_INET, SOCK_STREAM, SHUT_RDWR, SOL_SOCKET, SO_REUSE from time import strftime, gmtime import logging +import db from backend import run from utils import ( parse_cookies, parse_query, parse_headers, @@ -10,10 +11,9 @@ from utils import ( ) from templater import render_template from config import * -import db -logging.basicConfig(filename='log.log', level=logging.INFO) +logging.basicConfig(filename=db.get_config_entry('log_path'), level=logging.INFO) def log_requests(func): @@ -93,14 +93,15 @@ def parse_request(connection): cookies = {} if 'Content-Type' in headers and headers['Content-Type'] == 'application/x-www-form-urlencoded': + chunk = db.get_config_entry('chunk') length = int(headers['Content-Length']) - len(buffer) while length > 0: - if length < CHUNK: + if length < chunk: data = connection.recv(length) length = 0 else: - data = connection.recv(CHUNK) - length -= CHUNK + data = connection.recv(chunk) + length -= chunk buffer += data[0] @@ -138,7 +139,10 @@ def handle_connection(connection, address): connection.sendall(response.encode()) -def main(host, port): +def main(): + host = db.get_config_entry('host') + port = db.get_config_entry('port') + sock = socket(AF_INET, SOCK_STREAM) sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) sock.bind((host, port)) @@ -175,5 +179,4 @@ def main(host, port): if __name__ == '__main__': - HOST, PORT = ADDR = '0.0.0.0', 8888 - main(HOST, PORT) + main() |