Last active
May 31, 2024 10:18
-
-
Save fabiand/5628006 to your computer and use it in GitHub Desktop.
A simple HTTP Server supporting put (python3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# python3 -m SimpleHTTPPutServer 8080 | |
from http.server import HTTPServer, SimpleHTTPRequestHandler | |
class PutHTTPRequestHandler(SimpleHTTPRequestHandler): | |
def do_PUT(self): | |
print(self.headers) | |
length = int(self.headers["Content-Length"]) | |
path = self.translate_path(self.path) | |
with open(path, "wb") as dst: | |
dst.write(self.rfile.read(length)) | |
self.send_response(200) | |
self.end_headers() | |
def run(server_class=HTTPServer, handler_class=PutHTTPRequestHandler): | |
server_address = ('', 8000) | |
httpd = server_class(server_address, handler_class) | |
httpd.serve_forever() | |
if __name__ == '__main__': | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've updated the gist to stay minimal, but be python3 based.