From 53cb33371325f724684fa080960d336cc6aad9d6 Mon Sep 17 00:00:00 2001 From: Huachao Mao Date: Mon, 6 Sep 2021 10:10:53 +0800 Subject: [PATCH 1/3] Support pagination for stream api (#2572) --- trunk/src/app/srs_app_http_api.cpp | 8 ++++++-- trunk/src/app/srs_app_statistic.cpp | 12 ++++++++---- trunk/src/app/srs_app_statistic.hpp | 4 +++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index 6e9bec311..ce74b2178 100644 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -755,8 +755,12 @@ srs_error_t SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa if (!stream) { SrsJsonArray* data = SrsJsonAny::array(); obj->set("streams", data); - - if ((err = stat->dumps_streams(data)) != srs_success) { + + std::string rstart = r->query_get("start"); + std::string rcount = r->query_get("count"); + int start = srs_max(0, atoi(rstart.c_str())); + int count = srs_max(10, atoi(rcount.c_str())); + if ((err = stat->dumps_streams(data, start, count)) != srs_success) { int code = srs_error_code(err); srs_error_reset(err); return srs_api_response_code(w, r, code); diff --git a/trunk/src/app/srs_app_statistic.cpp b/trunk/src/app/srs_app_statistic.cpp index 1d75f280a..d861b0fa8 100644 --- a/trunk/src/app/srs_app_statistic.cpp +++ b/trunk/src/app/srs_app_statistic.cpp @@ -495,12 +495,16 @@ srs_error_t SrsStatistic::dumps_vhosts(SrsJsonArray* arr) return err; } -srs_error_t SrsStatistic::dumps_streams(SrsJsonArray* arr) +srs_error_t SrsStatistic::dumps_streams(SrsJsonArray* arr, int start, int count) { srs_error_t err = srs_success; - - std::map::iterator it; - for (it = streams.begin(); it != streams.end(); it++) { + + std::map::iterator it = streams.begin(); + for (int i = 0; i < start + count && it != streams.end(); i++) { + if (i < start) { + continue; + } + SrsStatisticStream* stream = it->second; SrsJsonObject* obj = SrsJsonAny::object(); diff --git a/trunk/src/app/srs_app_statistic.hpp b/trunk/src/app/srs_app_statistic.hpp index 8c8215ef0..b196a4f0a 100644 --- a/trunk/src/app/srs_app_statistic.hpp +++ b/trunk/src/app/srs_app_statistic.hpp @@ -182,7 +182,9 @@ public: // Dumps the vhosts to amf0 array. virtual srs_error_t dumps_vhosts(SrsJsonArray* arr); // Dumps the streams to amf0 array. - virtual srs_error_t dumps_streams(SrsJsonArray* arr); + // @param start the start index, from 0. + // @param count the max count of streams to dump. + virtual srs_error_t dumps_streams(SrsJsonArray* arr, int start, int count); // Dumps the clients to amf0 array // @param start the start index, from 0. // @param count the max count of clients to dump. From ff9e2339c1b74a51a9ce7bc2d8b9028eb0ac3837 Mon Sep 17 00:00:00 2001 From: Huachao Mao Date: Tue, 7 Sep 2021 08:14:40 +0800 Subject: [PATCH 2/3] Fix stream api iterator not incremented (#2582) --- trunk/src/app/srs_app_statistic.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trunk/src/app/srs_app_statistic.cpp b/trunk/src/app/srs_app_statistic.cpp index d861b0fa8..68c85a207 100644 --- a/trunk/src/app/srs_app_statistic.cpp +++ b/trunk/src/app/srs_app_statistic.cpp @@ -500,7 +500,7 @@ srs_error_t SrsStatistic::dumps_streams(SrsJsonArray* arr, int start, int count) srs_error_t err = srs_success; std::map::iterator it = streams.begin(); - for (int i = 0; i < start + count && it != streams.end(); i++) { + for (int i = 0; i < start + count && it != streams.end(); it++, i++) { if (i < start) { continue; } From a583d7efb4f35dd3ca7d1072ffb3c154b0296c25 Mon Sep 17 00:00:00 2001 From: Justin Kromlinger Date: Tue, 7 Sep 2021 02:15:27 +0200 Subject: [PATCH 3/3] Set empty HTTP paths to '/' to avoid malformed requests (#2329) This resolves #1610. --- trunk/src/protocol/srs_service_http_client.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/trunk/src/protocol/srs_service_http_client.cpp b/trunk/src/protocol/srs_service_http_client.cpp index bd25ebfbc..b88ec99a0 100644 --- a/trunk/src/protocol/srs_service_http_client.cpp +++ b/trunk/src/protocol/srs_service_http_client.cpp @@ -322,6 +322,10 @@ srs_error_t SrsHttpClient::post(string path, string req, ISrsHttpMessage** ppmsg return srs_error_wrap(err, "http: connect server"); } + if (path.size() == 0) { + path = "/"; + } + // send POST request to uri // POST %s HTTP/1.1\r\nHost: %s\r\nContent-Length: %d\r\n\r\n%s std::stringstream ss;