-
Notifications
You must be signed in to change notification settings - Fork 3
srs_redirect_hack
Alexander Tumin edited this page Jul 25, 2015
·
1 revision
diff --git a/trunk/src/app/srs_app_http_hooks.cpp b/trunk/src/app/srs_app_http_hooks.cpp
index 426b331..e534571 100644
--- a/trunk/src/app/srs_app_http_hooks.cpp
+++ b/trunk/src/app/srs_app_http_hooks.cpp
@@ -144,10 +144,16 @@ int SrsHttpHooks::on_publish(string url, SrsRequest* req)
std::string res;
int status_code;
if ((ret = do_post(url, data, status_code, res)) != ERROR_SUCCESS) {
- srs_error("http post on_publish uri failed. "
- "client_id=%d, url=%s, request=%s, response=%s, code=%d, ret=%d",
- client_id, url.c_str(), data.c_str(), res.c_str(), status_code, ret);
- return ret;
+ printf("%d\n", status_code);
+ if (status_code == 302) {
+ req->mock = res;
+ ret = ERROR_SUCCESS;
+ } else {
+ srs_error("http post on_publish uri failed. "
+ "client_id=%d, url=%s, request=%s, response=%s, code=%d, ret=%d",
+ client_id, url.c_str(), data.c_str(), res.c_str(), status_code, ret);
+ return ret;
+ }
}
srs_trace("http hook on_publish success. "
@@ -427,10 +433,18 @@ int SrsHttpHooks::do_post(std::string url, std::string req, int& code, string& r
if ((ret = msg->body_read_all(res)) != ERROR_SUCCESS) {
return ret;
}
-
+
// ensure the http status is ok.
// https://github.com/simple-rtmp-server/srs/issues/158
- if (code != SRS_CONSTS_HTTP_OK) {
+ if (code == 302) {
+ for (int i = 0; i < msg->request_header_count(); i++) {
+ if (msg->request_header_key_at(i) == "Location") {
+ res = msg->request_header_value_at(i);
+ break;
+ }
+ }
+ return ret;
+ } else if (code != SRS_CONSTS_HTTP_OK) {
return ERROR_HTTP_STATUS_INVLIAD;
}
diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp
index 1c38fba..7a6c1fd 100755
--- a/trunk/src/app/srs_app_source.cpp
+++ b/trunk/src/app/srs_app_source.cpp
@@ -724,6 +724,7 @@ int SrsSource::create(SrsRequest* r, ISrsSourceHandler* h, ISrsHlsHandler* hh, S
int ret = ERROR_SUCCESS;
string stream_url = r->get_stream_url();
+ string stream_mock = r->get_stream_mock();
string vhost = r->vhost;
// should always not exists for create a source.
@@ -736,6 +737,7 @@ int SrsSource::create(SrsRequest* r, ISrsSourceHandler* h, ISrsHlsHandler* hh, S
}
pool[stream_url] = source;
srs_info("create new source for url=%s, vhost=%s", stream_url.c_str(), vhost.c_str());
*pps = source;
@@ -748,11 +750,18 @@ SrsSource* SrsSource::fetch(SrsRequest* r)
SrsSource* source = NULL;
string stream_url = r->get_stream_url();
- if (pool.find(stream_url) == pool.end()) {
+ string stream_mock = r->get_stream_mock();
+
+ if (pool.find(stream_mock) != pool.end()) {
+ source = pool[stream_mock];
+ } else if (pool.find(stream_url) != pool.end()) {
+ source = pool[stream_url];
+ }
+
+ if (source == NULL) {
return NULL;
}
- source = pool[stream_url];
// we always update the request of resource,
// for origin auth is on, the token in request maybe invalid,
diff --git a/trunk/src/protocol/srs_rtmp_stack.cpp b/trunk/src/protocol/srs_rtmp_stack.cpp
index d365899..2ac7223 100644
--- a/trunk/src/protocol/srs_rtmp_stack.cpp
+++ b/trunk/src/protocol/srs_rtmp_stack.cpp
@@ -1717,6 +1717,11 @@ string SrsRequest::get_stream_url()
return srs_generate_stream_url(vhost, app, stream);
}
+string SrsRequest::get_stream_mock()
+{
+ return srs_generate_stream_url(vhost, app, mock);
+}
+
void SrsRequest::strip()
{
// remove the unsupported chars in names.
diff --git a/trunk/src/protocol/srs_rtmp_stack.hpp b/trunk/src/protocol/srs_rtmp_stack.hpp
index db6d76f..1ff8255 100644
--- a/trunk/src/protocol/srs_rtmp_stack.hpp
+++ b/trunk/src/protocol/srs_rtmp_stack.hpp
@@ -560,6 +560,7 @@ public:
// the param in tcUrl(app).
std::string param;
// the stream in play/publish
+ std::string mock;
std::string stream;
// for play live stream,
// used to specified the stop when exceed the duration.
@@ -590,6 +591,7 @@ public:
* get the stream identify, vhost/app/stream.
*/
virtual std::string get_stream_url();
+ virtual std::string get_stream_mock();
/**
* strip url, user must strip when update the url.
*/