forked from WorldBrain/Memex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleHTTPPutServer.py
More file actions
24 lines (20 loc) · 805 Bytes
/
SimpleHTTPPutServer.py
File metadata and controls
24 lines (20 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# python -m SimpleHTTPPutServer 8080
import os
from os import path
import http.server
class SputHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
def do_PUT(self):
length = int(self.headers["Content-Length"])
filepath = self.translate_path(self.path)
dirpath = path.dirname(filepath)
os.makedirs(dirpath, exist_ok=True)
with open(filepath, "wb") as dst:
dst.write(self.rfile.read(length))
self.send_response(200, 'OK')
self.end_headers()
def run(server_class=http.server.HTTPServer, handler_class=http.server.BaseHTTPRequestHandler):
server_address = ('', 8000)
httpd = server_class(server_address, handler_class)
httpd.serve_forever()
if __name__ == '__main__':
run(handler_class=SputHTTPRequestHandler)