winlin

refine the api, move the requests and errors to rest.

@@ -110,7 +110,12 @@ int SrsGoApiV1::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) @@ -110,7 +110,12 @@ int SrsGoApiV1::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
110 << SRS_JFIELD_STR("requests", "the request itself, for http debug") << SRS_JFIELD_CONT 110 << SRS_JFIELD_STR("requests", "the request itself, for http debug") << SRS_JFIELD_CONT
111 << SRS_JFIELD_STR("vhosts", "dumps vhost to json") << SRS_JFIELD_CONT 111 << SRS_JFIELD_STR("vhosts", "dumps vhost to json") << SRS_JFIELD_CONT
112 << SRS_JFIELD_STR("streams", "dumps streams to json") << SRS_JFIELD_CONT 112 << SRS_JFIELD_STR("streams", "dumps streams to json") << SRS_JFIELD_CONT
113 - << SRS_JFIELD_STR("errors", "always return an error 100.") 113 + << SRS_JFIELD_ORG("test", SRS_JOBJECT_START)
  114 + << SRS_JFIELD_STR("requests", "show the request info") << SRS_JFIELD_CONT
  115 + << SRS_JFIELD_STR("errors", "always return an error 100") << SRS_JFIELD_CONT
  116 + << SRS_JFIELD_STR("redirects", "always redirect to /api/v1/test/errors") << SRS_JFIELD_CONT
  117 + << SRS_JFIELD_STR(".vhost.", "http vhost for error.srs.com/api/v1/test/errors")
  118 + << SRS_JOBJECT_END
114 << SRS_JOBJECT_END 119 << SRS_JOBJECT_END
115 << SRS_JOBJECT_END; 120 << SRS_JOBJECT_END;
116 121
@@ -442,9 +447,9 @@ int SrsGoApiVhosts::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) @@ -442,9 +447,9 @@ int SrsGoApiVhosts::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
442 std::stringstream ss; 447 std::stringstream ss;
443 448
444 ss << SRS_JOBJECT_START 449 ss << SRS_JOBJECT_START
445 - << SRS_JFIELD_ERROR(ret) << SRS_JFIELD_CONT  
446 - << SRS_JFIELD_ORG("server", stat->server_id()) << SRS_JFIELD_CONT  
447 - << SRS_JFIELD_ORG("vhosts", data.str()) 450 + << SRS_JFIELD_ERROR(ret) << SRS_JFIELD_CONT
  451 + << SRS_JFIELD_ORG("server", stat->server_id()) << SRS_JFIELD_CONT
  452 + << SRS_JFIELD_ORG("vhosts", data.str())
448 << SRS_JOBJECT_END; 453 << SRS_JOBJECT_END;
449 454
450 return srs_http_response_json(w, ss.str()); 455 return srs_http_response_json(w, ss.str());
@@ -467,9 +472,9 @@ int SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) @@ -467,9 +472,9 @@ int SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
467 std::stringstream ss; 472 std::stringstream ss;
468 473
469 ss << SRS_JOBJECT_START 474 ss << SRS_JOBJECT_START
470 - << SRS_JFIELD_ERROR(ret) << SRS_JFIELD_CONT  
471 - << SRS_JFIELD_ORG("server", stat->server_id()) << SRS_JFIELD_CONT  
472 - << SRS_JFIELD_ORG("streams", data.str()) 475 + << SRS_JFIELD_ERROR(ret) << SRS_JFIELD_CONT
  476 + << SRS_JFIELD_ORG("server", stat->server_id()) << SRS_JFIELD_CONT
  477 + << SRS_JFIELD_ORG("streams", data.str())
473 << SRS_JOBJECT_END; 478 << SRS_JOBJECT_END;
474 479
475 return srs_http_response_json(w, ss.str()); 480 return srs_http_response_json(w, ss.str());
@@ -488,8 +493,9 @@ int SrsGoApiError::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) @@ -488,8 +493,9 @@ int SrsGoApiError::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
488 std::stringstream ss; 493 std::stringstream ss;
489 494
490 ss << SRS_JOBJECT_START 495 ss << SRS_JOBJECT_START
491 - << SRS_JFIELD_ERROR(100) << SRS_JFIELD_CONT  
492 - << SRS_JFIELD_STR("msg", "SRS demo error.") 496 + << SRS_JFIELD_ERROR(100) << SRS_JFIELD_CONT
  497 + << SRS_JFIELD_STR("msg", "SRS demo error.") << SRS_JFIELD_CONT
  498 + << SRS_JFIELD_STR("path", r->path())
493 << SRS_JOBJECT_END; 499 << SRS_JOBJECT_END;
494 500
495 return srs_http_response_json(w, ss.str()); 501 return srs_http_response_json(w, ss.str());
@@ -800,17 +800,27 @@ int SrsServer::http_handle() @@ -800,17 +800,27 @@ int SrsServer::http_handle()
800 if ((ret = http_api_mux->handle("/api/v1/authors", new SrsGoApiAuthors())) != ERROR_SUCCESS) { 800 if ((ret = http_api_mux->handle("/api/v1/authors", new SrsGoApiAuthors())) != ERROR_SUCCESS) {
801 return ret; 801 return ret;
802 } 802 }
803 - if ((ret = http_api_mux->handle("/api/v1/requests", new SrsGoApiRequests())) != ERROR_SUCCESS) {  
804 - return ret;  
805 - }  
806 if ((ret = http_api_mux->handle("/api/v1/vhosts", new SrsGoApiVhosts())) != ERROR_SUCCESS) { 803 if ((ret = http_api_mux->handle("/api/v1/vhosts", new SrsGoApiVhosts())) != ERROR_SUCCESS) {
807 return ret; 804 return ret;
808 } 805 }
809 if ((ret = http_api_mux->handle("/api/v1/streams", new SrsGoApiStreams())) != ERROR_SUCCESS) { 806 if ((ret = http_api_mux->handle("/api/v1/streams", new SrsGoApiStreams())) != ERROR_SUCCESS) {
810 return ret; 807 return ret;
811 } 808 }
812 - // for error test which always response error code 100.  
813 - if ((ret = http_api_mux->handle("/api/v1/errors", new SrsGoApiError())) != ERROR_SUCCESS) { 809 +
  810 + // test the request info.
  811 + if ((ret = http_api_mux->handle("/api/v1/test/requests", new SrsGoApiRequests())) != ERROR_SUCCESS) {
  812 + return ret;
  813 + }
  814 + // test the error code response.
  815 + if ((ret = http_api_mux->handle("/api/v1/test/errors", new SrsGoApiError())) != ERROR_SUCCESS) {
  816 + return ret;
  817 + }
  818 + // test the redirect mechenism.
  819 + if ((ret = http_api_mux->handle("/api/v1/test/redirects", new SrsHttpRedirectHandler("/api/v1/test/errors", SRS_CONSTS_HTTP_MovedPermanently))) != ERROR_SUCCESS) {
  820 + return ret;
  821 + }
  822 + // test the http vhost.
  823 + if ((ret = http_api_mux->handle("error.srs.com/api/v1/test/errors", new SrsGoApiError())) != ERROR_SUCCESS) {
814 return ret; 824 return ret;
815 } 825 }
816 826