mirror of
https://github.com/ossrs/srs.git
synced 2025-02-12 11:21:52 +00:00
For #1488, pass client ip to http callback.3.0.85
This commit is contained in:
commit
316cab794a
7 changed files with 56 additions and 1 deletions
|
@ -146,6 +146,7 @@ For previous versions, please read:
|
||||||
|
|
||||||
## V3 changes
|
## V3 changes
|
||||||
|
|
||||||
|
* v3.0, 2019-12-26, For [#1488][bug #1488], pass client ip to http callback. 3.0.85
|
||||||
* v3.0, 2019-12-25, For [#1537][bug #1537], [#1282][bug #1282], support aarch64 for armv8. 3.0.84
|
* v3.0, 2019-12-25, For [#1537][bug #1537], [#1282][bug #1282], support aarch64 for armv8. 3.0.84
|
||||||
* v3.0, 2019-12-25, For [#1538][bug #1538], fresh chunk allow fmt=0 or fmt=1. 3.0.83
|
* v3.0, 2019-12-25, For [#1538][bug #1538], fresh chunk allow fmt=0 or fmt=1. 3.0.83
|
||||||
* v3.0, 2019-12-25, Remove FFMPEG and NGINX, please use [srs-docker](https://github.com/ossrs/srs-docker) instead. 3.0.82
|
* v3.0, 2019-12-25, Remove FFMPEG and NGINX, please use [srs-docker](https://github.com/ossrs/srs-docker) instead. 3.0.82
|
||||||
|
@ -256,6 +257,7 @@ For previous versions, please read:
|
||||||
|
|
||||||
## V2 changes
|
## V2 changes
|
||||||
|
|
||||||
|
* v2.0, 2019-12-26, For [#1488][bug #1488], pass client ip to http callback. 2.0.269
|
||||||
* v2.0, 2019-12-23, Fix [srs-librtmp #22](https://github.com/ossrs/srs-librtmp/issues/22), parse vhost splited by single seperator. 2.0.268
|
* v2.0, 2019-12-23, Fix [srs-librtmp #22](https://github.com/ossrs/srs-librtmp/issues/22), parse vhost splited by single seperator. 2.0.268
|
||||||
* v2.0, 2019-12-23, Fix [srs-librtmp #25](https://github.com/ossrs/srs-librtmp/issues/25), build srs-librtmp on windows. 2.0.267
|
* v2.0, 2019-12-23, Fix [srs-librtmp #25](https://github.com/ossrs/srs-librtmp/issues/25), build srs-librtmp on windows. 2.0.267
|
||||||
* v2.0, 2019-12-13, Support openssl versions greater than 1.1.0. 2.0.266
|
* v2.0, 2019-12-13, Support openssl versions greater than 1.1.0. 2.0.266
|
||||||
|
|
|
@ -198,6 +198,10 @@ int SrsConnection::srs_id()
|
||||||
return trd->cid();
|
return trd->cid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string SrsConnection::remote_ip() {
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
|
||||||
void SrsConnection::expire()
|
void SrsConnection::expire()
|
||||||
{
|
{
|
||||||
trd->interrupt();
|
trd->interrupt();
|
||||||
|
|
|
@ -93,6 +93,8 @@ public:
|
||||||
public:
|
public:
|
||||||
// Get the srs id which identify the client.
|
// Get the srs id which identify the client.
|
||||||
virtual int srs_id();
|
virtual int srs_id();
|
||||||
|
// Get the remote ip of peer.
|
||||||
|
virtual std::string remote_ip();
|
||||||
// Set connection to expired.
|
// Set connection to expired.
|
||||||
virtual void expire();
|
virtual void expire();
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -49,6 +49,7 @@ using namespace std;
|
||||||
#include <srs_kernel_buffer.hpp>
|
#include <srs_kernel_buffer.hpp>
|
||||||
#include <srs_protocol_amf0.hpp>
|
#include <srs_protocol_amf0.hpp>
|
||||||
#include <srs_kernel_utility.hpp>
|
#include <srs_kernel_utility.hpp>
|
||||||
|
#include <srs_http_stack.hpp>
|
||||||
|
|
||||||
// the longest time to wait for a process to quit.
|
// the longest time to wait for a process to quit.
|
||||||
#define SRS_PROCESS_QUIT_TIMEOUT_MS 1000
|
#define SRS_PROCESS_QUIT_TIMEOUT_MS 1000
|
||||||
|
@ -1273,3 +1274,34 @@ void srs_api_dump_summaries(SrsJsonObject* obj)
|
||||||
sys->set("conn_srs", SrsJsonAny::integer(nrs->nb_conn_srs));
|
sys->set("conn_srs", SrsJsonAny::integer(nrs->nb_conn_srs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string srs_get_original_ip(ISrsHttpMessage* r)
|
||||||
|
{
|
||||||
|
string x_forwarded_for, x_real_ip;
|
||||||
|
for (int i = 0; i < r->request_header_count(); i++) {
|
||||||
|
string k = r->request_header_key_at(i);
|
||||||
|
if (k == "X-Forwarded-For") {
|
||||||
|
x_forwarded_for = r->request_header_value_at(i);
|
||||||
|
} else if (k == "X-Real-IP") {
|
||||||
|
x_real_ip = r->request_header_value_at(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!x_forwarded_for.empty()) {
|
||||||
|
size_t pos = string::npos;
|
||||||
|
if ((pos = x_forwarded_for.find(",")) == string::npos) {
|
||||||
|
return x_forwarded_for;
|
||||||
|
}
|
||||||
|
return x_forwarded_for.substr(0, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!x_real_ip.empty()) {
|
||||||
|
size_t pos = string::npos;
|
||||||
|
if ((pos = x_real_ip.find(":")) == string::npos) {
|
||||||
|
return x_real_ip;
|
||||||
|
}
|
||||||
|
return x_real_ip.substr(0, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
class SrsKbps;
|
class SrsKbps;
|
||||||
class SrsBuffer;
|
class SrsBuffer;
|
||||||
class SrsJsonObject;
|
class SrsJsonObject;
|
||||||
|
class ISrsHttpMessage;
|
||||||
|
|
||||||
// Convert level in string to log level in int.
|
// Convert level in string to log level in int.
|
||||||
// @return the log level defined in SrsLogLevel.
|
// @return the log level defined in SrsLogLevel.
|
||||||
|
@ -649,5 +650,8 @@ extern bool srs_is_boolean(const std::string& str);
|
||||||
// Dump summaries for /api/v1/summaries.
|
// Dump summaries for /api/v1/summaries.
|
||||||
extern void srs_api_dump_summaries(SrsJsonObject* obj);
|
extern void srs_api_dump_summaries(SrsJsonObject* obj);
|
||||||
|
|
||||||
|
// Get the original ip from query and header by proxy.
|
||||||
|
extern std::string srs_get_original_ip(ISrsHttpMessage* r);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
// The version config.
|
// The version config.
|
||||||
#define VERSION_MAJOR 3
|
#define VERSION_MAJOR 3
|
||||||
#define VERSION_MINOR 0
|
#define VERSION_MINOR 0
|
||||||
#define VERSION_REVISION 84
|
#define VERSION_REVISION 85
|
||||||
|
|
||||||
// The macros generated by configure script.
|
// The macros generated by configure script.
|
||||||
#include <srs_auto_headers.hpp>
|
#include <srs_auto_headers.hpp>
|
||||||
|
|
|
@ -626,6 +626,17 @@ SrsRequest* SrsHttpMessage::to_request(string vhost)
|
||||||
if (req->host == SRS_CONSTS_RTMP_DEFAULT_VHOST) {
|
if (req->host == SRS_CONSTS_RTMP_DEFAULT_VHOST) {
|
||||||
req->host = _uri->get_host();
|
req->host = _uri->get_host();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set ip by remote ip of connection.
|
||||||
|
if (conn) {
|
||||||
|
req->ip = conn->remote_ip();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overwrite by ip from proxy.
|
||||||
|
string oip = srs_get_original_ip(this);
|
||||||
|
if (!oip.empty()) {
|
||||||
|
req->ip = oip;
|
||||||
|
}
|
||||||
|
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue