Skip to content

Instantly share code, notes, and snippets.

@chb0github
Last active January 24, 2019 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chb0github/4ae97f5155786e91aa700554f369eae8 to your computer and use it in GitHub Desktop.
Save chb0github/4ae97f5155786e91aa700554f369eae8 to your computer and use it in GitHub Desktop.
# python -m SimpleHTTPPutServer 8080
import SimpleHTTPServer
import BaseHTTPServer
import uuid
class SputHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_PUT(self):
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)
def do_POST(self):
length = int(self.headers["Content-Length"])
path = self.translate_path(self.path)
with open(str(uuid.uuid4()) + ".json", "wb") as dst:
dst.write(self.rfile.read(length))
self.send_response(201)
if __name__ == '__main__':
SimpleHTTPServer.test(HandlerClass=SputHTTPRequestHandler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment