mirror of https://github.com/kurisufriend/shttpile
commit
4a66bb398a
Binary file not shown.
@ -0,0 +1,3 @@ |
||||
/technically/ standards-compliant http 1.1 server |
||||
|
||||
spec'd to RFC 2616 |
@ -0,0 +1,49 @@ |
||||
class status: |
||||
all_valid = { # https://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html |
||||
200: "OK",# add the rest l8r |
||||
403: "Forbidden", |
||||
404: "Not Found", |
||||
500: "Internal Server Error", |
||||
505: "HTTP Version not supported" |
||||
} |
||||
def __init__(self): |
||||
pass |
||||
@staticmethod |
||||
def add_status(status_line, code): |
||||
status_line.append(str(code)+" "+status.all_valid[code]) |
||||
class headers: |
||||
def __init__(self): |
||||
self.headers_dict = {} |
||||
def as_str(self): |
||||
ret = "" |
||||
for h in self.headers_dict: |
||||
ret += h+": "+str(self.headers_dict[h]) |
||||
ret += "\r\n" |
||||
return ret |
||||
class response: |
||||
def __init__(self): |
||||
self.status_line = [] |
||||
self.headers_obj = headers() |
||||
self.body = "" |
||||
def text(self): |
||||
return " ".join(self.status_line)+"\r\n"+self.headers_obj.as_str()+"\r\n"+self.body |
||||
@staticmethod |
||||
def build(query): |
||||
r = response() |
||||
|
||||
r.status_line.append("HTTP/1.1") |
||||
# check if query is heckin cute % valid/returnable |
||||
# always 200 for static testing |
||||
status.add_status(r.status_line, 200) |
||||
|
||||
f = open(query, "r") |
||||
r.body = f.read() |
||||
f.close() |
||||
|
||||
# manual for now |
||||
r.headers_obj.headers_dict["Server"] = "shttpile" |
||||
r.headers_obj.headers_dict["Content-Type"] = "text/html" |
||||
r.headers_obj.headers_dict["Content-Length"] = len(r.body.encode("ascii")) |
||||
r.headers_obj.headers_dict["X-Clacks-Overhead"] = "GNU Terry Pratchett, Aaron Swartz, Norm Macdonald" |
||||
|
||||
return r |
@ -0,0 +1,13 @@ |
||||
import socket |
||||
import response |
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
||||
s.bind(("0.0.0.0", 1337)) |
||||
s.listen() |
||||
while True: |
||||
c, c_add = s.accept() |
||||
print(c_add) |
||||
print(c.recv(1024).decode("ascii")) |
||||
r = response.response.build("body.html") |
||||
c.sendall(r.text().encode("ascii")) |
||||
c.close() |
||||
s.close() |
Loading…
Reference in new issue