From 94e34056e73f06061b55889c0365ee2ddfc02cee Mon Sep 17 00:00:00 2001 From: chenhaibo <495810242@qq.com> Date: Tue, 6 Dec 2022 18:16:22 +0800 Subject: [PATCH] parse fragment of uri --- trunk/src/protocol/srs_protocol_http_stack.cpp | 8 +++++++- trunk/src/protocol/srs_protocol_http_stack.hpp | 2 ++ trunk/src/protocol/srs_protocol_utility.cpp | 1 + trunk/src/utest/srs_utest_protocol.cpp | 12 ++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/trunk/src/protocol/srs_protocol_http_stack.cpp b/trunk/src/protocol/srs_protocol_http_stack.cpp index 91405506d1a..fcb0bf898e4 100644 --- a/trunk/src/protocol/srs_protocol_http_stack.cpp +++ b/trunk/src/protocol/srs_protocol_http_stack.cpp @@ -931,7 +931,7 @@ SrsHttpUri::~SrsHttpUri() srs_error_t SrsHttpUri::initialize(string url) { - schema = host = path = query = ""; + schema = host = path = query = fragment_ = ""; url_ = url; // Replace the default vhost to a domain like string, or parse failed. @@ -979,6 +979,7 @@ srs_error_t SrsHttpUri::initialize(string url) path = get_uri_field(parsing_url, &hp_u, UF_PATH); query = get_uri_field(parsing_url, &hp_u, UF_QUERY); + fragment_ = get_uri_field(parsing_url, &hp_u, UF_FRAGMENT); username_ = get_uri_field(parsing_url, &hp_u, UF_USERINFO); size_t pos = username_.find(":"); @@ -1040,6 +1041,11 @@ string SrsHttpUri::get_query_by_key(std::string key) return it->second; } +std::string SrsHttpUri::get_fragment() +{ + return fragment_; +} + std::string SrsHttpUri::username() { return username_; diff --git a/trunk/src/protocol/srs_protocol_http_stack.hpp b/trunk/src/protocol/srs_protocol_http_stack.hpp index 6360179540c..7608618b04f 100644 --- a/trunk/src/protocol/srs_protocol_http_stack.hpp +++ b/trunk/src/protocol/srs_protocol_http_stack.hpp @@ -580,6 +580,7 @@ class SrsHttpUri int port; std::string path; std::string query; + std::string fragment_; std::string username_; std::string password_; std::map query_values_; @@ -599,6 +600,7 @@ class SrsHttpUri virtual std::string get_path(); virtual std::string get_query(); virtual std::string get_query_by_key(std::string key); + virtual std::string get_fragment(); virtual std::string username(); virtual std::string password(); private: diff --git a/trunk/src/protocol/srs_protocol_utility.cpp b/trunk/src/protocol/srs_protocol_utility.cpp index c52d41b906d..74c7066a0c2 100644 --- a/trunk/src/protocol/srs_protocol_utility.cpp +++ b/trunk/src/protocol/srs_protocol_utility.cpp @@ -81,6 +81,7 @@ void srs_discovery_tc_url(string tcUrl, string& schema, string& host, string& vh port = uri.get_port(); stream = srs_path_basename(uri.get_path()); param = uri.get_query().empty() ? "" : "?" + uri.get_query(); + param += uri.get_fragment().empty() ? "" : "#" + uri.get_fragment(); // Parse app without the prefix slash. app = srs_path_dirname(uri.get_path()); diff --git a/trunk/src/utest/srs_utest_protocol.cpp b/trunk/src/utest/srs_utest_protocol.cpp index 1b15e9b2060..998fd6d7c91 100644 --- a/trunk/src/utest/srs_utest_protocol.cpp +++ b/trunk/src/utest/srs_utest_protocol.cpp @@ -3560,6 +3560,18 @@ VOID TEST(ProtocolRTMPTest, RTMPRequest) req.update_auth(&req1); EXPECT_TRUE(NULL != req.args); EXPECT_TRUE(req1.args != req.args); + + srs_discovery_tc_url("rtmp://std.ossrs.net/live?a=1#b=2", + req.schema, req.host, req.vhost, req.app, req.stream, req.port, param); + EXPECT_STREQ("?a=1#b=2", param.c_str()); + + srs_discovery_tc_url("rtmp://std.ossrs.net/live?a=1&c=3#b=2", + req.schema, req.host, req.vhost, req.app, req.stream, req.port, param); + EXPECT_STREQ("?a=1&c=3#b=2", param.c_str()); + + srs_discovery_tc_url("rtmp://std.ossrs.net/live?a=1&c=3#b=2#d=4", + req.schema, req.host, req.vhost, req.app, req.stream, req.port, param); + EXPECT_STREQ("?a=1&c=3#b=2#d=4", param.c_str()); } VOID TEST(ProtocolRTMPTest, RTMPHandshakeBytes)