summaryrefslogtreecommitdiff
path: root/project1/proj1_s4498062/webhttp/composer.py
diff options
context:
space:
mode:
authorCamil Staps2016-03-02 21:37:50 +0100
committerCamil Staps2016-03-02 21:39:52 +0100
commit436f26b4eb1b38089396374876908fdb06d3c015 (patch)
treed599191368ff027e98a704051dfa04a20d6645d1 /project1/proj1_s4498062/webhttp/composer.py
parentAssignment 2 (diff)
Added framework project 1
Diffstat (limited to 'project1/proj1_s4498062/webhttp/composer.py')
-rw-r--r--project1/proj1_s4498062/webhttp/composer.py50
1 files changed, 50 insertions, 0 deletions
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())