This commit is contained in:
2026-01-26 10:21:03 +01:00
parent fe2f087d9f
commit fbc1a6e294
40 changed files with 3478 additions and 547 deletions
+22
View File
@@ -0,0 +1,22 @@
// retoor <retoor@molodetz.nl>
import "web" for Request
var content = ""
for (i in 0...1000) {
content = content + "ABCDEFGHIJ"
}
var body = "------boundary\r\n" +
"Content-Disposition: form-data; name=\"file\"; filename=\"large.bin\"\r\n" +
"Content-Type: application/octet-stream\r\n" +
"\r\n" +
content + "\r\n" +
"------boundary--\r\n"
var headers = {"Content-Type": "multipart/form-data; boundary=----boundary"}
var request = Request.new_("POST", "/upload", {}, headers, body, {}, null)
var form = request.form
System.print(form["file"]["filename"]) // expect: large.bin
System.print(form["file"]["content"].count) // expect: 10000
+26
View File
@@ -0,0 +1,26 @@
// retoor <retoor@molodetz.nl>
import "web" for Request
var body = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\n" +
"Content-Disposition: form-data; name=\"description\"\r\n" +
"\r\n" +
"Test file description\r\n" +
"------WebKitFormBoundary7MA4YWxkTrZu0gW\r\n" +
"Content-Disposition: form-data; name=\"file\"; filename=\"test.txt\"\r\n" +
"Content-Type: text/plain\r\n" +
"\r\n" +
"Hello, World!\r\n" +
"------WebKitFormBoundary7MA4YWxkTrZu0gW--\r\n"
var headers = {
"Content-Type": "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"
}
var request = Request.new_("POST", "/upload", {}, headers, body, {}, null)
var form = request.form
System.print(form["description"]) // expect: Test file description
System.print(form["file"]["filename"]) // expect: test.txt
System.print(form["file"]["content"]) // expect: Hello, World!
System.print(form["file"]["content_type"]) // expect: text/plain
+21
View File
@@ -0,0 +1,21 @@
// retoor <retoor@molodetz.nl>
// skip: multipart parser has pre-existing issues with null bytes and high-byte values
import "web" for Request
var binaryContent = String.fromByte(0) + String.fromByte(255) + String.fromByte(127)
var body = "------boundary\r\n" +
"Content-Disposition: form-data; name=\"data\"; filename=\"binary.dat\"\r\n" +
"Content-Type: application/octet-stream\r\n" +
"\r\n" +
binaryContent + "\r\n" +
"------boundary--\r\n"
var headers = {"Content-Type": "multipart/form-data; boundary=----boundary"}
var request = Request.new_("POST", "/upload", {}, headers, body, {}, null)
var form = request.form
System.print(form["data"]["content"].bytes.count) // expect: 3
System.print(form["data"]["content"].bytes[0]) // expect: 0
System.print(form["data"]["content"].bytes[1]) // expect: 255
System.print(form["data"]["content"].bytes[2]) // expect: 127
+15
View File
@@ -0,0 +1,15 @@
// retoor <retoor@molodetz.nl>
import "web" for Request
var body = "------boundary\n" +
"Content-Disposition: form-data; name=\"field\"\n" +
"\n" +
"value\n" +
"------boundary--\n"
var headers = {"Content-Type": "multipart/form-data; boundary=----boundary"}
var request = Request.new_("POST", "/submit", {}, headers, body, {}, null)
var form = request.form
System.print(form["field"]) // expect: value
+24
View File
@@ -0,0 +1,24 @@
// retoor <retoor@molodetz.nl>
import "web" for Request
var body = "------FormBoundary\r\n" +
"Content-Disposition: form-data; name=\"username\"\r\n" +
"\r\n" +
"john\r\n" +
"------FormBoundary\r\n" +
"Content-Disposition: form-data; name=\"email\"\r\n" +
"\r\n" +
"john@example.com\r\n" +
"------FormBoundary--\r\n"
var headers = {
"Content-Type": "multipart/form-data; boundary=----FormBoundary"
}
var request = Request.new_("POST", "/submit", {}, headers, body, {}, null)
var form = request.form
System.print(form["username"]) // expect: john
System.print(form["email"]) // expect: john@example.com
System.print(form["file"]) // expect: null