diff --git a/trunk/src/service/srs_service_http_conn.cpp b/trunk/src/service/srs_service_http_conn.cpp index 2cc6196b4..3d8d1df06 100644 --- a/trunk/src/service/srs_service_http_conn.cpp +++ b/trunk/src/service/srs_service_http_conn.cpp @@ -460,6 +460,11 @@ string SrsHttpMessage::host() return _uri->get_host(); } +int SrsHttpMessage::port() +{ + return _uri->get_port(); +} + string SrsHttpMessage::path() { return _uri->get_path(); diff --git a/trunk/src/service/srs_service_http_conn.hpp b/trunk/src/service/srs_service_http_conn.hpp index cdd9524cf..997e26b66 100644 --- a/trunk/src/service/srs_service_http_conn.hpp +++ b/trunk/src/service/srs_service_http_conn.hpp @@ -163,6 +163,7 @@ public: // The url maybe the path. virtual std::string url(); virtual std::string host(); + virtual int port(); virtual std::string path(); virtual std::string query(); virtual std::string ext(); diff --git a/trunk/src/utest/srs_utest_http.cpp b/trunk/src/utest/srs_utest_http.cpp index bdcbe58d1..c1c10ffea 100644 --- a/trunk/src/utest/srs_utest_http.cpp +++ b/trunk/src/utest/srs_utest_http.cpp @@ -1265,6 +1265,39 @@ VOID TEST(ProtocolHTTPTest, HTTPMessageParser) VOID TEST(ProtocolHTTPTest, HTTPMessageUpdate) { + // Port use 80 if error. + if (true) { + SrsHttpHeader h; + h.set("Host", "ossrs.net:-1"); + + SrsHttpMessage m; + m.set_header(&h, false); + m.set_url("/api/v1", false); + EXPECT_EQ(80, m.port()); + } + + // Port default to 80. + if (true) { + SrsHttpHeader h; + h.set("Host", "ossrs.net"); + + SrsHttpMessage m; + m.set_header(&h, false); + m.set_url("/api/v1", false); + EXPECT_EQ(80, m.port()); + } + + // For port not 80. + if (true) { + SrsHttpHeader h; + h.set("Host", "ossrs.net:8080"); + + SrsHttpMessage m; + m.set_header(&h, false); + m.set_url("/api/v1", false); + EXPECT_EQ(8080, m.port()); + } + // The host is overwrite by header. if (true) { SrsHttpHeader h;