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

for bug #277, refine http api refer to go http-framework. 2.0.97

This commit is contained in:
winlin 2015-01-17 21:58:23 +08:00
parent 33efeeb399
commit 9bbbaad288
10 changed files with 1004 additions and 395 deletions

View file

@ -330,7 +330,7 @@ SrsServer::SrsServer()
// for some global instance is not ready now,
// new these objects in initialize instead.
#ifdef SRS_AUTO_HTTP_API
http_api_handler = NULL;
http_api_mux = new SrsGoHttpServeMux();
#endif
#ifdef SRS_AUTO_HTTP_SERVER
http_stream_handler = NULL;
@ -363,7 +363,7 @@ void SrsServer::destroy()
#endif
#ifdef SRS_AUTO_HTTP_API
srs_freep(http_api_handler);
srs_freep(http_api_mux);
#endif
#ifdef SRS_AUTO_HTTP_SERVER
@ -415,8 +415,52 @@ int SrsServer::initialize()
kbps->set_io(NULL, NULL);
#ifdef SRS_AUTO_HTTP_API
srs_assert(!http_api_handler);
http_api_handler = SrsHttpHandler::create_http_api();
if ((ret = http_api_mux->initialize()) != ERROR_SUCCESS) {
return ret;
}
#endif
#ifdef SRS_AUTO_HTTP_API
srs_assert(http_api_mux);
if ((ret = http_api_mux->handle("/", new SrsGoApiRoot())) != ERROR_SUCCESS) {
return ret;
}
if ((ret = http_api_mux->handle("/api", new SrsGoApiApi())) != ERROR_SUCCESS) {
return ret;
}
if ((ret = http_api_mux->handle("/api/v1", new SrsGoApiV1())) != ERROR_SUCCESS) {
return ret;
}
if ((ret = http_api_mux->handle("/api/v1/versions", new SrsGoApiVersion())) != ERROR_SUCCESS) {
return ret;
}
if ((ret = http_api_mux->handle("/api/v1/summaries", new SrsGoApiSummaries())) != ERROR_SUCCESS) {
return ret;
}
if ((ret = http_api_mux->handle("/api/v1/rusages", new SrsGoApiRusages())) != ERROR_SUCCESS) {
return ret;
}
if ((ret = http_api_mux->handle("/api/v1/self_proc_stats", new SrsGoApiSelfProcStats())) != ERROR_SUCCESS) {
return ret;
}
if ((ret = http_api_mux->handle("/api/v1/system_proc_stats", new SrsGoApiSystemProcStats())) != ERROR_SUCCESS) {
return ret;
}
if ((ret = http_api_mux->handle("/api/v1/meminfos", new SrsGoApiMemInfos())) != ERROR_SUCCESS) {
return ret;
}
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;
}
#endif
#ifdef SRS_AUTO_HTTP_SERVER
srs_assert(!http_stream_handler);
@ -430,12 +474,6 @@ int SrsServer::initialize()
srs_assert(!ingester);
ingester = new SrsIngester();
#endif
#ifdef SRS_AUTO_HTTP_API
if ((ret = http_api_handler->initialize()) != ERROR_SUCCESS) {
return ret;
}
#endif
#ifdef SRS_AUTO_HTTP_SERVER
if ((ret = http_stream_handler->initialize()) != ERROR_SUCCESS) {
@ -896,7 +934,7 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd)
conn = new SrsRtmpConn(this, client_stfd);
} else if (type == SrsListenerHttpApi) {
#ifdef SRS_AUTO_HTTP_API
conn = new SrsHttpApi(this, client_stfd, http_api_handler);
conn = new SrsHttpApi(this, client_stfd, http_api_mux);
#else
srs_warn("close http client for server not support http-api");
srs_close_stfd(client_stfd);