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:
parent
d67b050935
commit
74799a31e3
6 changed files with 18 additions and 14 deletions
|
@ -264,7 +264,7 @@ srs_error_t SrsDynamicHttpConn::on_start()
|
||||||
return srs_success;
|
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;
|
return srs_success;
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ public:
|
||||||
// Interface ISrsHttpConnOwner.
|
// Interface ISrsHttpConnOwner.
|
||||||
public:
|
public:
|
||||||
virtual srs_error_t on_start();
|
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();
|
virtual void on_conn_done();
|
||||||
// Interface ISrsResource.
|
// Interface ISrsResource.
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -1700,13 +1700,17 @@ srs_error_t SrsHttpApi::on_start()
|
||||||
return err;
|
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;
|
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.
|
// read all rest bytes in request body.
|
||||||
char buf[SRS_HTTP_READ_CACHE_BYTES];
|
char buf[SRS_HTTP_READ_CACHE_BYTES];
|
||||||
ISrsHttpResponseReader* br = req->body_reader();
|
ISrsHttpResponseReader* br = r->body_reader();
|
||||||
while (!br->eof()) {
|
while (!br->eof()) {
|
||||||
if ((err = br->read(buf, SRS_HTTP_READ_CACHE_BYTES, NULL)) != srs_success) {
|
if ((err = br->read(buf, SRS_HTTP_READ_CACHE_BYTES, NULL)) != srs_success) {
|
||||||
return srs_error_wrap(err, "read response");
|
return srs_error_wrap(err, "read response");
|
||||||
|
|
|
@ -269,7 +269,7 @@ public:
|
||||||
// Interface ISrsHttpConnOwner.
|
// Interface ISrsHttpConnOwner.
|
||||||
public:
|
public:
|
||||||
virtual srs_error_t on_start();
|
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();
|
virtual void on_conn_done();
|
||||||
// Interface ISrsResource.
|
// Interface ISrsResource.
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -202,12 +202,12 @@ srs_error_t SrsHttpConn::do_cycle()
|
||||||
last_req = hreq->to_request(hreq->host());
|
last_req = hreq->to_request(hreq->host());
|
||||||
|
|
||||||
// may should discard the body.
|
// 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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ok, handle http request.
|
// ok, handle http request.
|
||||||
SrsHttpResponseWriter writer(skt);
|
|
||||||
if ((err = process_request(&writer, req)) != srs_success) {
|
if ((err = process_request(&writer, req)) != srs_success) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -365,14 +365,14 @@ srs_error_t SrsResponseOnlyHttpConn::on_start()
|
||||||
return srs_success;
|
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;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
ISrsHttpResponseReader* br = msg->body_reader();
|
ISrsHttpResponseReader* br = r->body_reader();
|
||||||
|
|
||||||
// when not specified the content length, ignore.
|
// when not specified the content length, ignore.
|
||||||
if (msg->content_length() == -1) {
|
if (r->content_length() == -1) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,10 +63,10 @@ public:
|
||||||
public:
|
public:
|
||||||
// When start the coroutine to process connection.
|
// When start the coroutine to process connection.
|
||||||
virtual srs_error_t on_start() = 0;
|
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 static service or api, discard any body.
|
||||||
// For the stream caster, for instance, http flv streaming, may discard the flv header or not.
|
// 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.
|
// When connection is destroy, should use manager to dispose it.
|
||||||
virtual void on_conn_done() = 0;
|
virtual void on_conn_done() = 0;
|
||||||
};
|
};
|
||||||
|
@ -169,7 +169,7 @@ public:
|
||||||
// Interface ISrsHttpConnOwner.
|
// Interface ISrsHttpConnOwner.
|
||||||
public:
|
public:
|
||||||
virtual srs_error_t on_start();
|
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();
|
virtual void on_conn_done();
|
||||||
// Extract APIs from SrsTcpConnection.
|
// Extract APIs from SrsTcpConnection.
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue