From fbcc07d85a7b2487c7e9f1e55033c8eb519f0746 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 5 Aug 2015 22:54:29 +0800 Subject: [PATCH 1/4] fix the typo of AUTIO. --- trunk/src/app/srs_app_source.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index 1c38fbaa9..fe19f1f3a 100755 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -1489,7 +1489,7 @@ int SrsSource::on_audio(SrsCommonMessage* shared_audio) if (!mix_correct && is_monotonically_increase) { if (last_packet_time > 0 && shared_audio->header.timestamp < last_packet_time) { is_monotonically_increase = false; - srs_warn("AUTIO: stream not monotonically increase, please open mix_correct."); + srs_warn("AUDIO: stream not monotonically increase, please open mix_correct."); } } last_packet_time = shared_audio->header.timestamp; From c5bf3972956f41005347937e25e8244f15c57e1e Mon Sep 17 00:00:00 2001 From: winlin Date: Mon, 10 Aug 2015 16:41:25 +0800 Subject: [PATCH 2/4] fix the http error header. --- trunk/src/app/srs_app_http_api.cpp | 23 ++++++++++++++++++++++- trunk/src/app/srs_app_http_api.hpp | 9 +++++++++ trunk/src/app/srs_app_http_conn.cpp | 12 +++++++----- trunk/src/app/srs_app_server.cpp | 15 ++++++++++++++- 4 files changed, 52 insertions(+), 7 deletions(-) diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index c95cb9289..d23a21d26 100644 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -109,7 +109,8 @@ int SrsGoApiV1::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) << SRS_JFIELD_STR("authors", "the primary authors and contributors") << SRS_JFIELD_CONT << SRS_JFIELD_STR("requests", "the request itself, for http debug") << SRS_JFIELD_CONT << SRS_JFIELD_STR("vhosts", "dumps vhost to json") << SRS_JFIELD_CONT - << SRS_JFIELD_STR("streams", "dumps streams to json") + << SRS_JFIELD_STR("streams", "dumps streams to json") << SRS_JFIELD_CONT + << SRS_JFIELD_STR("errors", "always return an error 100.") << SRS_JOBJECT_END << SRS_JOBJECT_END; @@ -474,6 +475,26 @@ int SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) return srs_http_response_json(w, ss.str()); } +SrsGoApiError::SrsGoApiError() +{ +} + +SrsGoApiError::~SrsGoApiError() +{ +} + +int SrsGoApiError::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) +{ + std::stringstream ss; + + ss << SRS_JOBJECT_START + << SRS_JFIELD_ERROR(100) << SRS_JFIELD_CONT + << SRS_JFIELD_STR("msg", "SRS demo error.") + << SRS_JOBJECT_END; + + return srs_http_response_json(w, ss.str()); +} + SrsHttpApi::SrsHttpApi(IConnectionManager* cm, st_netfd_t fd, SrsHttpServeMux* m) : SrsConnection(cm, fd) { diff --git a/trunk/src/app/srs_app_http_api.hpp b/trunk/src/app/srs_app_http_api.hpp index c5f4ed462..cdc5d0af0 100644 --- a/trunk/src/app/srs_app_http_api.hpp +++ b/trunk/src/app/srs_app_http_api.hpp @@ -159,6 +159,15 @@ public: virtual int serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r); }; +class SrsGoApiError : public ISrsHttpHandler +{ +public: + SrsGoApiError(); + virtual ~SrsGoApiError(); +public: + virtual int serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r); +}; + class SrsHttpApi : public SrsConnection { private: diff --git a/trunk/src/app/srs_app_http_conn.cpp b/trunk/src/app/srs_app_http_conn.cpp index 64e095be0..f29cc1dd2 100644 --- a/trunk/src/app/srs_app_http_conn.cpp +++ b/trunk/src/app/srs_app_http_conn.cpp @@ -102,13 +102,15 @@ int SrsHttpResponseWriter::write(char* data, int size) { int ret = ERROR_SUCCESS; + // write the header data in memory. if (!header_wrote) { write_header(SRS_CONSTS_HTTP_OK); - - if ((ret = send_header(data, size)) != ERROR_SUCCESS) { - srs_error("http: send header failed. ret=%d", ret); - return ret; - } + } + + // whatever header is wrote, we should try to send header. + if ((ret = send_header(data, size)) != ERROR_SUCCESS) { + srs_error("http: send header failed. ret=%d", ret); + return ret; } // check the bytes send and content length. diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 147dfbd17..939454583 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -770,7 +770,7 @@ int SrsServer::http_handle() #ifdef SRS_AUTO_HTTP_API srs_assert(http_api_mux); - if ((ret = http_api_mux->handle("/", new SrsGoApiRoot())) != ERROR_SUCCESS) { + if ((ret = http_api_mux->handle("/", new SrsHttpNotFoundHandler())) != ERROR_SUCCESS) { return ret; } if ((ret = http_api_mux->handle("/api", new SrsGoApiApi())) != ERROR_SUCCESS) { @@ -809,6 +809,19 @@ int SrsServer::http_handle() if ((ret = http_api_mux->handle("/api/v1/streams", new SrsGoApiStreams())) != ERROR_SUCCESS) { return ret; } + // for error test which always response error code 100. + if ((ret = http_api_mux->handle("/api/v1/errors", new SrsGoApiError())) != ERROR_SUCCESS) { + return ret; + } + + // TODO: FIXME: for console. + // TODO: FIXME: support reload. + std::string dir = _srs_config->get_http_stream_dir() + "/srs-console"; + if ((ret = http_api_mux->handle("/console/", new SrsHttpFileServer(dir))) != ERROR_SUCCESS) { + srs_error("http: mount console dir=%s failed. ret=%d", dir.c_str(), ret); + return ret; + } + srs_trace("http: console mount to %s", dir.c_str()); #endif return ret; From d761ebfa55eda09d6ec22cd744a64cbcbefafded Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 11 Aug 2015 13:09:21 +0800 Subject: [PATCH 3/4] refine the api, move the requests and errors to rest. --- trunk/src/app/srs_app_http_api.cpp | 24 +++++++++++++++--------- trunk/src/app/srs_app_server.cpp | 20 +++++++++++++++----- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index d23a21d26..202bc6fa4 100644 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -110,7 +110,12 @@ int SrsGoApiV1::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) << SRS_JFIELD_STR("requests", "the request itself, for http debug") << SRS_JFIELD_CONT << SRS_JFIELD_STR("vhosts", "dumps vhost to json") << SRS_JFIELD_CONT << SRS_JFIELD_STR("streams", "dumps streams to json") << SRS_JFIELD_CONT - << SRS_JFIELD_STR("errors", "always return an error 100.") + << SRS_JFIELD_ORG("test", SRS_JOBJECT_START) + << SRS_JFIELD_STR("requests", "show the request info") << SRS_JFIELD_CONT + << SRS_JFIELD_STR("errors", "always return an error 100") << SRS_JFIELD_CONT + << SRS_JFIELD_STR("redirects", "always redirect to /api/v1/test/errors") << SRS_JFIELD_CONT + << SRS_JFIELD_STR(".vhost.", "http vhost for error.srs.com/api/v1/test/errors") + << SRS_JOBJECT_END << SRS_JOBJECT_END << SRS_JOBJECT_END; @@ -442,9 +447,9 @@ int SrsGoApiVhosts::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) std::stringstream ss; ss << SRS_JOBJECT_START - << SRS_JFIELD_ERROR(ret) << SRS_JFIELD_CONT - << SRS_JFIELD_ORG("server", stat->server_id()) << SRS_JFIELD_CONT - << SRS_JFIELD_ORG("vhosts", data.str()) + << SRS_JFIELD_ERROR(ret) << SRS_JFIELD_CONT + << SRS_JFIELD_ORG("server", stat->server_id()) << SRS_JFIELD_CONT + << SRS_JFIELD_ORG("vhosts", data.str()) << SRS_JOBJECT_END; return srs_http_response_json(w, ss.str()); @@ -467,9 +472,9 @@ int SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) std::stringstream ss; ss << SRS_JOBJECT_START - << SRS_JFIELD_ERROR(ret) << SRS_JFIELD_CONT - << SRS_JFIELD_ORG("server", stat->server_id()) << SRS_JFIELD_CONT - << SRS_JFIELD_ORG("streams", data.str()) + << SRS_JFIELD_ERROR(ret) << SRS_JFIELD_CONT + << SRS_JFIELD_ORG("server", stat->server_id()) << SRS_JFIELD_CONT + << SRS_JFIELD_ORG("streams", data.str()) << SRS_JOBJECT_END; return srs_http_response_json(w, ss.str()); @@ -488,8 +493,9 @@ int SrsGoApiError::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) std::stringstream ss; ss << SRS_JOBJECT_START - << SRS_JFIELD_ERROR(100) << SRS_JFIELD_CONT - << SRS_JFIELD_STR("msg", "SRS demo error.") + << SRS_JFIELD_ERROR(100) << SRS_JFIELD_CONT + << SRS_JFIELD_STR("msg", "SRS demo error.") << SRS_JFIELD_CONT + << SRS_JFIELD_STR("path", r->path()) << SRS_JOBJECT_END; return srs_http_response_json(w, ss.str()); diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 939454583..77b89bdf5 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -800,17 +800,27 @@ int SrsServer::http_handle() if ((ret = http_api_mux->handle("/api/v1/authors", new SrsGoApiAuthors())) != ERROR_SUCCESS) { return ret; } - if ((ret = http_api_mux->handle("/api/v1/requests", new SrsGoApiRequests())) != ERROR_SUCCESS) { - return ret; - } if ((ret = http_api_mux->handle("/api/v1/vhosts", new SrsGoApiVhosts())) != ERROR_SUCCESS) { return ret; } if ((ret = http_api_mux->handle("/api/v1/streams", new SrsGoApiStreams())) != ERROR_SUCCESS) { return ret; } - // for error test which always response error code 100. - if ((ret = http_api_mux->handle("/api/v1/errors", new SrsGoApiError())) != ERROR_SUCCESS) { + + // test the request info. + if ((ret = http_api_mux->handle("/api/v1/test/requests", new SrsGoApiRequests())) != ERROR_SUCCESS) { + return ret; + } + // test the error code response. + if ((ret = http_api_mux->handle("/api/v1/test/errors", new SrsGoApiError())) != ERROR_SUCCESS) { + return ret; + } + // test the redirect mechenism. + if ((ret = http_api_mux->handle("/api/v1/test/redirects", new SrsHttpRedirectHandler("/api/v1/test/errors", SRS_CONSTS_HTTP_MovedPermanently))) != ERROR_SUCCESS) { + return ret; + } + // test the http vhost. + if ((ret = http_api_mux->handle("error.srs.com/api/v1/test/errors", new SrsGoApiError())) != ERROR_SUCCESS) { return ret; } From 3a6854fc2e575cf640808f5a5c9bcb2dac92fbad Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 11 Aug 2015 15:36:14 +0800 Subject: [PATCH 4/4] refine code. --- trunk/src/app/srs_app_http_conn.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trunk/src/app/srs_app_http_conn.cpp b/trunk/src/app/srs_app_http_conn.cpp index f29cc1dd2..d4637cc01 100644 --- a/trunk/src/app/srs_app_http_conn.cpp +++ b/trunk/src/app/srs_app_http_conn.cpp @@ -263,7 +263,7 @@ int SrsHttpResponseWriter::send_header(char* data, int size) // status_line ss << "HTTP/1.1 " << status << " " - << srs_generate_http_status_text(status) << SRS_HTTP_CRLF; + << srs_generate_http_status_text(status) << SRS_HTTP_CRLF; // detect content type if (srs_go_http_body_allowd(status)) {