From 436f26b4eb1b38089396374876908fdb06d3c015 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Wed, 2 Mar 2016 21:37:50 +0100 Subject: Added framework project 1 --- project1/proj1_s4498062/webhttp/composer.py | 50 +++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 project1/proj1_s4498062/webhttp/composer.py (limited to 'project1/proj1_s4498062/webhttp/composer.py') diff --git a/project1/proj1_s4498062/webhttp/composer.py b/project1/proj1_s4498062/webhttp/composer.py new file mode 100644 index 0000000..dfac7a1 --- /dev/null +++ b/project1/proj1_s4498062/webhttp/composer.py @@ -0,0 +1,50 @@ +""" Composer for HTTP responses + +This module contains a composer, which can compose responses to +HTTP requests from a client. +""" + +import time + +import webhttp.message +import webhttp.resource + + +class ResponseComposer: + """Class that composes a HTTP response to a HTTP request""" + + def __init__(self, timeout): + """Initialize the ResponseComposer + + Args: + timeout (int): connection timeout + """ + self.timeout = timeout + + def compose_response(self, request): + """Compose a response to a request + + Args: + request (webhttp.Request): request from client + + Returns: + webhttp.Response: response to request + + """ + response = webhttp.message.Response() + + # Stub code + response.code = 200 + response.set_header("Content-Length", 4) + response.set_header("Connection", "close") + response.body = "Test" + + return response + + def make_date_string(self): + """Make string of date and time + + Returns: + str: formatted string of date and time + """ + return time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime()) -- cgit v1.2.3