From cbee2895b3643aaccd62b221bf1bb4ac6a1ca9fb Mon Sep 17 00:00:00 2001 From: "Kevin (Kun) \"Kassimo\" Qian" Date: Fri, 21 Dec 2018 17:09:53 -0500 Subject: Implement `Body.formData` for fetch (#1393) --- tools/http_server.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tools/http_server.py') 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) -- cgit v1.2.3