fix(cli/js/web): formData parser for binary files (#6015)

This commit is contained in:
Marcos Casagrande 2020-06-01 14:32:08 +02:00 committed by GitHub
parent edeeedf401
commit 1d3dce9a68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 163 additions and 87 deletions

View file

@ -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')