diff options
author | Camil Staps | 2016-03-02 21:37:50 +0100 |
---|---|---|
committer | Camil Staps | 2016-03-02 21:39:52 +0100 |
commit | 436f26b4eb1b38089396374876908fdb06d3c015 (patch) | |
tree | d599191368ff027e98a704051dfa04a20d6645d1 /project1/proj1_s4498062/webhttp/message.py | |
parent | Assignment 2 (diff) |
Added framework project 1
Diffstat (limited to 'project1/proj1_s4498062/webhttp/message.py')
-rw-r--r-- | project1/proj1_s4498062/webhttp/message.py | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/project1/proj1_s4498062/webhttp/message.py b/project1/proj1_s4498062/webhttp/message.py new file mode 100644 index 0000000..fb47f88 --- /dev/null +++ b/project1/proj1_s4498062/webhttp/message.py @@ -0,0 +1,90 @@ +"""HTTP Messages
+
+This modules contains classes for representing HTTP responses and requests.
+"""
+
+reasondict = {
+ # Dictionary for code reasons
+ # Format: code : "Reason"
+ 500 : "Internal Server Error"
+}
+
+
+class Message(object):
+ """Class that stores a HTTP Message"""
+
+ def __init__(self):
+ """Initialize the Message"""
+ self.version = "HTTP/1.1"
+ self.startline = ""
+ self.body = ""
+ self.headerdict = dict()
+
+ def set_header(self, name, value):
+ """Add a header and its value
+
+ Args:
+ name (str): name of header
+ value (str): value of header
+ """
+ self.headerdict[name] = value
+
+ def get_header(self, name):
+ """Get the value of a header
+
+ Args:
+ name (str): name of header
+
+ Returns:
+ str: value of header, empty if header does not exist
+ """
+ if name in self.headerdict:
+ return self.headerdict[name]
+ else:
+ return ""
+
+ def __str__(self):
+ """Convert the Message to a string
+
+ Returns:
+ str: representation the can be sent over socket
+ """
+ message = ""
+ return message
+
+
+class Request(Message):
+ """Class that stores a HTTP request"""
+
+ def __init__(self):
+ """Initialize the Request"""
+ super(Request, self).__init__()
+ self.method = ""
+ self.uri = ""
+
+ def __str__(self):
+ """Convert the Request to a string
+
+ Returns:
+ str: representation the can be sent over socket
+ """
+ self.startline = ""
+ return super(Request, self).__str__()
+
+
+class Response(Message):
+ """Class that stores a HTTP Response"""
+
+ def __init__(self):
+ """Initialize the Response"""
+ super(Response, self).__init__()
+ self.code = 500
+
+ def __str__(self):
+ """Convert the Response to a string
+
+ Returns:
+ str: representation the can be sent over socket
+ """
+ self.startline = ""
+ return super(Response, self).__str__()
|