mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
refine the api, move the requests and errors to rest.
This commit is contained in:
parent
c5bf397295
commit
d761ebfa55
2 changed files with 30 additions and 14 deletions
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue