mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
For #1488, add test and improve coverage for parsing client ip.
This commit is contained in:
parent
316cab794a
commit
2115d5d22a
8 changed files with 88 additions and 44 deletions
|
@ -33,6 +33,7 @@ using namespace std;
|
|||
#include <srs_kernel_file.hpp>
|
||||
#include <srs_utest_kernel.hpp>
|
||||
#include <srs_app_http_static.hpp>
|
||||
#include <srs_service_utility.hpp>
|
||||
|
||||
class MockMSegmentsReader : public ISrsReader
|
||||
{
|
||||
|
@ -1677,3 +1678,45 @@ VOID TEST(ProtocolHTTPTest, HTTPMessageUpdate)
|
|||
EXPECT_EQ(-1, m.content_length());
|
||||
}
|
||||
}
|
||||
|
||||
VOID TEST(ProtocolHTTPTest, GetOriginalIP)
|
||||
{
|
||||
if (true) {
|
||||
SrsHttpHeader h;
|
||||
h.set("X-Forwarded-For", "10.11.12.13");
|
||||
|
||||
SrsHttpMessage m;
|
||||
m.set_header(&h, false);
|
||||
|
||||
EXPECT_STREQ("10.11.12.13", srs_get_original_ip(&m).c_str());
|
||||
}
|
||||
|
||||
if (true) {
|
||||
SrsHttpHeader h;
|
||||
h.set("X-Forwarded-For", "192.193.194.195,10.11.12.13");
|
||||
|
||||
SrsHttpMessage m;
|
||||
m.set_header(&h, false);
|
||||
|
||||
EXPECT_STREQ("192.193.194.195", srs_get_original_ip(&m).c_str());
|
||||
}
|
||||
|
||||
if (true) {
|
||||
SrsHttpHeader h;
|
||||
h.set("X-Real-IP", "172.14.42.78");
|
||||
|
||||
SrsHttpMessage m;
|
||||
m.set_header(&h, false);
|
||||
|
||||
EXPECT_STREQ("172.14.42.78", srs_get_original_ip(&m).c_str());
|
||||
}
|
||||
|
||||
if (true) {
|
||||
SrsHttpHeader h;
|
||||
|
||||
SrsHttpMessage m;
|
||||
m.set_header(&h, false);
|
||||
|
||||
EXPECT_STREQ("", srs_get_original_ip(&m).c_str());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue