master
sidekek 4 years ago
commit 4a66bb398a
  1. BIN
      __pycache__/response.cpython-39.pyc
  2. 1
      body.html
  3. 3
      readme.txt
  4. 49
      response.py
  5. 13
      server.py

@ -0,0 +1 @@
< BLACK_MAN> yes, hello. black man here

@ -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…
Cancel
Save