diff options
author | Kevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com> | 2018-12-21 17:09:53 -0500 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-12-21 17:09:53 -0500 |
commit | cbee2895b3643aaccd62b221bf1bb4ac6a1ca9fb (patch) | |
tree | c02fb8a8edcea85f86c12a14a9736f3b35357a85 /tools/http_server.py | |
parent | 317fddbbf8615b8cb4dc3c0ea7d81c0c80a8e3ee (diff) |
Implement `Body.formData` for fetch (#1393)
Diffstat (limited to 'tools/http_server.py')
-rwxr-xr-x | tools/http_server.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tools/http_server.py b/tools/http_server.py index f9820ff19..6cf997b86 100755 --- a/tools/http_server.py +++ b/tools/http_server.py @@ -15,6 +15,30 @@ REDIRECT_PORT = 4546 class ContentTypeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): + def do_GET(self): + if "multipart_form_data.txt" in self.path: + self.protocol_version = 'HTTP/1.1' + self.send_response(200, 'OK') + self.send_header('Content-type', + 'multipart/form-data;boundary=boundary') + self.end_headers() + self.wfile.write( + bytes('Preamble\r\n' + '--boundary\t \r\n' + 'Content-Disposition: form-data; name="field_1"\r\n' + '\r\n' + 'value_1 \r\n' + '\r\n--boundary\r\n' + 'Content-Disposition: form-data; name="field_2"; ' + 'filename="file.js"\r\n' + 'Content-Type: text/javascript\r\n' + '\r\n' + 'console.log("Hi")' + '\r\n--boundary--\r\n' + 'Epilogue')) + return + return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self) + def guess_type(self, path): if ".t1." in path: return "text/typescript" @@ -32,6 +56,8 @@ class ContentTypeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): return "text/ecmascript" if ".j4." in path: return "application/x-javascript" + if "form_urlencoded" in path: + return "application/x-www-form-urlencoded" return SimpleHTTPServer.SimpleHTTPRequestHandler.guess_type(self, path) |