Skip to content

Commit

Permalink
[5.1]Fix bug swoole#5168 (swoole#5169)
Browse files Browse the repository at this point in the history
* Fix bug swoole#5186

* Fix test
  • Loading branch information
NathanFreeman authored Oct 24, 2023
1 parent d445481 commit 2cf0afd
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
47 changes: 47 additions & 0 deletions tests/swoole_http_server/bug_5186.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
--TEST--
swoole_http_server: 在使用hyperf3的时候遇到Context::parse_multipart_data()的提示
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';

use Swoole\Coroutine\Client;
use Swoole\Http\Server;
use Swoole\Http\Request;
use Swoole\Http\Response;
use function Swoole\Coroutine\run;

$pm = new SwooleTest\ProcessManager;
$pm->parentFunc = function () use ($pm) {
run(function () use ($pm) {
$content = "POST / HTTP/1.1\r\nHost: 127.0.0.1:{$pm->getFreePort()}\r\nConnection: keep-alive\r\nContent-Length: 44\r\nContent-Type: multipart/form-data; boundary=----WebKitFormBoundaryOldDnwBESVoBBtI5\r\nAccept-Encoding: gzip, deflate\r\n\r\n------WebKitFormBoundaryOldDnwBESVoBBtI5--\r\n\r\n";
$client = new Client(SWOOLE_SOCK_TCP);
$client->connect('127.0.0.1', $pm->getFreePort(), 0.5);
$client->send($content);
$client->close();
});
echo "DONE\n";
$pm->kill();
};

$pm->childFunc = function () use ($pm) {
$http = new Server('127.0.0.1', $pm->getFreePort(), SWOOLE_BASE);
$http->set([
'log_file' => '/dev/null',
]);
$http->on('workerStart', function () use ($pm) {
$pm->wakeup();
});
$http->on('request', function (Request $request, Response $response) use ($http) {
var_dump($request->files);
$response->end('Hello World');
});
$http->start();
};
$pm->childFirst();
$pm->run();
?>
--EXPECT--
DONE
NULL
5 changes: 4 additions & 1 deletion thirdparty/multipart_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ ssize_t multipart_parser_execute(multipart_parser *p, const char *buf, size_t le
case s_start_boundary:
multipart_log_c("s_start_boundary");
if (p->index == p->boundary_length) {
if (c != CR) {
// https://github.com/swoole/swoole-src/issues/5168
if (c == '-') {
p->state = s_part_data_final_hyphen;
} else if (c != CR) {
ERROR_EXPECT(MPPE_BOUNDARY_END_NO_CRLF, CR);
}
p->index++;
Expand Down

0 comments on commit 2cf0afd

Please sign in to comment.