diff options
author | Marcos Casagrande <marcoscvp90@gmail.com> | 2020-06-01 14:32:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-01 14:32:08 +0200 |
commit | 1d3dce9a68c981aded31b4eb12f8a2ec4beecfab (patch) | |
tree | ea21bc746bab92715d5d9621edd272167f61451a /tools | |
parent | edeeedf40161dcc4932a33139a7fffa1a73cc142 (diff) |
fix(cli/js/web): formData parser for binary files (#6015)
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/http_server.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tools/http_server.py b/tools/http_server.py index 76f8e6e69..d143f0ba8 100755 --- a/tools/http_server.py +++ b/tools/http_server.py @@ -207,6 +207,25 @@ class ContentTypeHandler(QuietSimpleHTTPRequestHandler): data_string = self.rfile.read(int(self.headers['Content-Length'])) self.wfile.write(bytes(data_string)) return + if "echo_multipart_file" 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() + file_content = self.rfile.read(int(self.headers['Content-Length'])) + self.wfile.write( + bytes('--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="file"; ' + 'filename="file.bin"\r\n' + 'Content-Type: application/octet-stream\r\n' + '\r\n') + bytes(file_content) + + bytes('\r\n--boundary--\r\n')) + return self.protocol_version = 'HTTP/1.1' self.send_response(501) self.send_header('content-type', 'text/plain') |