diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/base/test/file_bug1250148.sjs | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | dom/base/test/file_bug1250148.sjs | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/dom/base/test/file_bug1250148.sjs b/dom/base/test/file_bug1250148.sjs new file mode 100644 index 0000000000..5f8037a08a --- /dev/null +++ b/dom/base/test/file_bug1250148.sjs @@ -0,0 +1,73 @@ +const CC = Components.Constructor; +const BinaryInputStream = CC( + "@mozilla.org/binaryinputstream;1", + "nsIBinaryInputStream", + "setInputStream" +); + +function utf8decode(s) { + return decodeURIComponent(escape(s)); +} + +function utf8encode(s) { + return unescape(encodeURIComponent(s)); +} + +function handleRequest(request, response) { + var bodyStream = new BinaryInputStream(request.bodyInputStream); + + var requestBody = ""; + while ((bodyAvail = bodyStream.available()) > 0) { + requestBody += bodyStream.readBytes(bodyAvail); + } + + var result = []; + + if (request.method == "POST") { + var contentTypeParams = {}; + request + .getHeader("Content-Type") + .split(/\s*\;\s*/) + .forEach(function (str) { + if (str.indexOf("=") >= 0) { + let [name, value] = str.split("="); + contentTypeParams[name] = value; + } else { + contentTypeParams[""] = str; + } + }); + + if ( + contentTypeParams[""] == "multipart/form-data" && + request.queryString == "" + ) { + requestBody + .split("--" + contentTypeParams.boundary) + .slice(1, -1) + .forEach(function (s) { + let headers = {}; + let headerEnd = s.indexOf("\r\n\r\n"); + s.substr(2, headerEnd - 2) + .split("\r\n") + .forEach(function (str) { + // We're assuming UTF8 for now + let [name, value] = str.split(": "); + headers[name] = utf8decode(value); + }); + + let body = s.substring(headerEnd + 4, s.length - 2); + if ( + !headers["Content-Type"] || + headers["Content-Type"] == "text/plain" + ) { + // We're assuming UTF8 for now + body = utf8decode(body); + } + result.push({ headers, body }); + }); + } + } + + response.setHeader("Content-Type", "text/plain; charset=utf-8", false); + response.write(utf8encode(JSON.stringify(result))); +} |