正在显示
2 个修改的文件
包含
14 行增加
和
29 行删除
@@ -509,31 +509,23 @@ int SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | @@ -509,31 +509,23 @@ int SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | ||
509 | if (sid >= 0 && (stream = stat->find_stream(sid)) == NULL) { | 509 | if (sid >= 0 && (stream = stat->find_stream(sid)) == NULL) { |
510 | ret = ERROR_RTMP_STREAM_NOT_FOUND; | 510 | ret = ERROR_RTMP_STREAM_NOT_FOUND; |
511 | srs_error("stream stream_id=%d not found. ret=%d", sid, ret); | 511 | srs_error("stream stream_id=%d not found. ret=%d", sid, ret); |
512 | - | ||
513 | - ss << SRS_JOBJECT_START | ||
514 | - << SRS_JFIELD_ERROR(ret) | ||
515 | - << SRS_JOBJECT_END; | ||
516 | - | ||
517 | - return srs_http_response_json(w, ss.str()); | 512 | + return srs_http_response_code(w, ret); |
518 | } | 513 | } |
519 | 514 | ||
520 | if (r->is_http_delete()) { | 515 | if (r->is_http_delete()) { |
521 | srs_assert(stream); | 516 | srs_assert(stream); |
522 | 517 | ||
523 | SrsSource* source = SrsSource::fetch(stream->vhost->vhost, stream->app, stream->stream); | 518 | SrsSource* source = SrsSource::fetch(stream->vhost->vhost, stream->app, stream->stream); |
524 | - if (source) { | ||
525 | - source->set_expired(); | ||
526 | - srs_warn("disconnent stream=%d successfully. vhost=%s, app=%s, stream=%s.", | ||
527 | - sid, stream->vhost->vhost.c_str(), stream->app.c_str(), stream->stream.c_str()); | ||
528 | - } else { | 519 | + if (!source) { |
529 | ret = ERROR_SOURCE_NOT_FOUND; | 520 | ret = ERROR_SOURCE_NOT_FOUND; |
521 | + srs_warn("source not found for sid=%d", sid); | ||
522 | + return srs_http_response_code(w, ret); | ||
530 | } | 523 | } |
531 | 524 | ||
532 | - ss << SRS_JOBJECT_START | ||
533 | - << SRS_JFIELD_ERROR(ret) | ||
534 | - << SRS_JOBJECT_END; | ||
535 | - | ||
536 | - return srs_http_response_json(w, ss.str()); | 525 | + source->set_expired(); |
526 | + srs_warn("disconnent stream=%d successfully. vhost=%s, app=%s, stream=%s.", | ||
527 | + sid, stream->vhost->vhost.c_str(), stream->app.c_str(), stream->stream.c_str()); | ||
528 | + return srs_http_response_code(w, ret); | ||
537 | } else if (r->is_http_get()) { | 529 | } else if (r->is_http_get()) { |
538 | std::stringstream data; | 530 | std::stringstream data; |
539 | 531 | ||
@@ -584,10 +576,7 @@ int SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | @@ -584,10 +576,7 @@ int SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | ||
584 | if (cid >= 0 && (client = stat->find_client(cid)) == NULL) { | 576 | if (cid >= 0 && (client = stat->find_client(cid)) == NULL) { |
585 | ret = ERROR_RTMP_STREAM_NOT_FOUND; | 577 | ret = ERROR_RTMP_STREAM_NOT_FOUND; |
586 | srs_error("stream client_id=%d not found. ret=%d", cid, ret); | 578 | srs_error("stream client_id=%d not found. ret=%d", cid, ret); |
587 | - | ||
588 | - ss << SRS_JOBJECT_START << SRS_JFIELD_ERROR(ret) << SRS_JOBJECT_END; | ||
589 | - | ||
590 | - return srs_http_response_json(w, ss.str()); | 579 | + return srs_http_response_code(w, ret); |
591 | 580 | ||
592 | } | 581 | } |
593 | 582 | ||
@@ -628,15 +617,7 @@ SrsGoApiError::~SrsGoApiError() | @@ -628,15 +617,7 @@ SrsGoApiError::~SrsGoApiError() | ||
628 | 617 | ||
629 | int SrsGoApiError::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | 618 | int SrsGoApiError::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) |
630 | { | 619 | { |
631 | - std::stringstream ss; | ||
632 | - | ||
633 | - ss << SRS_JOBJECT_START | ||
634 | - << SRS_JFIELD_ERROR(100) << SRS_JFIELD_CONT | ||
635 | - << SRS_JFIELD_STR("msg", "SRS demo error.") << SRS_JFIELD_CONT | ||
636 | - << SRS_JFIELD_STR("path", r->path()) | ||
637 | - << SRS_JOBJECT_END; | ||
638 | - | ||
639 | - return srs_http_response_json(w, ss.str()); | 620 | + return srs_http_response_code(w, 100); |
640 | } | 621 | } |
641 | 622 | ||
642 | 623 |
@@ -78,6 +78,10 @@ class ISrsHttpResponseWriter; | @@ -78,6 +78,10 @@ class ISrsHttpResponseWriter; | ||
78 | 78 | ||
79 | // helper function: response in json format. | 79 | // helper function: response in json format. |
80 | extern int srs_http_response_json(ISrsHttpResponseWriter* w, std::string data); | 80 | extern int srs_http_response_json(ISrsHttpResponseWriter* w, std::string data); |
81 | +/** | ||
82 | + * response a typical code object, for example: | ||
83 | + * {code : 100} | ||
84 | + */ | ||
81 | extern int srs_http_response_code(ISrsHttpResponseWriter* w, int code); | 85 | extern int srs_http_response_code(ISrsHttpResponseWriter* w, int code); |
82 | 86 | ||
83 | // get the status text of code. | 87 | // get the status text of code. |
-
请 注册 或 登录 后发表评论