Skip to content

Commit 42d9e37

Browse files
committed
Fix empty files upload test
- Fix emulation of blank file field upload - Replace cURL file upload with socket communication - Resolve #2778 Irrelevant metadata for blank file upload field
1 parent 5ca0dbe commit 42d9e37

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

tests/swoole_http_server/upload_file_empty.phpt

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,37 @@ require __DIR__ . '/../include/bootstrap.php';
1313
$pm = new ProcessManager;
1414

1515
$pm->parentFunc = function () use ($pm) {
16-
$formData = [
17-
'file1' => curl_file_create('/dev/null', 'text/plain', 'empty.txt'),
18-
'file2' => curl_file_create('/dev/null', 'application/octet-stream', ' '),
19-
];
20-
21-
$ch = curl_init();
22-
curl_setopt($ch, CURLOPT_URL, "http://127.0.0.1:{$pm->getFreePort()}");
23-
curl_setopt($ch, CURLOPT_HEADER, 0);
24-
curl_setopt($ch, CURLOPT_POST, 1);
25-
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Expect:']);
26-
curl_setopt($ch, CURLOPT_POSTFIELDS, $formData);
27-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
28-
$result = curl_exec($ch);
29-
curl_close($ch);
16+
$boundary = "------------------------d3f990cdce762596";
17+
$body = implode("\r\n", [
18+
"--$boundary",
19+
'Content-Disposition: form-data; name="file1"; filename="empty.txt"',
20+
'Content-Type: text/plain',
21+
'',
22+
'',
23+
"--$boundary",
24+
'Content-Disposition: form-data; name="file2"; filename=""',
25+
'Content-Type: application/octet-stream',
26+
'',
27+
'',
28+
"--$boundary--",
29+
'',
30+
]);
31+
$request = implode("\r\n", [
32+
'POST / HTTP/1.1',
33+
"Content-Type: multipart/form-data; boundary=$boundary",
34+
'Content-Length: ' . strlen($body),
35+
'',
36+
'',
37+
$body,
38+
]);
39+
40+
$sock = stream_socket_client("tcp://127.0.0.1:{$pm->getFreePort()}");
41+
fwrite($sock, $request);
42+
stream_set_chunk_size($sock, 2 * 1024 * 1024);
43+
$response = fread($sock, 2 * 1024 * 1024);
44+
fclose($sock);
3045

46+
$result = ltrim(strstr($response, "\r\n\r\n"));
3147
echo "$result\n";
3248
$pm->kill();
3349
};

0 commit comments

Comments
 (0)