This repository has been archived on 2026-11-17. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
pythonwebserver/header.py
2020-10-30 19:15:21 +01:00

29 lines
No EOL
767 B
Python

def buildHeader(statusCode, mime, size):
header = (headers[str(statusCode)] + "Content-type: " + mimeTypes[mime] + "\nContent-Length: " + str(size) + "\n\n").encode("utf-8")
return header
headers = {
"200":"HTTP/1.1 200 OK\n",
"404":"HTTP/1.0 404 Not Found\n",
"500":"HTTP/1.1 500 Internal Server Error\n",
"301":"HTTP/1.1 301 Moved Permanently\n"
}
mimeTypes = {
"plain":"text/plain",
"txt":"text/plain",
"html":"text/html",
"css":"text/css",
"js":"text/javascript",
"png":"image/png",
"bmp":"image/bmp",
"gif":"image/gif",
"ico":"image/x-icon",
"jpeg":"image/jpeg",
"svg":"image/svg+xml",
"wav":"audio/wav",
"mp3":"audio/mpeg",
"zip":"application/zip",
"pdf":"application/pdf"
}