mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
hook接口在http头中附带vhost:#872
This commit is contained in:
parent
7641db4225
commit
b7e6bfb574
@ -250,7 +250,7 @@ static inline string getProxyKey(const string &vhost,const string &app,const str
|
|||||||
Value makeMediaSourceJson(MediaSource &media){
|
Value makeMediaSourceJson(MediaSource &media){
|
||||||
Value item;
|
Value item;
|
||||||
item["schema"] = media.getSchema();
|
item["schema"] = media.getSchema();
|
||||||
item["vhost"] = media.getVhost();
|
item[VHOST_KEY] = media.getVhost();
|
||||||
item["app"] = media.getApp();
|
item["app"] = media.getApp();
|
||||||
item["stream"] = media.getId();
|
item["stream"] = media.getId();
|
||||||
item["createStamp"] = (Json::UInt64) media.getCreateStamp();
|
item["createStamp"] = (Json::UInt64) media.getCreateStamp();
|
||||||
|
@ -113,6 +113,17 @@ const char *getContentType(const HttpArgs &value){
|
|||||||
return "application/x-www-form-urlencoded";
|
return "application/x-www-form-urlencoded";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string getVhost(const Value &value) {
|
||||||
|
const char *key = VHOST_KEY;
|
||||||
|
auto val = value.find(key, key + sizeof(VHOST_KEY) - 1);
|
||||||
|
return val ? val->asString() : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
string getVhost(const HttpArgs &value) {
|
||||||
|
auto val = value.find(VHOST_KEY);
|
||||||
|
return val != value.end() ? val->second : "";
|
||||||
|
}
|
||||||
|
|
||||||
void do_http_hook(const string &url,const ArgsType &body,const function<void(const Value &,const string &)> &func){
|
void do_http_hook(const string &url,const ArgsType &body,const function<void(const Value &,const string &)> &func){
|
||||||
GET_CONFIG(string, mediaServerId, General::kMediaServerId);
|
GET_CONFIG(string, mediaServerId, General::kMediaServerId);
|
||||||
GET_CONFIG(float, hook_timeoutSec, Hook::kTimeoutSec);
|
GET_CONFIG(float, hook_timeoutSec, Hook::kTimeoutSec);
|
||||||
@ -123,6 +134,10 @@ void do_http_hook(const string &url,const ArgsType &body,const function<void(con
|
|||||||
auto bodyStr = to_string(body);
|
auto bodyStr = to_string(body);
|
||||||
requester->setBody(bodyStr);
|
requester->setBody(bodyStr);
|
||||||
requester->addHeader("Content-Type", getContentType(body));
|
requester->addHeader("Content-Type", getContentType(body));
|
||||||
|
auto vhost = getVhost(body);
|
||||||
|
if (!vhost.empty()) {
|
||||||
|
requester->addHeader("X-VHOST", vhost);
|
||||||
|
}
|
||||||
std::shared_ptr<Ticker> pTicker(new Ticker);
|
std::shared_ptr<Ticker> pTicker(new Ticker);
|
||||||
requester->startRequester(url, [url, func, bodyStr, requester, pTicker](const SockException &ex,
|
requester->startRequester(url, [url, func, bodyStr, requester, pTicker](const SockException &ex,
|
||||||
const string &status,
|
const string &status,
|
||||||
@ -147,7 +162,7 @@ void do_http_hook(const string &url,const ArgsType &body,const function<void(con
|
|||||||
static ArgsType make_json(const MediaInfo &args){
|
static ArgsType make_json(const MediaInfo &args){
|
||||||
ArgsType body;
|
ArgsType body;
|
||||||
body["schema"] = args._schema;
|
body["schema"] = args._schema;
|
||||||
body["vhost"] = args._vhost;
|
body[VHOST_KEY] = args._vhost;
|
||||||
body["app"] = args._app;
|
body["app"] = args._app;
|
||||||
body["stream"] = args._streamid;
|
body["stream"] = args._streamid;
|
||||||
body["params"] = args._param_strs;
|
body["params"] = args._param_strs;
|
||||||
@ -306,7 +321,7 @@ void installWebHook(){
|
|||||||
body["regist"] = bRegist;
|
body["regist"] = bRegist;
|
||||||
} else {
|
} else {
|
||||||
body["schema"] = sender.getSchema();
|
body["schema"] = sender.getSchema();
|
||||||
body["vhost"] = sender.getVhost();
|
body[VHOST_KEY] = sender.getVhost();
|
||||||
body["app"] = sender.getApp();
|
body["app"] = sender.getApp();
|
||||||
body["stream"] = sender.getId();
|
body["stream"] = sender.getId();
|
||||||
body["regist"] = bRegist;
|
body["regist"] = bRegist;
|
||||||
@ -342,7 +357,7 @@ void installWebHook(){
|
|||||||
body["url"] = info.url;
|
body["url"] = info.url;
|
||||||
body["app"] = info.app;
|
body["app"] = info.app;
|
||||||
body["stream"] = info.stream;
|
body["stream"] = info.stream;
|
||||||
body["vhost"] = info.vhost;
|
body[VHOST_KEY] = info.vhost;
|
||||||
return body;
|
return body;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -394,7 +409,7 @@ void installWebHook(){
|
|||||||
|
|
||||||
ArgsType body;
|
ArgsType body;
|
||||||
body["schema"] = sender.getSchema();
|
body["schema"] = sender.getSchema();
|
||||||
body["vhost"] = sender.getVhost();
|
body[VHOST_KEY] = sender.getVhost();
|
||||||
body["app"] = sender.getApp();
|
body["app"] = sender.getApp();
|
||||||
body["stream"] = sender.getId();
|
body["stream"] = sender.getId();
|
||||||
weak_ptr<MediaSource> weakSrc = sender.shared_from_this();
|
weak_ptr<MediaSource> weakSrc = sender.shared_from_this();
|
||||||
|
Loading…
Reference in New Issue
Block a user