From 3f68d88666c832e0af50c5f4543ba3513c5fb0cb Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 25 May 2019 19:35:44 +0400 Subject: =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0?= =?UTF-8?q?=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B0=D1=80=D0=B3=D1=83=D0=BC=D0=B5=D0=BD=D1=82=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4=D0=BD=D0=BE=D0=B9=20=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day7/http_handler.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'day7/http_handler.py') 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() -- cgit v1.2.3