mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 04:31:37 +08:00
http服务器支持OPTIONS命令
This commit is contained in:
parent
2b592780ad
commit
e90319a1f2
@ -53,20 +53,32 @@ HttpSession::~HttpSession() {
|
|||||||
TraceP(this);
|
TraceP(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HttpSession::Handle_Req_OPTIONS(int64_t &content_len){
|
||||||
|
KeyValue header;
|
||||||
|
header.emplace("Allow","GET, POST, OPTIONS");
|
||||||
|
header.emplace("Access-Control-Allow-Origin","*");
|
||||||
|
header.emplace("Access-Control-Allow-Credentials","true");
|
||||||
|
header.emplace("Access-Control-Request-Methods","GET, POST, OPTIONS");
|
||||||
|
header.emplace("Access-Control-Request-Headers","Accept,Accept-Language,Content-Language,Content-Type");
|
||||||
|
sendResponse( "200 OK" , true, nullptr,header);
|
||||||
|
}
|
||||||
|
|
||||||
int64_t HttpSession::onRecvHeader(const char *header,uint64_t len) {
|
int64_t HttpSession::onRecvHeader(const char *header,uint64_t len) {
|
||||||
typedef void (HttpSession::*HttpCMDHandle)(int64_t &);
|
typedef void (HttpSession::*HttpCMDHandle)(int64_t &);
|
||||||
static unordered_map<string, HttpCMDHandle> s_func_map;
|
static unordered_map<string, HttpCMDHandle> s_func_map;
|
||||||
static onceToken token([]() {
|
static onceToken token([]() {
|
||||||
s_func_map.emplace("GET",&HttpSession::Handle_Req_GET);
|
s_func_map.emplace("GET",&HttpSession::Handle_Req_GET);
|
||||||
s_func_map.emplace("POST",&HttpSession::Handle_Req_POST);
|
s_func_map.emplace("POST",&HttpSession::Handle_Req_POST);
|
||||||
}, nullptr);
|
s_func_map.emplace("OPTIONS",&HttpSession::Handle_Req_OPTIONS);
|
||||||
|
}, nullptr);
|
||||||
|
|
||||||
_parser.Parse(header);
|
_parser.Parse(header);
|
||||||
urlDecode(_parser);
|
urlDecode(_parser);
|
||||||
string cmd = _parser.Method();
|
string cmd = _parser.Method();
|
||||||
auto it = s_func_map.find(cmd);
|
auto it = s_func_map.find(cmd);
|
||||||
if (it == s_func_map.end()) {
|
if (it == s_func_map.end()) {
|
||||||
sendResponse("403 Forbidden", true);
|
WarnL << "不支持该命令:" << cmd;
|
||||||
|
sendResponse("405 Not Allowed", true);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,9 @@ protected:
|
|||||||
private:
|
private:
|
||||||
void Handle_Req_GET(int64_t &content_len);
|
void Handle_Req_GET(int64_t &content_len);
|
||||||
void Handle_Req_POST(int64_t &content_len);
|
void Handle_Req_POST(int64_t &content_len);
|
||||||
bool checkLiveFlvStream(const function<void()> &cb = nullptr);
|
void Handle_Req_OPTIONS(int64_t &content_len);
|
||||||
|
|
||||||
|
bool checkLiveFlvStream(const function<void()> &cb = nullptr);
|
||||||
bool checkWebSocket();
|
bool checkWebSocket();
|
||||||
bool emitHttpEvent(bool doInvoke);
|
bool emitHttpEvent(bool doInvoke);
|
||||||
void urlDecode(Parser &parser);
|
void urlDecode(Parser &parser);
|
||||||
|
Loading…
Reference in New Issue
Block a user