1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Improve the coverage for HTTP error response.

This commit is contained in:
winlin 2019-12-16 11:36:39 +08:00
parent 474266eae7
commit 8c10c26f00
6 changed files with 141 additions and 8 deletions

View file

@ -614,7 +614,15 @@ bool SrsHttpMessage::is_jsonp()
return jsonp;
}
SrsHttpResponseWriter::SrsHttpResponseWriter(SrsStSocket* io)
ISrsHttpHeaderFilter::ISrsHttpHeaderFilter()
{
}
ISrsHttpHeaderFilter::~ISrsHttpHeaderFilter()
{
}
SrsHttpResponseWriter::SrsHttpResponseWriter(ISrsProtocolReadWriter* io)
{
skt = io;
hdr = new SrsHttpHeader();
@ -625,6 +633,7 @@ SrsHttpResponseWriter::SrsHttpResponseWriter(SrsStSocket* io)
header_sent = false;
nb_iovss_cache = 0;
iovss_cache = NULL;
hf = NULL;
}
SrsHttpResponseWriter::~SrsHttpResponseWriter()
@ -840,6 +849,11 @@ srs_error_t SrsHttpResponseWriter::send_header(char* data, int size)
// keep alive to make vlc happy.
hdr->set("Connection", "Keep-Alive");
// Filter the header before writing it.
if (hf && ((err = hf->filter(hdr)) != srs_success)) {
return srs_error_wrap(err, "filter header");
}
// write headers
hdr->write(ss);

View file

@ -35,7 +35,7 @@ class SrsFastStream;
class SrsRequest;
class ISrsReader;
class SrsHttpResponseReader;
class SrsStSocket;
class ISrsProtocolReadWriter;
// A wrapper for http-parser,
// provides HTTP message originted service.
@ -195,12 +195,25 @@ public:
// for writev, there always one chunk to send it.
#define SRS_HTTP_HEADER_CACHE_SIZE 64
class ISrsHttpHeaderFilter
{
public:
ISrsHttpHeaderFilter();
virtual ~ISrsHttpHeaderFilter();
public:
// Filter the HTTP header h.
virtual srs_error_t filter(SrsHttpHeader* h) = 0;
};
// Response writer use st socket
class SrsHttpResponseWriter : public ISrsHttpResponseWriter
{
private:
SrsStSocket* skt;
ISrsProtocolReadWriter* skt;
SrsHttpHeader* hdr;
// Before writing header, there is a chance to filter it,
// such as remove some headers or inject new.
ISrsHttpHeaderFilter* hf;
private:
char header_cache[SRS_HTTP_HEADER_CACHE_SIZE];
iovec* iovss_cache;
@ -222,7 +235,7 @@ private:
// logically written.
bool header_sent;
public:
SrsHttpResponseWriter(SrsStSocket* io);
SrsHttpResponseWriter(ISrsProtocolReadWriter* io);
virtual ~SrsHttpResponseWriter();
public:
virtual srs_error_t final_request();