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

Improve test coverage for http message

This commit is contained in:
winlin 2019-12-17 21:08:18 +08:00
parent 43a5cea158
commit 6c50d85671
3 changed files with 39 additions and 0 deletions

View file

@ -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();

View file

@ -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();

View file

@ -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;