From 41f52173604f999eefd203991953bb977a91fee4 Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 27 Mar 2014 17:13:26 +0800 Subject: [PATCH] refine http code, define CRLF consts for http --- trunk/src/app/srs_app_http.cpp | 17 ++++++++++------- trunk/src/app/srs_app_http.hpp | 18 ++++++++++++++++++ trunk/src/app/srs_app_http_api.cpp | 4 ++-- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/trunk/src/app/srs_app_http.cpp b/trunk/src/app/srs_app_http.cpp index 83af8e4df..bb1358cee 100644 --- a/trunk/src/app/srs_app_http.cpp +++ b/trunk/src/app/srs_app_http.cpp @@ -26,6 +26,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #ifdef SRS_HTTP_CALLBACK #include +using namespace std; #include #include @@ -37,6 +38,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include +using namespace srs; + #define SRS_DEFAULT_HTTP_PORT 80 #define SRS_HTTP_RESPONSE_OK "0" @@ -150,13 +153,13 @@ int SrsHttpClient::post(SrsHttpUri* uri, std::string req, std::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\r\n" - << "Host: " << uri->get_host() << "\r\n" - << "Connection: Keep-Alive" << "\r\n" - << "Content-Length: " << std::dec << req.length() << "\r\n" - << "User-Agent: " << RTMP_SIG_SRS_NAME << RTMP_SIG_SRS_VERSION << "\r\n" - << "Content-Type: text/html" << "\r\n" - << "\r\n" + << "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 << req; SrsSocket skt(stfd); diff --git a/trunk/src/app/srs_app_http.hpp b/trunk/src/app/srs_app_http.hpp index 795907f8f..97e4cb49a 100644 --- a/trunk/src/app/srs_app_http.hpp +++ b/trunk/src/app/srs_app_http.hpp @@ -31,6 +31,24 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include +// http specification +namespace srs +{ + // CR = + const static char CR = '\r'; + // LF = + const static char LF = '\n'; + // SP = + const static char SP = ' '; + // HT = + const static char HT = 9; + + // 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). + const static char* CRLF = "\r\n"; +}; + #ifdef SRS_HTTP_CALLBACK class SrsRequest; diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index 71a0c47b1..a48ada702 100644 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -31,11 +31,11 @@ SrsHttpApi::SrsHttpApi(SrsServer* srs_server, st_netfd_t client_stfd) { } -SrsHttpApi::~SrsHttpApi() +SrsHttpApi::~SrsHttpApi() { } -int SrsHttpApi::do_cycle() +int SrsHttpApi::do_cycle() { int ret = ERROR_SUCCESS;