mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
refie http consts.
This commit is contained in:
parent
573952e2fc
commit
c46b3bd193
4 changed files with 106 additions and 99 deletions
|
@ -41,6 +41,13 @@ using namespace std;
|
||||||
|
|
||||||
#define SRS_HTTP_HEADER_BUFFER 1024
|
#define SRS_HTTP_HEADER_BUFFER 1024
|
||||||
|
|
||||||
|
// for http parser macros
|
||||||
|
#define SRS_CONSTS_HTTP_OPTIONS HTTP_OPTIONS
|
||||||
|
#define SRS_CONSTS_HTTP_GET HTTP_GET
|
||||||
|
#define SRS_CONSTS_HTTP_POST HTTP_POST
|
||||||
|
#define SRS_CONSTS_HTTP_PUT HTTP_PUT
|
||||||
|
#define SRS_CONSTS_HTTP_DELETE HTTP_DELETE
|
||||||
|
|
||||||
bool srs_path_equals(const char* expect, const char* path, int nb_path)
|
bool srs_path_equals(const char* expect, const char* path, int nb_path)
|
||||||
{
|
{
|
||||||
int size = strlen(expect);
|
int size = strlen(expect);
|
||||||
|
@ -92,7 +99,7 @@ bool SrsHttpHandler::can_handle(const char* /*path*/, int /*length*/, const char
|
||||||
|
|
||||||
int SrsHttpHandler::process_request(SrsSocket* skt, SrsHttpMessage* req)
|
int SrsHttpHandler::process_request(SrsSocket* skt, SrsHttpMessage* req)
|
||||||
{
|
{
|
||||||
if (req->method() == HTTP_OPTIONS) {
|
if (req->method() == SRS_CONSTS_HTTP_OPTIONS) {
|
||||||
req->set_requires_crossdomain(true);
|
req->set_requires_crossdomain(true);
|
||||||
return res_options(skt);
|
return res_options(skt);
|
||||||
}
|
}
|
||||||
|
@ -120,8 +127,8 @@ int SrsHttpHandler::process_request(SrsSocket* skt, SrsHttpMessage* req)
|
||||||
bool SrsHttpHandler::is_handler_valid(SrsHttpMessage* req, int& status_code, string& reason_phrase)
|
bool SrsHttpHandler::is_handler_valid(SrsHttpMessage* req, int& status_code, string& reason_phrase)
|
||||||
{
|
{
|
||||||
if (!req->match()->unmatched_url.empty()) {
|
if (!req->match()->unmatched_url.empty()) {
|
||||||
status_code = HTTP_NotFound;
|
status_code = SRS_CONSTS_HTTP_NotFound;
|
||||||
reason_phrase = HTTP_NotFound_str;
|
reason_phrase = SRS_CONSTS_HTTP_NotFound_str;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -534,7 +541,7 @@ SrsHttpMessage::SrsHttpMessage()
|
||||||
_uri = new SrsHttpUri();
|
_uri = new SrsHttpUri();
|
||||||
_match = NULL;
|
_match = NULL;
|
||||||
_requires_crossdomain = false;
|
_requires_crossdomain = false;
|
||||||
_http_ts_send_buffer = new char[HTTP_TS_SEND_BUFFER_SIZE];
|
_http_ts_send_buffer = new char[SRS_CONSTS_HTTP_TS_SEND_BUFFER_SIZE];
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsHttpMessage::~SrsHttpMessage()
|
SrsHttpMessage::~SrsHttpMessage()
|
||||||
|
@ -608,27 +615,27 @@ string SrsHttpMessage::method_str()
|
||||||
|
|
||||||
bool SrsHttpMessage::is_http_get()
|
bool SrsHttpMessage::is_http_get()
|
||||||
{
|
{
|
||||||
return _header.method == HTTP_GET;
|
return _header.method == SRS_CONSTS_HTTP_GET;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsHttpMessage::is_http_put()
|
bool SrsHttpMessage::is_http_put()
|
||||||
{
|
{
|
||||||
return _header.method == HTTP_PUT;
|
return _header.method == SRS_CONSTS_HTTP_PUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsHttpMessage::is_http_post()
|
bool SrsHttpMessage::is_http_post()
|
||||||
{
|
{
|
||||||
return _header.method == HTTP_POST;
|
return _header.method == SRS_CONSTS_HTTP_POST;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsHttpMessage::is_http_delete()
|
bool SrsHttpMessage::is_http_delete()
|
||||||
{
|
{
|
||||||
return _header.method == HTTP_DELETE;
|
return _header.method == SRS_CONSTS_HTTP_DELETE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsHttpMessage::is_http_options()
|
bool SrsHttpMessage::is_http_options()
|
||||||
{
|
{
|
||||||
return _header.method == HTTP_OPTIONS;
|
return _header.method == SRS_CONSTS_HTTP_OPTIONS;
|
||||||
}
|
}
|
||||||
|
|
||||||
string SrsHttpMessage::uri()
|
string SrsHttpMessage::uri()
|
||||||
|
|
|
@ -63,90 +63,90 @@ class SrsHttpHandler;
|
||||||
#define __SRS_CRLFCRLF "\r\n\r\n" // 0x0D0A0D0A
|
#define __SRS_CRLFCRLF "\r\n\r\n" // 0x0D0A0D0A
|
||||||
|
|
||||||
// 6.1.1 Status Code and Reason Phrase
|
// 6.1.1 Status Code and Reason Phrase
|
||||||
#define HTTP_Continue 100
|
#define SRS_CONSTS_HTTP_Continue 100
|
||||||
#define HTTP_SwitchingProtocols 101
|
#define SRS_CONSTS_HTTP_SwitchingProtocols 101
|
||||||
#define HTTP_OK 200
|
#define SRS_CONSTS_HTTP_OK 200
|
||||||
#define HTTP_Created 201
|
#define SRS_CONSTS_HTTP_Created 201
|
||||||
#define HTTP_Accepted 202
|
#define SRS_CONSTS_HTTP_Accepted 202
|
||||||
#define HTTP_NonAuthoritativeInformation 203
|
#define SRS_CONSTS_HTTP_NonAuthoritativeInformation 203
|
||||||
#define HTTP_NoContent 204
|
#define SRS_CONSTS_HTTP_NoContent 204
|
||||||
#define HTTP_ResetContent 205
|
#define SRS_CONSTS_HTTP_ResetContent 205
|
||||||
#define HTTP_PartialContent 206
|
#define SRS_CONSTS_HTTP_PartialContent 206
|
||||||
#define HTTP_MultipleChoices 300
|
#define SRS_CONSTS_HTTP_MultipleChoices 300
|
||||||
#define HTTP_MovedPermanently 301
|
#define SRS_CONSTS_HTTP_MovedPermanently 301
|
||||||
#define HTTP_Found 302
|
#define SRS_CONSTS_HTTP_Found 302
|
||||||
#define HTTP_SeeOther 303
|
#define SRS_CONSTS_HTTP_SeeOther 303
|
||||||
#define HTTP_NotModified 304
|
#define SRS_CONSTS_HTTP_NotModified 304
|
||||||
#define HTTP_UseProxy 305
|
#define SRS_CONSTS_HTTP_UseProxy 305
|
||||||
#define HTTP_TemporaryRedirect 307
|
#define SRS_CONSTS_HTTP_TemporaryRedirect 307
|
||||||
#define HTTP_BadRequest 400
|
#define SRS_CONSTS_HTTP_BadRequest 400
|
||||||
#define HTTP_Unauthorized 401
|
#define SRS_CONSTS_HTTP_Unauthorized 401
|
||||||
#define HTTP_PaymentRequired 402
|
#define SRS_CONSTS_HTTP_PaymentRequired 402
|
||||||
#define HTTP_Forbidden 403
|
#define SRS_CONSTS_HTTP_Forbidden 403
|
||||||
#define HTTP_NotFound 404
|
#define SRS_CONSTS_HTTP_NotFound 404
|
||||||
#define HTTP_MethodNotAllowed 405
|
#define SRS_CONSTS_HTTP_MethodNotAllowed 405
|
||||||
#define HTTP_NotAcceptable 406
|
#define SRS_CONSTS_HTTP_NotAcceptable 406
|
||||||
#define HTTP_ProxyAuthenticationRequired 407
|
#define SRS_CONSTS_HTTP_ProxyAuthenticationRequired 407
|
||||||
#define HTTP_RequestTimeout 408
|
#define SRS_CONSTS_HTTP_RequestTimeout 408
|
||||||
#define HTTP_Conflict 409
|
#define SRS_CONSTS_HTTP_Conflict 409
|
||||||
#define HTTP_Gone 410
|
#define SRS_CONSTS_HTTP_Gone 410
|
||||||
#define HTTP_LengthRequired 411
|
#define SRS_CONSTS_HTTP_LengthRequired 411
|
||||||
#define HTTP_PreconditionFailed 412
|
#define SRS_CONSTS_HTTP_PreconditionFailed 412
|
||||||
#define HTTP_RequestEntityTooLarge 413
|
#define SRS_CONSTS_HTTP_RequestEntityTooLarge 413
|
||||||
#define HTTP_RequestURITooLarge 414
|
#define SRS_CONSTS_HTTP_RequestURITooLarge 414
|
||||||
#define HTTP_UnsupportedMediaType 415
|
#define SRS_CONSTS_HTTP_UnsupportedMediaType 415
|
||||||
#define HTTP_RequestedRangeNotSatisfiable 416
|
#define SRS_CONSTS_HTTP_RequestedRangeNotSatisfiable 416
|
||||||
#define HTTP_ExpectationFailed 417
|
#define SRS_CONSTS_HTTP_ExpectationFailed 417
|
||||||
#define HTTP_InternalServerError 500
|
#define SRS_CONSTS_HTTP_InternalServerError 500
|
||||||
#define HTTP_NotImplemented 501
|
#define SRS_CONSTS_HTTP_NotImplemented 501
|
||||||
#define HTTP_BadGateway 502
|
#define SRS_CONSTS_HTTP_BadGateway 502
|
||||||
#define HTTP_ServiceUnavailable 503
|
#define SRS_CONSTS_HTTP_ServiceUnavailable 503
|
||||||
#define HTTP_GatewayTimeout 504
|
#define SRS_CONSTS_HTTP_GatewayTimeout 504
|
||||||
#define HTTP_HTTPVersionNotSupported 505
|
#define SRS_CONSTS_HTTP_HTTPVersionNotSupported 505
|
||||||
|
|
||||||
#define HTTP_Continue_str "Continue"
|
#define SRS_CONSTS_HTTP_Continue_str "Continue"
|
||||||
#define HTTP_SwitchingProtocols_str "Switching Protocols"
|
#define SRS_CONSTS_HTTP_SwitchingProtocols_str "Switching Protocols"
|
||||||
#define HTTP_OK_str "OK"
|
#define SRS_CONSTS_HTTP_OK_str "OK"
|
||||||
#define HTTP_Created_str "Created "
|
#define SRS_CONSTS_HTTP_Created_str "Created "
|
||||||
#define HTTP_Accepted_str "Accepted"
|
#define SRS_CONSTS_HTTP_Accepted_str "Accepted"
|
||||||
#define HTTP_NonAuthoritativeInformation_str "Non Authoritative Information "
|
#define SRS_CONSTS_HTTP_NonAuthoritativeInformation_str "Non Authoritative Information "
|
||||||
#define HTTP_NoContent_str "No Content "
|
#define SRS_CONSTS_HTTP_NoContent_str "No Content "
|
||||||
#define HTTP_ResetContent_str "Reset Content"
|
#define SRS_CONSTS_HTTP_ResetContent_str "Reset Content"
|
||||||
#define HTTP_PartialContent_str "Partial Content"
|
#define SRS_CONSTS_HTTP_PartialContent_str "Partial Content"
|
||||||
#define HTTP_MultipleChoices_str "Multiple Choices "
|
#define SRS_CONSTS_HTTP_MultipleChoices_str "Multiple Choices "
|
||||||
#define HTTP_MovedPermanently_str "Moved Permanently"
|
#define SRS_CONSTS_HTTP_MovedPermanently_str "Moved Permanently"
|
||||||
#define HTTP_Found_str "Found"
|
#define SRS_CONSTS_HTTP_Found_str "Found"
|
||||||
#define HTTP_SeeOther_str "See Other"
|
#define SRS_CONSTS_HTTP_SeeOther_str "See Other"
|
||||||
#define HTTP_NotModified_str "Not Modified "
|
#define SRS_CONSTS_HTTP_NotModified_str "Not Modified "
|
||||||
#define HTTP_UseProxy_str "Use Proxy"
|
#define SRS_CONSTS_HTTP_UseProxy_str "Use Proxy"
|
||||||
#define HTTP_TemporaryRedirect_str "Temporary Redirect "
|
#define SRS_CONSTS_HTTP_TemporaryRedirect_str "Temporary Redirect "
|
||||||
#define HTTP_BadRequest_str "Bad Request"
|
#define SRS_CONSTS_HTTP_BadRequest_str "Bad Request"
|
||||||
#define HTTP_Unauthorized_str "Unauthorized"
|
#define SRS_CONSTS_HTTP_Unauthorized_str "Unauthorized"
|
||||||
#define HTTP_PaymentRequired_str "Payment Required "
|
#define SRS_CONSTS_HTTP_PaymentRequired_str "Payment Required "
|
||||||
#define HTTP_Forbidden_str "Forbidden "
|
#define SRS_CONSTS_HTTP_Forbidden_str "Forbidden "
|
||||||
#define HTTP_NotFound_str "Not Found"
|
#define SRS_CONSTS_HTTP_NotFound_str "Not Found"
|
||||||
#define HTTP_MethodNotAllowed_str "Method Not Allowed"
|
#define SRS_CONSTS_HTTP_MethodNotAllowed_str "Method Not Allowed"
|
||||||
#define HTTP_NotAcceptable_str "Not Acceptable "
|
#define SRS_CONSTS_HTTP_NotAcceptable_str "Not Acceptable "
|
||||||
#define HTTP_ProxyAuthenticationRequired_str "Proxy Authentication Required "
|
#define SRS_CONSTS_HTTP_ProxyAuthenticationRequired_str "Proxy Authentication Required "
|
||||||
#define HTTP_RequestTimeout_str "Request Timeout"
|
#define SRS_CONSTS_HTTP_RequestTimeout_str "Request Timeout"
|
||||||
#define HTTP_Conflict_str "Conflict"
|
#define SRS_CONSTS_HTTP_Conflict_str "Conflict"
|
||||||
#define HTTP_Gone_str "Gone"
|
#define SRS_CONSTS_HTTP_Gone_str "Gone"
|
||||||
#define HTTP_LengthRequired_str "Length Required"
|
#define SRS_CONSTS_HTTP_LengthRequired_str "Length Required"
|
||||||
#define HTTP_PreconditionFailed_str "Precondition Failed"
|
#define SRS_CONSTS_HTTP_PreconditionFailed_str "Precondition Failed"
|
||||||
#define HTTP_RequestEntityTooLarge_str "Request Entity Too Large "
|
#define SRS_CONSTS_HTTP_RequestEntityTooLarge_str "Request Entity Too Large "
|
||||||
#define HTTP_RequestURITooLarge_str "Request URI Too Large"
|
#define SRS_CONSTS_HTTP_RequestURITooLarge_str "Request URI Too Large"
|
||||||
#define HTTP_UnsupportedMediaType_str "Unsupported Media Type"
|
#define SRS_CONSTS_HTTP_UnsupportedMediaType_str "Unsupported Media Type"
|
||||||
#define HTTP_RequestedRangeNotSatisfiable_str "Requested Range Not Satisfiable"
|
#define SRS_CONSTS_HTTP_RequestedRangeNotSatisfiable_str "Requested Range Not Satisfiable"
|
||||||
#define HTTP_ExpectationFailed_str "Expectation Failed "
|
#define SRS_CONSTS_HTTP_ExpectationFailed_str "Expectation Failed "
|
||||||
#define HTTP_InternalServerError_str "Internal Server Error "
|
#define SRS_CONSTS_HTTP_InternalServerError_str "Internal Server Error "
|
||||||
#define HTTP_NotImplemented_str "Not Implemented"
|
#define SRS_CONSTS_HTTP_NotImplemented_str "Not Implemented"
|
||||||
#define HTTP_BadGateway_str "Bad Gateway"
|
#define SRS_CONSTS_HTTP_BadGateway_str "Bad Gateway"
|
||||||
#define HTTP_ServiceUnavailable_str "Service Unavailable"
|
#define SRS_CONSTS_HTTP_ServiceUnavailable_str "Service Unavailable"
|
||||||
#define HTTP_GatewayTimeout_str "Gateway Timeout"
|
#define SRS_CONSTS_HTTP_GatewayTimeout_str "Gateway Timeout"
|
||||||
#define HTTP_HTTPVersionNotSupported_str "HTTP Version Not Supported"
|
#define SRS_CONSTS_HTTP_HTTPVersionNotSupported_str "HTTP Version Not Supported"
|
||||||
|
|
||||||
// @see SrsHttpMessage._http_ts_send_buffer
|
// @see SrsHttpMessage._http_ts_send_buffer
|
||||||
#define HTTP_TS_SEND_BUFFER_SIZE 4096
|
#define SRS_CONSTS_HTTP_TS_SEND_BUFFER_SIZE 4096
|
||||||
|
|
||||||
// linux path seprator
|
// linux path seprator
|
||||||
#define __PATH_SEP '/'
|
#define __PATH_SEP '/'
|
||||||
|
|
|
@ -54,8 +54,8 @@ bool SrsApiRoot::is_handler_valid(SrsHttpMessage* req, int& status_code, std::st
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req->match()->matched_url.length() != 1) {
|
if (req->match()->matched_url.length() != 1) {
|
||||||
status_code = HTTP_NotFound;
|
status_code = SRS_CONSTS_HTTP_NotFound;
|
||||||
reason_phrase = HTTP_NotFound_str;
|
reason_phrase = SRS_CONSTS_HTTP_NotFound_str;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,8 +118,8 @@ int SrsHttpRoot::best_match(const char* path, int length, SrsHttpHandlerMatch**
|
||||||
|
|
||||||
bool SrsHttpRoot::is_handler_valid(SrsHttpMessage* req, int& status_code, std::string& reason_phrase)
|
bool SrsHttpRoot::is_handler_valid(SrsHttpMessage* req, int& status_code, std::string& reason_phrase)
|
||||||
{
|
{
|
||||||
status_code = HTTP_InternalServerError;
|
status_code = SRS_CONSTS_HTTP_InternalServerError;
|
||||||
reason_phrase = HTTP_InternalServerError_str;
|
reason_phrase = SRS_CONSTS_HTTP_InternalServerError_str;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -153,8 +153,8 @@ bool SrsHttpVhost::is_handler_valid(SrsHttpMessage* req, int& status_code, std::
|
||||||
if (::access(fullpath.c_str(), F_OK | R_OK) < 0) {
|
if (::access(fullpath.c_str(), F_OK | R_OK) < 0) {
|
||||||
srs_warn("check file %s does not exists", fullpath.c_str());
|
srs_warn("check file %s does not exists", fullpath.c_str());
|
||||||
|
|
||||||
status_code = HTTP_NotFound;
|
status_code = SRS_CONSTS_HTTP_NotFound;
|
||||||
reason_phrase = HTTP_NotFound_str;
|
reason_phrase = SRS_CONSTS_HTTP_NotFound_str;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ int SrsHttpVhost::response_flv_file(SrsSocket* skt, SrsHttpMessage* req, string
|
||||||
|
|
||||||
while (left > 0) {
|
while (left > 0) {
|
||||||
ssize_t nread = -1;
|
ssize_t nread = -1;
|
||||||
if ((ret = fs.read(buf, HTTP_TS_SEND_BUFFER_SIZE, &nread)) != ERROR_SUCCESS) {
|
if ((ret = fs.read(buf, SRS_CONSTS_HTTP_TS_SEND_BUFFER_SIZE, &nread)) != ERROR_SUCCESS) {
|
||||||
srs_warn("read file %s failed, ret=%d", fullpath.c_str(), ret);
|
srs_warn("read file %s failed, ret=%d", fullpath.c_str(), ret);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -377,7 +377,7 @@ int SrsHttpVhost::response_flv_file2(SrsSocket* skt, SrsHttpMessage* req, string
|
||||||
// send data
|
// send data
|
||||||
while (left > 0) {
|
while (left > 0) {
|
||||||
ssize_t nread = -1;
|
ssize_t nread = -1;
|
||||||
if ((ret = fs.read(buf, HTTP_TS_SEND_BUFFER_SIZE, &nread)) != ERROR_SUCCESS) {
|
if ((ret = fs.read(buf, SRS_CONSTS_HTTP_TS_SEND_BUFFER_SIZE, &nread)) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,7 +427,7 @@ int SrsHttpVhost::response_ts_file(SrsSocket* skt, SrsHttpMessage* req, string f
|
||||||
|
|
||||||
while (left > 0) {
|
while (left > 0) {
|
||||||
ssize_t nread = -1;
|
ssize_t nread = -1;
|
||||||
if ((ret = fs.read(buf, HTTP_TS_SEND_BUFFER_SIZE, &nread)) != ERROR_SUCCESS) {
|
if ((ret = fs.read(buf, SRS_CONSTS_HTTP_TS_SEND_BUFFER_SIZE, &nread)) != ERROR_SUCCESS) {
|
||||||
srs_warn("read file %s failed, ret=%d", fullpath.c_str(), ret);
|
srs_warn("read file %s failed, ret=%d", fullpath.c_str(), ret);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue