1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00

For #1657, refine on_http_message with response writer

This commit is contained in:
winlin 2020-11-05 18:08:13 +08:00
parent d67b050935
commit 74799a31e3
6 changed files with 18 additions and 14 deletions

View file

@ -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;
}

View file

@ -100,7 +100,7 @@ public:
// 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:

View file

@ -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");

View file

@ -269,7 +269,7 @@ public:
// 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:

View file

@ -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;
}
@ -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;
}

View file

@ -63,10 +63,10 @@ public:
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;
};
@ -169,7 +169,7 @@ public:
// 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: