1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Fix #2881: HTTP: Support merging api to server. v5.0.47

This commit is contained in:
winlin 2022-08-28 09:10:13 +08:00
parent 6508a082e9
commit 457738f6eb
34 changed files with 333 additions and 934 deletions

View file

@ -61,6 +61,10 @@ srs_error_t prepare_main() {
_srs_context = new SrsThreadContext();
#ifdef SRS_SRT
if ((err = srs_srt_log_initialize()) != srs_success) {
return srs_error_wrap(err, "srt log initialize");
}
_srt_eventloop = new SrsSrtEventLoop();
if ((err = _srt_eventloop->initialize()) != srs_success) {
return srs_error_wrap(err, "srt poller initialize");

View file

@ -3558,6 +3558,58 @@ VOID TEST(ConfigMainTest, CheckVhostConfig4)
}
}
VOID TEST(ConfigMainTest, CheckHttpListen)
{
srs_error_t err;
if (true) {
MockSrsConfig conf;
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "http_api{enabled on;listen xxx;}http_server{enabled on;listen xxx;}"));
EXPECT_TRUE(conf.get_http_stream_enabled());
EXPECT_STREQ("xxx", conf.get_http_stream_listen().c_str());
EXPECT_STREQ("xxx", conf.get_http_api_listen().c_str());
EXPECT_TRUE(conf.get_http_stream_crossdomain());
}
if (true) {
MockSrsConfig conf;
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "http_api{enabled on;listen xxx;}http_server{enabled on;listen xxx;}"));
EXPECT_TRUE(conf.get_http_stream_enabled());
EXPECT_STREQ("xxx", conf.get_http_stream_listen().c_str());
EXPECT_STREQ("8088", conf.get_https_stream_listen().c_str());
EXPECT_STREQ("xxx", conf.get_http_api_listen().c_str());
EXPECT_STREQ("8088", conf.get_https_api_listen().c_str());
EXPECT_TRUE(conf.get_http_stream_crossdomain());
}
if (true) {
MockSrsConfig conf;
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "http_api{enabled on;listen mmm;https{enabled on;listen zzz;}}http_server{enabled on;listen xxx;https{enabled on;listen yyy;}}"));
EXPECT_TRUE(conf.get_http_stream_enabled());
EXPECT_STREQ("xxx", conf.get_http_stream_listen().c_str());
EXPECT_STREQ("yyy", conf.get_https_stream_listen().c_str());
EXPECT_STREQ("mmm", conf.get_http_api_listen().c_str());
EXPECT_STREQ("zzz", conf.get_https_api_listen().c_str());
EXPECT_TRUE(conf.get_http_stream_crossdomain());
}
if (true) {
MockSrsConfig conf;
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "http_api{enabled on;listen xxx;https{enabled on;listen yyy;}}http_server{enabled on;listen xxx;https{enabled on;listen yyy;}}"));
EXPECT_TRUE(conf.get_http_stream_enabled());
EXPECT_STREQ("xxx", conf.get_http_stream_listen().c_str());
EXPECT_STREQ("yyy", conf.get_https_stream_listen().c_str());
EXPECT_STREQ("xxx", conf.get_http_api_listen().c_str());
EXPECT_STREQ("yyy", conf.get_https_api_listen().c_str());
EXPECT_TRUE(conf.get_http_stream_crossdomain());
}
if (true) {
MockSrsConfig conf;
HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "http_api{enabled on;listen xxx;https{enabled on;listen zzz;}}http_server{enabled on;listen xxx;https{enabled on;listen yyy;}}"));
}
}
VOID TEST(ConfigMainTest, CheckVhostConfig5)
{
srs_error_t err;
@ -3803,8 +3855,8 @@ VOID TEST(ConfigMainTest, CheckIncludeConfig)
conf.mock_include("./conf/include_test/include_3.conf", "hls {enabled on;hls_path xxx;hls_m3u8_file xxx1;hls_ts_file xxx2;hls_fragment 10;hls_window 60;}");
conf.mock_include("./conf/include_test/include_4.conf", "listen 1935;max_connections 1000;daemon off;srs_log_tank console;include ./conf/include_test/include_5.conf;vhost ossrs.net {include ./conf/include_test/include_3.conf;}include ./conf/include_test/include_6.conf;");
conf.mock_include("./conf/include_test/include_5.conf", "http_server {enabled on;listen xxx;dir xxx2;}");
conf.mock_include("./conf/include_test/include_6.conf", "http_api {enabled on;listen xxx;}");
conf.mock_include("./conf/include_test/include_5.conf", "http_server {enabled on;listen 8080;dir xxx2;}");
conf.mock_include("./conf/include_test/include_6.conf", "http_api {enabled on;listen 1985;}");
HELPER_ASSERT_SUCCESS(conf.parse("include ./conf/include_test/include_4.conf;"));
@ -3815,7 +3867,7 @@ VOID TEST(ConfigMainTest, CheckIncludeConfig)
EXPECT_FALSE(conf.get_log_tank_file());
EXPECT_TRUE(conf.get_http_stream_enabled());
EXPECT_STREQ("xxx", conf.get_http_stream_listen().c_str());
EXPECT_STREQ("8080", conf.get_http_stream_listen().c_str());
EXPECT_STREQ("xxx2", conf.get_http_stream_dir().c_str());
EXPECT_TRUE(conf.get_hls_enabled("ossrs.net"));
@ -3826,7 +3878,7 @@ VOID TEST(ConfigMainTest, CheckIncludeConfig)
EXPECT_EQ(60*SRS_UTIME_SECONDS, conf.get_hls_window("ossrs.net"));
EXPECT_TRUE(conf.get_http_api_enabled());
EXPECT_STREQ("xxx", conf.get_http_api_listen().c_str());
EXPECT_STREQ("1985", conf.get_http_api_listen().c_str());
}
if (true) {
@ -3835,7 +3887,7 @@ VOID TEST(ConfigMainTest, CheckIncludeConfig)
conf.mock_include("./conf/include_test/include_3.conf", "hls {enabled on;hls_path xxx;hls_m3u8_file xxx1;hls_ts_file xxx2;hls_fragment 10;hls_window 60;}");
conf.mock_include("./conf/include_test/include_4.conf", "listen 1935;max_connections 1000;daemon off;srs_log_tank console;include ./conf/include_test/include_5.conf ./conf/include_test/include_6.conf;vhost ossrs.net {include ./conf/include_test/include_3.conf;}");
conf.mock_include("./conf/include_test/include_5.conf", "http_server {enabled on;listen xxx;dir xxx2;}");
conf.mock_include("./conf/include_test/include_6.conf", "http_api {enabled on;listen xxx;}");
conf.mock_include("./conf/include_test/include_6.conf", "http_api {enabled on;listen yyy;}");
HELPER_ASSERT_SUCCESS(conf.parse("include ./conf/include_test/include_4.conf;"));
@ -3850,7 +3902,7 @@ VOID TEST(ConfigMainTest, CheckIncludeConfig)
EXPECT_STREQ("xxx2", conf.get_http_stream_dir().c_str());
EXPECT_TRUE(conf.get_http_api_enabled());
EXPECT_STREQ("xxx", conf.get_http_api_listen().c_str());
EXPECT_STREQ("yyy", conf.get_http_api_listen().c_str());
EXPECT_TRUE(conf.get_hls_enabled("ossrs.net"));
EXPECT_STREQ("xxx", conf.get_hls_path("ossrs.net").c_str());
@ -3866,7 +3918,7 @@ VOID TEST(ConfigMainTest, CheckIncludeConfig)
conf.mock_include("./conf/include_test/include_3.conf", "hls {enabled on;hls_path xxx;hls_m3u8_file xxx1;hls_ts_file xxx2;hls_fragment 10;hls_window 60;}");
conf.mock_include("./conf/include_test/include_4.conf", "listen 1935;max_connections 1000;daemon off;srs_log_tank console;include ./conf/include_test/include_5.conf ./conf/include_test/include_6.conf;vhost ossrs.net {include ./conf/include_test/include_3.conf ./conf/include_test/include_7.conf;}");
conf.mock_include("./conf/include_test/include_5.conf", "http_server {enabled on;listen xxx;dir xxx2;}");
conf.mock_include("./conf/include_test/include_6.conf", "http_api {enabled on;listen xxx;}");
conf.mock_include("./conf/include_test/include_6.conf", "http_api {enabled on;listen yyy;}");
conf.mock_include("./conf/include_test/include_7.conf", "dash{enabled on;dash_fragment 10;dash_update_period 10;dash_timeshift 10;dash_path xxx;dash_mpd_file xxx2;}");
HELPER_ASSERT_SUCCESS(conf.parse("include ./conf/include_test/include_4.conf;"));
@ -3882,7 +3934,7 @@ VOID TEST(ConfigMainTest, CheckIncludeConfig)
EXPECT_STREQ("xxx2", conf.get_http_stream_dir().c_str());
EXPECT_TRUE(conf.get_http_api_enabled());
EXPECT_STREQ("xxx", conf.get_http_api_listen().c_str());
EXPECT_STREQ("yyy", conf.get_http_api_listen().c_str());
EXPECT_TRUE(conf.get_hls_enabled("ossrs.net"));
EXPECT_STREQ("xxx", conf.get_hls_path("ossrs.net").c_str());

View file

@ -23,12 +23,6 @@ void MockReloadHandler::reset()
{
listen_reloaded = false;
pithy_print_reloaded = false;
http_api_enabled_reloaded = false;
http_api_disabled_reloaded = false;
http_stream_enabled_reloaded = false;
http_stream_disabled_reloaded = false;
http_stream_updated_reloaded = false;
vhost_http_updated_reloaded = false;
vhost_added_reloaded = false;
vhost_removed_reloaded = false;
vhost_play_reloaded = false;
@ -52,12 +46,6 @@ int MockReloadHandler::count_true()
if (listen_reloaded) count_true++;
if (pithy_print_reloaded) count_true++;
if (http_api_enabled_reloaded) count_true++;
if (http_api_disabled_reloaded) count_true++;
if (http_stream_enabled_reloaded) count_true++;
if (http_stream_disabled_reloaded) count_true++;
if (http_stream_updated_reloaded) count_true++;
if (vhost_http_updated_reloaded) count_true++;
if (vhost_added_reloaded) count_true++;
if (vhost_removed_reloaded) count_true++;
if (vhost_play_reloaded) count_true++;
@ -78,12 +66,6 @@ int MockReloadHandler::count_false()
if (!listen_reloaded) count_false++;
if (!pithy_print_reloaded) count_false++;
if (!http_api_enabled_reloaded) count_false++;
if (!http_api_disabled_reloaded) count_false++;
if (!http_stream_enabled_reloaded) count_false++;
if (!http_stream_disabled_reloaded) count_false++;
if (!http_stream_updated_reloaded) count_false++;
if (!vhost_http_updated_reloaded) count_false++;
if (!vhost_added_reloaded) count_false++;
if (!vhost_removed_reloaded) count_false++;
if (!vhost_play_reloaded) count_false++;
@ -120,42 +102,6 @@ srs_error_t MockReloadHandler::on_reload_pithy_print()
return srs_success;
}
srs_error_t MockReloadHandler::on_reload_http_api_enabled()
{
http_api_enabled_reloaded = true;
return srs_success;
}
srs_error_t MockReloadHandler::on_reload_http_api_disabled()
{
http_api_disabled_reloaded = true;
return srs_success;
}
srs_error_t MockReloadHandler::on_reload_http_stream_enabled()
{
http_stream_enabled_reloaded = true;
return srs_success;
}
srs_error_t MockReloadHandler::on_reload_http_stream_disabled()
{
http_stream_disabled_reloaded = true;
return srs_success;
}
srs_error_t MockReloadHandler::on_reload_http_stream_updated()
{
http_stream_updated_reloaded = true;
return srs_success;
}
srs_error_t MockReloadHandler::on_reload_vhost_http_updated()
{
vhost_http_updated_reloaded = true;
return srs_success;
}
srs_error_t MockReloadHandler::on_reload_vhost_added(string /*vhost*/)
{
vhost_added_reloaded = true;
@ -319,132 +265,6 @@ VOID TEST(ConfigReloadTest, ReloadPithyPrint)
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadHttpApiEnabled)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"http_api {enabled off;}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_api {enabled off;}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_api {enabled on;}"));
EXPECT_TRUE(handler.http_api_enabled_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_api {enabled off;}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadHttpApiDisabled)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"http_api {enabled on;}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_api {enabled on;}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_api {enabled off;}"));
EXPECT_TRUE(handler.http_api_disabled_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_api {enabled on;}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadHttpStreamEnabled)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"http_stream {enabled off;}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_stream {enabled off;}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_stream {enabled on;}"));
EXPECT_TRUE(handler.http_stream_enabled_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_stream {enabled off;}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadHttpStreamDisabled)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"http_stream {enabled on;}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_stream {enabled on;}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_stream {enabled off;}"));
EXPECT_TRUE(handler.http_stream_disabled_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_stream {enabled on;}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadHttpStreamUpdated)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"http_stream {enabled on; listen 8080;}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_stream {enabled on; listen 8080;}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_stream {enabled on; listen 8000;}"));
EXPECT_TRUE(handler.http_stream_updated_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_stream {enabled on; listen 8080;}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadVhostHttpUpdated)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost http.srs.com {http {enabled on;mount /hls;}}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost http.srs.com {http {enabled on;mount /hls;}}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost http.srs.com {http {enabled on;mount /hls1;}}"));
EXPECT_TRUE(handler.vhost_http_updated_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost http.srs.com {http {enabled on;mount /hls;}}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadVhostAdded)
{
MockReloadHandler handler;

View file

@ -20,12 +20,6 @@ class MockReloadHandler : public ISrsReloadHandler
public:
bool listen_reloaded;
bool pithy_print_reloaded;
bool http_api_enabled_reloaded;
bool http_api_disabled_reloaded;
bool http_stream_enabled_reloaded;
bool http_stream_disabled_reloaded;
bool http_stream_updated_reloaded;
bool vhost_http_updated_reloaded;
bool vhost_added_reloaded;
bool vhost_removed_reloaded;
bool vhost_play_reloaded;
@ -49,12 +43,6 @@ public:
public:
virtual srs_error_t on_reload_listen();
virtual srs_error_t on_reload_pithy_print();
virtual srs_error_t on_reload_http_api_enabled();
virtual srs_error_t on_reload_http_api_disabled();
virtual srs_error_t on_reload_http_stream_enabled();
virtual srs_error_t on_reload_http_stream_disabled();
virtual srs_error_t on_reload_http_stream_updated();
virtual srs_error_t on_reload_vhost_http_updated();
virtual srs_error_t on_reload_vhost_added(std::string vhost);
virtual srs_error_t on_reload_vhost_removed(std::string vhost);
virtual srs_error_t on_reload_vhost_play(std::string vhost);