Improve logging, fix small issues

This commit is contained in:
2021-03-28 15:58:07 +02:00
parent cd053bc74e
commit 210c03b73f
10 changed files with 58 additions and 60 deletions

View File

@@ -5,7 +5,7 @@ from abc import ABC, abstractmethod
from datetime import datetime
from httplib import parser
from httplib.exceptions import NotFound, Forbidden, NotModified
from httplib.exceptions import NotFound, Forbidden, NotModified, BadRequest
from httplib.httpsocket import FORMAT
from httplib.message import RequestMessage as Message
@@ -66,8 +66,6 @@ class AbstractCommand(ABC):
def _build_message(self, status: int, content_type: str, body: bytes, extra_headers=None):
if extra_headers is None:
extra_headers = {}
self._process_conditional_headers()
message = f"HTTP/1.1 {status} {status_message[status]}\r\n"
@@ -237,3 +235,9 @@ class PutCommand(AbstractModifyCommand):
@property
def _file_mode(self):
return "w"
def execute(self):
if "content-range" in self.msg.headers:
raise BadRequest("PUT request contains Content-Range header")
super().execute()

View File

@@ -1,6 +1,4 @@
import logging
import os
import sys
from socket import socket
from typing import Union
from urllib.parse import ParseResultBytes, ParseResult

View File

@@ -85,6 +85,7 @@ class Worker:
RequestHandler.send_error(conn, InternalServerError.status_code, InternalServerError.message)
break
logging.info("Closing socket for client %s", addr)
conn.shutdown(socket.SHUT_RDWR)
conn.close()
# Finished, put back into queue