summaryrefslogtreecommitdiff
path: root/day7/http_handler.py
diff options
context:
space:
mode:
authorAndrew <saintruler@gmail.com>2019-05-25 19:35:44 +0400
committerAndrew <saintruler@gmail.com>2019-05-25 19:35:44 +0400
commit3f68d88666c832e0af50c5f4543ba3513c5fb0cb (patch)
tree5d922bf8926020598a15ec30ecc3523b6fa3a003 /day7/http_handler.py
parenta4899cf1c6f65669cfa46fd0a99a51e4f55416ac (diff)
Добавлена обработка аргументов командной строки
Diffstat (limited to 'day7/http_handler.py')
-rw-r--r--day7/http_handler.py19
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()