summary refs log tree commit diff
path: root/demo/webserver.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-08-15 11:50:14 +0100
committerErik Johnston <erik@matrix.org>2014-08-15 11:50:14 +0100
commitd72f897f078fa72548522440149369293f0d12b2 (patch)
tree4e8d692713f73389b89dea4fdba719b696c9f3af /demo/webserver.py
parentReimplement the get public rooms api to work with new DB schema (diff)
parentAdd a check to make sure that during state conflict res we only request a PDU... (diff)
downloadsynapse-d72f897f078fa72548522440149369293f0d12b2.tar.xz
Merge branch 'master' of github.com:matrix-org/synapse into sql_refactor
Conflicts:
	synapse/storage/stream.py
Diffstat (limited to 'demo/webserver.py')
-rw-r--r--demo/webserver.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/demo/webserver.py b/demo/webserver.py
index 78f3213540..875095c877 100644
--- a/demo/webserver.py
+++ b/demo/webserver.py
@@ -2,9 +2,32 @@ import argparse
 import BaseHTTPServer
 import os
 import SimpleHTTPServer
+import cgi, logging
 
 from daemonize import Daemonize
 
+class SimpleHTTPRequestHandlerWithPOST(SimpleHTTPServer.SimpleHTTPRequestHandler):
+    UPLOAD_PATH = "upload"
+
+    """
+    Accept all post request as file upload
+    """
+    def do_POST(self):
+
+        path = os.path.join(self.UPLOAD_PATH, os.path.basename(self.path))
+        length = self.headers['content-length']
+        data = self.rfile.read(int(length))
+
+        with open(path, 'wb') as fh:
+            fh.write(data)
+
+        self.send_response(200)
+        self.send_header('Content-Type', 'application/json')
+        self.end_headers()
+
+        # Return the absolute path of the uploaded file
+        self.wfile.write('{"url":"/%s"}' % path)
+
 
 def setup():
     parser = argparse.ArgumentParser()
@@ -19,7 +42,7 @@ def setup():
 
     httpd = BaseHTTPServer.HTTPServer(
         ('', args.port),
-        SimpleHTTPServer.SimpleHTTPRequestHandler
+        SimpleHTTPRequestHandlerWithPOST
     )
 
     def run():