Skip to content

Commit

Permalink
RFC-1027 HTTP Server supports upload large file (#4748)
Browse files Browse the repository at this point in the history
* Optimize multipart_parser

* Support large file upload

* Support large file upload [2]

* optimize code, fix cmake file

* optimize code [2]

* add fuzz cases, optimize code

* add form_data tests

* fix tests

* fix tests [2]

* fix tests [3]

* fix tests [4]

* fix tests [5]

* fix tests [6]

* fix tests [7]

* fix tests [8]

* fix tests [9]

* rm

* add cases

* fix tests[8]

* fix tests[10]
  • Loading branch information
matyhtf authored Jun 22, 2022
1 parent d09e5dc commit 9702dda
Show file tree
Hide file tree
Showing 41 changed files with 1,328 additions and 230 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,5 @@ core-tests/samples/CMakeFiles/
/html
/tests/include/lib/vendor/
/tests/include/lib/composer.lock
/core-tests/fuzz/fuzz_results/
/core-tests/fuzz/bin/
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ file(GLOB_RECURSE SRC_LIST FOLLOW_SYMLINKS src/*.c src/*.cc
thirdparty/hiredis/net.c
thirdparty/hiredis/read.c
thirdparty/hiredis/sds.c
thirdparty/swoole_http_parser.c
thirdparty/multipart_parser.c
)
file(GLOB_RECURSE HEAD_FILES FOLLOW_SYMLINKS include/*.h)
file(GLOB_RECURSE HEAD_WAPPER_FILES FOLLOW_SYMLINKS include/wrapper/*.hpp)
Expand Down Expand Up @@ -146,8 +148,6 @@ set(ext_src_list ${ext_cxx_files}
thirdparty/php/sockets/conversions.cc
thirdparty/php/sockets/sockaddr_conv.cc
thirdparty/php/standard/proc_open.cc
thirdparty/swoole_http_parser.c
thirdparty/multipart_parser.c
thirdparty/nghttp2/nghttp2_hd.c
thirdparty/nghttp2/nghttp2_rcbuf.c
thirdparty/nghttp2/nghttp2_helper.c
Expand Down
1 change: 1 addition & 0 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ EOF
src/server/task_worker.cc \
src/server/worker.cc \
src/wrapper/event.cc \
src/wrapper/http.cc \
src/wrapper/timer.cc"

swoole_source_file="$swoole_source_file \
Expand Down
19 changes: 19 additions & 0 deletions core-tests/fuzz/cases/req1.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
POST / HTTP/1.1
Host: 127.0.0.1:35347
Accept: */*
Content-Length: 11199
Content-Type: multipart/form-data; boundary=------------------------18610972117ffaf2

--------------------------18610972117ffaf2
Content-Disposition: form-data; name="test"

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
--------------------------18610972117ffaf2
Content-Disposition: form-data; name="hello"

ibOnkVsuKvLnzrTeS81ueAmswSWiUUvcOtHAamPBw2NIgEM3286PmK0lvCcPDnsYQ0lm8/emwynbcngwmUJ5983lmEBj49th5ED73eFUGHSLQzTY1nAaD54f
--------------------------18610972117ffaf2
Content-Disposition: form-data; name="world"

NDdKoaAEmCjD+MFAo1tOBTJ0yPTWG2amx0f8wI/PJf/sIB+XAxRmdftsyd48o47Lt8U8pgIxBd4xcUsLGVomZZT13eIpsCHnPjSdgAr8vSBrxFciyHBIzkhFX8IxTBFs+YqMqiH5/YWx/TQnxoqYWcqa86RShKne2JmF6+JXZUkB6O3I21X1cioUmdK9d3pOBWGUviL9oY99FA0fVAC9qH01hyO2AQyh3hjhvpq1uPYhjnCwetQlpYExhxPC2Q1gJ9edA8pmccWFSRlS079wq8l1ikkQqNnLvzp15pzNmUbvDGXAywsQrpJco3G9b8gwljHGUPpctxBB8DyO1LfavJ8Zusa9rSA4NAA3NzZpZ5bbKy5rYFQASuFXd7orlXdoPkyZ7ERSqgIT6y8Y3pnPrzAs8LLEmGuWbjN6ME7PtUuT87f10GtobckOUqYJktX9fmD4lxgJT0uUam++HG1j3ztFzyaY1pCREYmKewy2Q5FTgYQxKNzN4WdRmz+X8k2upRFDEr22Gm1wUEct2vOZD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medd2kCJp4s2b9bewldPHan5WX6AMecl/4NXp1sQrHPjO9en0Xz5n92qKpdZQC8p2AdSlASNhAAKBu6nBzlMbzoyex/vlJcWtAzMyleHdvHOHpFF0z0SF4kmkpGMz/WKxpH2cagE973ExU1ClJi/BIcjP+p203Z/YBTkZCFhy2GH8DK4jXWvPJIfkG5m5Z1xbrkNwJIfUfd90ubiYgbhxawEbKRjhFDtl7PV1wA8fHKOxCY6I0DN0mqxIDYgxc0FVE85+NSYR8z5ucjFCHQmCoSwWohznWvIANmVgDt5tu6HeCirL02uGNgmvpStMxosgYKU4Xt84XstQm19eQnJXTiceTogNzh3X3UWxELUnc46UC9NiMOZrOq/vKRgRUvW1JhwBhpmYOOyOdn8EqsJyAsjgFWNZE3gwi3RIaA6MIjkO6yCtJPs2g==
--------------------------18610972117ffaf2--
Binary file added core-tests/fuzz/cases/req2.bin
Binary file not shown.
16 changes: 16 additions & 0 deletions core-tests/fuzz/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"project": {
"name": "fuzz",
"type": "bin"
},
"build": {
"ldflags": "",
"cxxflags": "",
"cflags": "",
"c_std": "",
"cxx_std": ""
},
"install": {
"target": ""
}
}
48 changes: 48 additions & 0 deletions core-tests/fuzz/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "phpx_embed.h"
#include <iostream>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>

using namespace php;
using namespace std;

int main(int argc, char * argv[])
{
VM vm(argc, argv);
cout << "hello world" << endl;

char buf[8192];
ssize_t n;

int fd = 0;
if (argc > 0) {
fd = open(argv[1], O_RDONLY);
}

n = read(fd, buf, 8192);
if (n < 0) {
fprintf(stderr, "failed to read data\n");
return 1;
}

auto req_var = exec("Swoole\\Http\\Request::create");

var_dump(req_var);

if (!req_var.isObject()) {
fprintf(stderr, "cannot create object of Swoole\\Http\\Request\n");
return 2;
}

Variant data(buf, n);

auto req = Object(req_var);
auto retval = req.exec("parse", data);

printf("retval=%ld", retval.toInt());

var_dump(req);

return 0;
}
4 changes: 2 additions & 2 deletions core-tests/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ cmake_minimum_required(VERSION 2.8)
project(samples)
#set(CMAKE_BUILD_TYPE Released)
set(CMAKE_CXX_STANDARD 11)
file(GLOB_RECURSE SOURCE_FILES FOLLOW_SYMLINKS *.cc)
file(GLOB_RECURSE SOURCE_FILES FOLLOW_SYMLINKS src/*.cc)

add_definitions(-DHAVE_CONFIG_H)

link_directories($ENV{SWOOLE_DIR}/lib)
include_directories(./include ./ $ENV{SWOOLE_DIR}/ $ENV{SWOOLE_DIR}/include/ BEFORE)
include_directories(. ./include $ENV{SWOOLE_DIR} $ENV{SWOOLE_DIR}/include BEFORE)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
add_executable(core_samples ${SOURCE_FILES})
target_link_libraries(core_samples swoole)
37 changes: 13 additions & 24 deletions core-tests/samples/s1.cc → core-tests/samples/src/s1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,36 @@
#include <iostream>

using swoole::Coroutine;
using swoole::coroutine::System;
using swoole::coroutine::Socket;
using swoole::coroutine::System;
using namespace std;

struct A
{
struct A {
int x;
int *y;
};

static A G_a =
{ 0, 0 };
static A G_a = {0, 0};

int main(int argc, char **argv)
{
int main(int argc, char **argv) {
swoole_event_init(SW_EVENTLOOP_WAIT_EXIT);
/**
* 协程1
*/
Coroutine::create([](void *arg)
{

// coroutine 1
Coroutine::create([](void *arg) {
G_a.x = 1234;
int y = 5678;
G_a.y = &y;
/**
* 这里协程挂起后,协程2 会执行,在协程2中修改了 x, y 值
* 协程2 退出或挂起后,重新回到协程1,这里的x和y的值已经不符合预期了
*/
// After the coroutine 1 is suspended here, the coroutine 2 will be executed, and the x, y values is updated in
// the coroutine 2. After the coroutine 2 suspends, go back to coroutine 1, where the values of x and y will be
// no longer as expected
System::sleep(1);
//这里会显示 100
// output 100
cout << "X=" << G_a.x << endl;
//这里会读到空指针
// read invalid point
cout << "Y=" << *G_a.y << endl;
});

/**
* 协程2
*/
Coroutine::create([](void *arg)
{
// coroutine 2
Coroutine::create([](void *arg) {
G_a.x = 100;
G_a.y = nullptr;
});
Expand Down
9 changes: 7 additions & 2 deletions core-tests/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ int main(int argc, char **argv) {

static void init_root_path(const char *_exec_file) {
char buf[PATH_MAX];
char *dir = getcwd(buf, sizeof(buf));
string file = string(dir) + "/" + _exec_file;
string file;
if (_exec_file[0] == '/') {
file = _exec_file;
} else {
char *dir = getcwd(buf, sizeof(buf));
file = string(dir) + "/" + _exec_file;
}
string relative_root_path = file.substr(0, file.rfind('/')) + "/../../";
char *_realpath = realpath(relative_root_path.c_str(), buf);
if (_realpath == nullptr) {
Expand Down
6 changes: 3 additions & 3 deletions core-tests/src/protocol/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ TEST(protocol, eof) {
}
});

serv.onWorkerStart = [&lock](swServer *serv, int worker_id) { lock.unlock(); };
serv.onWorkerStart = [&lock](Server *serv, WorkerId worker_id) { lock.unlock(); };

int recv_count = 0;

serv.onReceive = [&](swServer *serv, swRecvData *req) -> int {
serv.onReceive = [&](Server *serv, RecvData *req) -> int {
// printf("[1]LEN=%d, count=%d\n%s\n---------------------------------\n", req->info.len, recv_count,
// req->data); printf("[2]LEN=%d\n%s\n---------------------------------\n", pkgs[recv_count].length,
// pkgs[recv_count].str);
Expand All @@ -75,7 +75,7 @@ TEST(protocol, eof) {
recv_count++;

if (recv_count == PKG_N) {
kill(serv->gs->master_pid, SIGTERM);
kill(serv->get_master_pid(), SIGTERM);
}

return SW_OK;
Expand Down
42 changes: 39 additions & 3 deletions core-tests/src/server/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

using namespace swoole;
using namespace std;
using swoole::network::SyncClient;
using swoole::http_server::Context;

struct http_context {
unordered_map<string, string> headers;
Expand Down Expand Up @@ -98,7 +100,7 @@ static void test_run_server(function<void(Server *)> fn) {

sw_logger()->set_level(SW_LOG_WARNING);

swListenPort *port = serv.add_port(SW_SOCK_TCP, TEST_HOST, 0);
ListenPort *port = serv.add_port(SW_SOCK_TCP, TEST_HOST, 0);
if (!port) {
swoole_warning("listen failed, [error=%d]", swoole_get_last_error());
exit(2);
Expand All @@ -120,8 +122,11 @@ static void test_run_server(function<void(Server *)> fn) {
if (conn->websocket_status == swoole::websocket::STATUS_ACTIVE) {
sw_tg_buffer()->clear();
std::string resp = "Swoole: " + string(req->data, req->info.len);
swoole::websocket::encode(
sw_tg_buffer(), resp.c_str(), resp.length(), swoole::websocket::OPCODE_TEXT, swoole::websocket::FLAG_FIN);
swoole::websocket::encode(sw_tg_buffer(),
resp.c_str(),
resp.length(),
swoole::websocket::OPCODE_TEXT,
swoole::websocket::FLAG_FIN);
serv->send(session_id, sw_tg_buffer()->str, sw_tg_buffer()->length);
return SW_OK;
}
Expand Down Expand Up @@ -270,3 +275,34 @@ TEST(http_server, websocket_big) {
kill(getpid(), SIGTERM);
});
}

TEST(http_server, parser) {
std::thread t;
auto server = swoole::http_server::listen(":0", [](Context &ctx) {
EXPECT_EQ(ctx.form_data.size(), 3);
ctx.end("DONE");
});
server->worker_num = 1;
server->onWorkerStart = [&t](Server *server, uint32_t worker_id) {
t = std::thread([server]() {
swoole_signal_block_all();
string file = test::get_root_path() + "/core-tests/fuzz/cases/req1.bin";
File fp(file, O_RDONLY);
EXPECT_TRUE(fp.ready());
auto str = fp.read_content();
SyncClient c(SW_SOCK_TCP);
c.connect(TEST_HOST, server->get_primary_port()->port);
c.send(str->value(), str->get_length());
char buf[1024];
auto n = c.recv(buf, sizeof(buf));
c.close();
std::string resp(buf, n);

EXPECT_TRUE(resp.find("200 OK") != resp.npos);

kill(server->get_master_pid(), SIGTERM);
});
};
server->start();
t.join();
}
Loading

0 comments on commit 9702dda

Please sign in to comment.