Skip to content

Commit

Permalink
For #1657, refine on_http_message with response writer
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Nov 5, 2020
1 parent d67b050 commit 74799a3
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_caster_flv.cpp
Expand Up @@ -264,7 +264,7 @@ srs_error_t SrsDynamicHttpConn::on_start()
return srs_success;
}

srs_error_t SrsDynamicHttpConn::on_http_message(ISrsHttpMessage* msg)
srs_error_t SrsDynamicHttpConn::on_http_message(ISrsHttpMessage* r, SrsHttpResponseWriter* w)
{
return srs_success;
}
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_caster_flv.hpp
Expand Up @@ -100,7 +100,7 @@ class SrsDynamicHttpConn : virtual public ISrsStartableConneciton, virtual publi
// Interface ISrsHttpConnOwner.
public:
virtual srs_error_t on_start();
virtual srs_error_t on_http_message(ISrsHttpMessage* msg);
virtual srs_error_t on_http_message(ISrsHttpMessage* r, SrsHttpResponseWriter* w);
virtual void on_conn_done();
// Interface ISrsResource.
public:
Expand Down
8 changes: 6 additions & 2 deletions trunk/src/app/srs_app_http_api.cpp
Expand Up @@ -1700,13 +1700,17 @@ srs_error_t SrsHttpApi::on_start()
return err;
}

srs_error_t SrsHttpApi::on_http_message(ISrsHttpMessage* req)
srs_error_t SrsHttpApi::on_http_message(ISrsHttpMessage* r, SrsHttpResponseWriter* w)
{
srs_error_t err = srs_success;

// TODO: For each API session, we use short-term HTTP connection.
//SrsHttpHeader* hdr = w->header();
//hdr->set("Connection", "Close");

// read all rest bytes in request body.
char buf[SRS_HTTP_READ_CACHE_BYTES];
ISrsHttpResponseReader* br = req->body_reader();
ISrsHttpResponseReader* br = r->body_reader();
while (!br->eof()) {
if ((err = br->read(buf, SRS_HTTP_READ_CACHE_BYTES, NULL)) != srs_success) {
return srs_error_wrap(err, "read response");
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_http_api.hpp
Expand Up @@ -269,7 +269,7 @@ class SrsHttpApi : virtual public ISrsStartableConneciton, virtual public ISrsHt
// Interface ISrsHttpConnOwner.
public:
virtual srs_error_t on_start();
virtual srs_error_t on_http_message(ISrsHttpMessage* msg);
virtual srs_error_t on_http_message(ISrsHttpMessage* r, SrsHttpResponseWriter* w);
virtual void on_conn_done();
// Interface ISrsResource.
public:
Expand Down
12 changes: 6 additions & 6 deletions trunk/src/app/srs_app_http_conn.cpp
Expand Up @@ -200,14 +200,14 @@ srs_error_t SrsHttpConn::do_cycle()
// copy request to last request object.
srs_freep(last_req);
last_req = hreq->to_request(hreq->host());

// may should discard the body.
if ((err = handler_->on_http_message(req)) != srs_success) {
SrsHttpResponseWriter writer(skt);
if ((err = handler_->on_http_message(req, &writer)) != srs_success) {
break;
}

// ok, handle http request.
SrsHttpResponseWriter writer(skt);
if ((err = process_request(&writer, req)) != srs_success) {
break;
}
Expand Down Expand Up @@ -365,14 +365,14 @@ srs_error_t SrsResponseOnlyHttpConn::on_start()
return srs_success;
}

srs_error_t SrsResponseOnlyHttpConn::on_http_message(ISrsHttpMessage* msg)
srs_error_t SrsResponseOnlyHttpConn::on_http_message(ISrsHttpMessage* r, SrsHttpResponseWriter* w)
{
srs_error_t err = srs_success;

ISrsHttpResponseReader* br = msg->body_reader();
ISrsHttpResponseReader* br = r->body_reader();

// when not specified the content length, ignore.
if (msg->content_length() == -1) {
if (r->content_length() == -1) {
return err;
}

Expand Down
6 changes: 3 additions & 3 deletions trunk/src/app/srs_app_http_conn.hpp
Expand Up @@ -63,10 +63,10 @@ class ISrsHttpConnOwner
public:
// When start the coroutine to process connection.
virtual srs_error_t on_start() = 0;
// Handle the HTTP message msg, which may be parsed partially.
// Handle the HTTP message r, which may be parsed partially.
// For the static service or api, discard any body.
// For the stream caster, for instance, http flv streaming, may discard the flv header or not.
virtual srs_error_t on_http_message(ISrsHttpMessage* msg) = 0;
virtual srs_error_t on_http_message(ISrsHttpMessage* r, SrsHttpResponseWriter* w) = 0;
// When connection is destroy, should use manager to dispose it.
virtual void on_conn_done() = 0;
};
Expand Down Expand Up @@ -169,7 +169,7 @@ class SrsResponseOnlyHttpConn : virtual public ISrsStartableConneciton, virtual
// Interface ISrsHttpConnOwner.
public:
virtual srs_error_t on_start();
virtual srs_error_t on_http_message(ISrsHttpMessage* msg);
virtual srs_error_t on_http_message(ISrsHttpMessage* r, SrsHttpResponseWriter* w);
virtual void on_conn_done();
// Extract APIs from SrsTcpConnection.
public:
Expand Down

0 comments on commit 74799a3

Please sign in to comment.