Skip to content

Instantly share code, notes, and snippets.

@fabiand
Last active May 31, 2024 10:18
Show Gist options
  • Save fabiand/5628006 to your computer and use it in GitHub Desktop.
Save fabiand/5628006 to your computer and use it in GitHub Desktop.
A simple HTTP Server supporting put (python3)
# 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()
@fabiand
Copy link
Author

fabiand commented May 31, 2024

I've updated the gist to stay minimal, but be python3 based.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment