mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
fix the http error header.
This commit is contained in:
parent
fbcc07d85a
commit
c5bf397295
4 changed files with 52 additions and 7 deletions
|
@ -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("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("requests", "the request itself, for http debug") << SRS_JFIELD_CONT
|
||||||
<< SRS_JFIELD_STR("vhosts", "dumps vhost to json") << 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
|
||||||
<< 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());
|
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)
|
SrsHttpApi::SrsHttpApi(IConnectionManager* cm, st_netfd_t fd, SrsHttpServeMux* m)
|
||||||
: SrsConnection(cm, fd)
|
: SrsConnection(cm, fd)
|
||||||
{
|
{
|
||||||
|
|
|
@ -159,6 +159,15 @@ public:
|
||||||
virtual int serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
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
|
class SrsHttpApi : public SrsConnection
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -102,13 +102,15 @@ int SrsHttpResponseWriter::write(char* data, int size)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
// write the header data in memory.
|
||||||
if (!header_wrote) {
|
if (!header_wrote) {
|
||||||
write_header(SRS_CONSTS_HTTP_OK);
|
write_header(SRS_CONSTS_HTTP_OK);
|
||||||
|
}
|
||||||
if ((ret = send_header(data, size)) != ERROR_SUCCESS) {
|
|
||||||
srs_error("http: send header failed. ret=%d", ret);
|
// whatever header is wrote, we should try to send header.
|
||||||
return ret;
|
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.
|
// check the bytes send and content length.
|
||||||
|
|
|
@ -770,7 +770,7 @@ int SrsServer::http_handle()
|
||||||
|
|
||||||
#ifdef SRS_AUTO_HTTP_API
|
#ifdef SRS_AUTO_HTTP_API
|
||||||
srs_assert(http_api_mux);
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
if ((ret = http_api_mux->handle("/api", new SrsGoApiApi())) != ERROR_SUCCESS) {
|
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) {
|
if ((ret = http_api_mux->handle("/api/v1/streams", new SrsGoApiStreams())) != ERROR_SUCCESS) {
|
||||||
return ret;
|
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
|
#endif
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in a new issue