1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

refine macros of HTTP

This commit is contained in:
winlin 2014-07-20 13:33:21 +08:00
parent 198a7f1e9d
commit 573952e2fc
15 changed files with 97 additions and 88 deletions

View file

@ -170,7 +170,7 @@ int SrsEdgeIngester::ingest()
client->set_recv_timeout(SRS_EDGE_INGESTER_TIMEOUT_US);
SrsPithyPrint pithy_print(SRS_STAGE_EDGE);
SrsPithyPrint pithy_print(SRS_CONSTS_STAGE_EDGE);
while (pthread->can_loop()) {
// switch to other st-threads.
@ -413,7 +413,7 @@ int SrsEdgeForwarder::cycle()
client->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);
SrsPithyPrint pithy_print(SRS_STAGE_EDGE);
SrsPithyPrint pithy_print(SRS_CONSTS_STAGE_EDGE);
SrsSharedPtrMessageArray msgs(SYS_MAX_EDGE_SEND_MSGS);

View file

@ -47,7 +47,7 @@ static std::vector<std::string> _transcoded_url;
SrsEncoder::SrsEncoder()
{
pthread = new SrsThread(this, SRS_RTMP_ENCODER_SLEEP_US, true);
pithy_print = new SrsPithyPrint(SRS_STAGE_ENCODER);
pithy_print = new SrsPithyPrint(SRS_CONSTS_STAGE_ENCODER);
}
SrsEncoder::~SrsEncoder()

View file

@ -284,7 +284,7 @@ int SrsForwarder::forward()
client->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);
SrsPithyPrint pithy_print(SRS_STAGE_FORWARDER);
SrsPithyPrint pithy_print(SRS_CONSTS_STAGE_FORWARDER);
SrsSharedPtrMessageArray msgs(SYS_MAX_FORWARD_SEND_MSGS);

View file

@ -1342,7 +1342,7 @@ SrsHls::SrsHls(SrsSource* _source)
muxer = new SrsHlsMuxer();
hls_cache = new SrsHlsCache();
pithy_print = new SrsPithyPrint(SRS_STAGE_HLS);
pithy_print = new SrsPithyPrint(SRS_CONSTS_STAGE_HLS);
stream_dts = 0;
}

View file

@ -217,107 +217,107 @@ int SrsHttpHandler::best_match(const char* path, int length, SrsHttpHandlerMatch
SrsHttpHandler* SrsHttpHandler::res_status_line(stringstream& ss)
{
ss << "HTTP/1.1 200 OK " << __CRLF
<< "Server: "RTMP_SIG_SRS_KEY"/"RTMP_SIG_SRS_VERSION"" << __CRLF;
ss << "HTTP/1.1 200 OK " << __SRS_CRLF
<< "Server: "RTMP_SIG_SRS_KEY"/"RTMP_SIG_SRS_VERSION"" << __SRS_CRLF;
return this;
}
SrsHttpHandler* SrsHttpHandler::res_status_line_error(stringstream& ss, int code, string reason_phrase)
{
ss << "HTTP/1.1 " << code << " " << reason_phrase << __CRLF
<< "Server: SRS/"RTMP_SIG_SRS_VERSION"" << __CRLF;
ss << "HTTP/1.1 " << code << " " << reason_phrase << __SRS_CRLF
<< "Server: SRS/"RTMP_SIG_SRS_VERSION"" << __SRS_CRLF;
return this;
}
SrsHttpHandler* SrsHttpHandler::res_content_type(stringstream& ss)
{
ss << "Content-Type: text/html;charset=utf-8" << __CRLF
<< "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __CRLF;
ss << "Content-Type: text/html;charset=utf-8" << __SRS_CRLF
<< "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __SRS_CRLF;
return this;
}
SrsHttpHandler* SrsHttpHandler::res_content_type_xml(stringstream& ss)
{
ss << "Content-Type: text/xml;charset=utf-8" << __CRLF
<< "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __CRLF;
ss << "Content-Type: text/xml;charset=utf-8" << __SRS_CRLF
<< "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __SRS_CRLF;
return this;
}
SrsHttpHandler* SrsHttpHandler::res_content_type_javascript(stringstream& ss)
{
ss << "Content-Type: text/javascript" << __CRLF
<< "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __CRLF;
ss << "Content-Type: text/javascript" << __SRS_CRLF
<< "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __SRS_CRLF;
return this;
}
SrsHttpHandler* SrsHttpHandler::res_content_type_swf(stringstream& ss)
{
ss << "Content-Type: application/x-shockwave-flash" << __CRLF
<< "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __CRLF;
ss << "Content-Type: application/x-shockwave-flash" << __SRS_CRLF
<< "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __SRS_CRLF;
return this;
}
SrsHttpHandler* SrsHttpHandler::res_content_type_css(stringstream& ss)
{
ss << "Content-Type: text/css;charset=utf-8" << __CRLF
<< "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __CRLF;
ss << "Content-Type: text/css;charset=utf-8" << __SRS_CRLF
<< "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __SRS_CRLF;
return this;
}
SrsHttpHandler* SrsHttpHandler::res_content_type_ico(stringstream& ss)
{
ss << "Content-Type: image/x-icon" << __CRLF
<< "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __CRLF;
ss << "Content-Type: image/x-icon" << __SRS_CRLF
<< "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __SRS_CRLF;
return this;
}
SrsHttpHandler* SrsHttpHandler::res_content_type_json(stringstream& ss)
{
ss << "Content-Type: application/json;charset=utf-8" << __CRLF
<< "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __CRLF;
ss << "Content-Type: application/json;charset=utf-8" << __SRS_CRLF
<< "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __SRS_CRLF;
return this;
}
SrsHttpHandler* SrsHttpHandler::res_content_type_m3u8(stringstream& ss)
{
ss << "Content-Type: application/x-mpegURL;charset=utf-8" << __CRLF
<< "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __CRLF;
ss << "Content-Type: application/x-mpegURL;charset=utf-8" << __SRS_CRLF
<< "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __SRS_CRLF;
return this;
}
SrsHttpHandler* SrsHttpHandler::res_content_type_mpegts(stringstream& ss)
{
ss << "Content-Type: video/MP2T" << __CRLF
<< "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __CRLF;
ss << "Content-Type: video/MP2T" << __SRS_CRLF
<< "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __SRS_CRLF;
return this;
}
SrsHttpHandler* SrsHttpHandler::res_content_type_flv(stringstream& ss)
{
ss << "Content-Type: video/x-flv" << __CRLF
<< "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __CRLF;
ss << "Content-Type: video/x-flv" << __SRS_CRLF
<< "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __SRS_CRLF;
return this;
}
SrsHttpHandler* SrsHttpHandler::res_content_length(stringstream& ss, int64_t length)
{
ss << "Content-Length: "<< length << __CRLF;
ss << "Content-Length: "<< length << __SRS_CRLF;
return this;
}
SrsHttpHandler* SrsHttpHandler::res_enable_crossdomain(stringstream& ss)
{
ss << "Access-Control-Allow-Origin: *" << __CRLF
ss << "Access-Control-Allow-Origin: *" << __SRS_CRLF
<< "Access-Control-Allow-Methods: "
<< "GET, POST, HEAD, PUT, DELETE" << __CRLF
<< "GET, POST, HEAD, PUT, DELETE" << __SRS_CRLF
<< "Access-Control-Allow-Headers: "
<< "Cache-Control,X-Proxy-Authorization,X-Requested-With,Content-Type" << __CRLF;
<< "Cache-Control,X-Proxy-Authorization,X-Requested-With,Content-Type" << __SRS_CRLF;
return this;
}
SrsHttpHandler* SrsHttpHandler::res_header_eof(stringstream& ss)
{
ss << __CRLF;
ss << __SRS_CRLF;
return this;
}

View file

@ -48,19 +48,19 @@ class SrsHttpHandler;
// http specification
// CR = <US-ASCII CR, carriage return (13)>
#define __CR "\r" // 0x0D
#define __SRS_CR "\r" // 0x0D
// LF = <US-ASCII LF, linefeed (10)>
#define __LF "\n" // 0x0A
#define __SRS_LF "\n" // 0x0A
// SP = <US-ASCII SP, space (32)>
#define __SP " " // 0x20
#define __SRS_SP " " // 0x20
// HT = <US-ASCII HT, horizontal-tab (9)>
#define __HT "\x09" // 0x09
#define __SRS_HT "\x09" // 0x09
// HTTP/1.1 defines the sequence CR LF as the end-of-line marker for all
// protocol elements except the entity-body (see appendix 19.3 for
// tolerant applications).
#define __CRLF "\r\n" // 0x0D0A
#define __CRLFCRLF "\r\n\r\n" // 0x0D0A0D0A
#define __SRS_CRLF "\r\n" // 0x0D0A
#define __SRS_CRLFCRLF "\r\n\r\n" // 0x0D0A0D0A
// 6.1.1 Status Code and Reason Phrase
#define HTTP_Continue 100

View file

@ -76,13 +76,13 @@ int SrsHttpClient::post(SrsHttpUri* uri, string req, string& res)
// POST %s HTTP/1.1\r\nHost: %s\r\nContent-Length: %d\r\n\r\n%s
std::stringstream ss;
ss << "POST " << uri->get_path() << " "
<< "HTTP/1.1" << __CRLF
<< "Host: " << uri->get_host() << __CRLF
<< "Connection: Keep-Alive" << __CRLF
<< "Content-Length: " << std::dec << req.length() << __CRLF
<< "User-Agent: " << RTMP_SIG_SRS_NAME << RTMP_SIG_SRS_VERSION << __CRLF
<< "Content-Type: text/html" << __CRLF
<< __CRLF
<< "HTTP/1.1" << __SRS_CRLF
<< "Host: " << uri->get_host() << __SRS_CRLF
<< "Connection: Keep-Alive" << __SRS_CRLF
<< "Content-Length: " << std::dec << req.length() << __SRS_CRLF
<< "User-Agent: " << RTMP_SIG_SRS_NAME << RTMP_SIG_SRS_VERSION << __SRS_CRLF
<< "Content-Type: text/html" << __SRS_CRLF
<< __SRS_CRLF
<< req;
SrsSocket skt(stfd);

View file

@ -56,7 +56,7 @@ SrsIngester::SrsIngester()
_srs_config->subscribe(this);
pthread = new SrsThread(this, SRS_AUTO_INGESTER_SLEEP_US, true);
pithy_print = new SrsPithyPrint(SRS_STAGE_INGESTER);
pithy_print = new SrsPithyPrint(SRS_CONSTS_STAGE_INGESTER);
}
SrsIngester::~SrsIngester()

View file

@ -32,7 +32,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_kernel_error.hpp>
#include <srs_kernel_utility.hpp>
#define SRS_STAGE_DEFAULT_INTERVAL_MS 1200
#define SRS_CONSTS_STAGE_DEFAULT_INTERVAL_MS 1200
SrsStageInfo::SrsStageInfo(int _stage_id)
{
@ -53,36 +53,36 @@ SrsStageInfo::~SrsStageInfo()
void SrsStageInfo::update_print_time()
{
switch (stage_id) {
case SRS_STAGE_PLAY_USER: {
case SRS_CONSTS_STAGE_PLAY_USER: {
pithy_print_time_ms = _srs_config->get_pithy_print_play();
break;
}
case SRS_STAGE_PUBLISH_USER: {
case SRS_CONSTS_STAGE_PUBLISH_USER: {
pithy_print_time_ms = _srs_config->get_pithy_print_publish();
break;
}
case SRS_STAGE_FORWARDER: {
case SRS_CONSTS_STAGE_FORWARDER: {
pithy_print_time_ms = _srs_config->get_pithy_print_forwarder();
break;
}
case SRS_STAGE_ENCODER: {
case SRS_CONSTS_STAGE_ENCODER: {
pithy_print_time_ms = _srs_config->get_pithy_print_encoder();
break;
}
case SRS_STAGE_INGESTER: {
case SRS_CONSTS_STAGE_INGESTER: {
pithy_print_time_ms = _srs_config->get_pithy_print_ingester();
break;
}
case SRS_STAGE_EDGE: {
case SRS_CONSTS_STAGE_EDGE: {
pithy_print_time_ms = _srs_config->get_pithy_print_edge();
break;
}
case SRS_STAGE_HLS: {
case SRS_CONSTS_STAGE_HLS: {
pithy_print_time_ms = _srs_config->get_pithy_print_hls();
break;
}
default: {
pithy_print_time_ms = SRS_STAGE_DEFAULT_INTERVAL_MS;
pithy_print_time_ms = SRS_CONSTS_STAGE_DEFAULT_INTERVAL_MS;
break;
}
}

View file

@ -32,21 +32,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_app_reload.hpp>
// the pithy stage for all play clients.
#define SRS_STAGE_PLAY_USER 1
// the pithy stage for all publish clients.
#define SRS_STAGE_PUBLISH_USER 2
// the pithy stage for all forward clients.
#define SRS_STAGE_FORWARDER 3
// the pithy stage for all encoders.
#define SRS_STAGE_ENCODER 4
// the pithy stage for all hls.
#define SRS_STAGE_HLS 5
// the pithy stage for all ingesters.
#define SRS_STAGE_INGESTER 6
// the pithy stage for all edge.
#define SRS_STAGE_EDGE 7
class SrsStageInfo : public ISrsReloadHandler
{
public:
@ -83,7 +68,7 @@ private:
int64_t previous_tick;
public:
/**
* @param _stage_id defined in SRS_STAGE_xxx, eg. SRS_STAGE_PLAY_USER.
* @param _stage_id defined in SRS_CONSTS_STAGE_xxx, eg. SRS_CONSTS_STAGE_PLAY_USER.
*/
SrsPithyPrint(int _stage_id);
virtual ~SrsPithyPrint();

View file

@ -503,7 +503,7 @@ int SrsRtmpConn::playing(SrsSource* source)
rtmp->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);
SrsPithyPrint pithy_print(SRS_STAGE_PLAY_USER);
SrsPithyPrint pithy_print(SRS_CONSTS_STAGE_PLAY_USER);
SrsSharedPtrMessageArray msgs(SYS_MAX_PLAY_SEND_MSGS);
@ -611,7 +611,7 @@ int SrsRtmpConn::fmle_publishing(SrsSource* source)
}
srs_verbose("fmle check publish_refer success.");
SrsPithyPrint pithy_print(SRS_STAGE_PUBLISH_USER);
SrsPithyPrint pithy_print(SRS_CONSTS_STAGE_PUBLISH_USER);
bool vhost_is_edge = _srs_config->get_vhost_is_edge(req->vhost);
@ -690,7 +690,7 @@ int SrsRtmpConn::flash_publishing(SrsSource* source)
}
srs_verbose("flash check publish_refer success.");
SrsPithyPrint pithy_print(SRS_STAGE_PUBLISH_USER);
SrsPithyPrint pithy_print(SRS_CONSTS_STAGE_PUBLISH_USER);
bool vhost_is_edge = _srs_config->get_vhost_is_edge(req->vhost);