mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
parent
15d87537a1
commit
b04888a35d
3 changed files with 48 additions and 4 deletions
|
@ -339,7 +339,8 @@ int SrsGoHttpFileServer::serve_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage*
|
||||||
|
|
||||||
int64_t length = fs.filesize();
|
int64_t length = fs.filesize();
|
||||||
|
|
||||||
w->header()->set_content_length(length);
|
// unset the content length in chunked encoding.
|
||||||
|
//w->header()->set_content_length(length);
|
||||||
|
|
||||||
static std::map<std::string, std::string> _mime;
|
static std::map<std::string, std::string> _mime;
|
||||||
if (_mime.empty()) {
|
if (_mime.empty()) {
|
||||||
|
@ -391,7 +392,7 @@ int SrsGoHttpFileServer::serve_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage*
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return w->final_request();
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGoHttpFileServer::serve_flv_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, string fullpath, int offset)
|
int SrsGoHttpFileServer::serve_flv_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, string fullpath, int offset)
|
||||||
|
@ -653,6 +654,20 @@ SrsGoHttpResponseWriter::~SrsGoHttpResponseWriter()
|
||||||
srs_freep(hdr);
|
srs_freep(hdr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SrsGoHttpResponseWriter::final_request()
|
||||||
|
{
|
||||||
|
// complete the chunked encoding.
|
||||||
|
if (content_length == -1) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << 0 << __SRS_CRLF << __SRS_CRLF;
|
||||||
|
std::string ch = ss.str();
|
||||||
|
return skt->write((void*)ch.data(), (int)ch.length(), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ignore when send with content length
|
||||||
|
return ERROR_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
SrsGoHttpHeader* SrsGoHttpResponseWriter::header()
|
SrsGoHttpHeader* SrsGoHttpResponseWriter::header()
|
||||||
{
|
{
|
||||||
return hdr;
|
return hdr;
|
||||||
|
@ -678,7 +693,26 @@ int SrsGoHttpResponseWriter::write(char* data, int size)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return skt->write((void*)data, size, NULL);
|
// directly send with content length
|
||||||
|
if (content_length != -1) {
|
||||||
|
return skt->write((void*)data, size, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// send in chunked encoding.
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << hex << size << __SRS_CRLF;
|
||||||
|
std::string ch = ss.str();
|
||||||
|
if ((ret = skt->write((void*)ch.data(), (int)ch.length(), NULL)) != ERROR_SUCCESS) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
if ((ret = skt->write((void*)data, size, NULL)) != ERROR_SUCCESS) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
if ((ret = skt->write((void*)__SRS_CRLF, 2, NULL)) != ERROR_SUCCESS) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsGoHttpResponseWriter::write_header(int code)
|
void SrsGoHttpResponseWriter::write_header(int code)
|
||||||
|
@ -722,6 +756,11 @@ int SrsGoHttpResponseWriter::send_header(char* data, int size)
|
||||||
hdr->set("Server", RTMP_SIG_SRS_KEY"/"RTMP_SIG_SRS_VERSION);
|
hdr->set("Server", RTMP_SIG_SRS_KEY"/"RTMP_SIG_SRS_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// chunked encoding
|
||||||
|
if (content_length == -1) {
|
||||||
|
hdr->set("Transfer-Encoding", "chunked");
|
||||||
|
}
|
||||||
|
|
||||||
// write headers
|
// write headers
|
||||||
hdr->write(ss);
|
hdr->write(ss);
|
||||||
|
|
||||||
|
|
|
@ -128,6 +128,10 @@ public:
|
||||||
ISrsGoHttpResponseWriter();
|
ISrsGoHttpResponseWriter();
|
||||||
virtual ~ISrsGoHttpResponseWriter();
|
virtual ~ISrsGoHttpResponseWriter();
|
||||||
public:
|
public:
|
||||||
|
// when chunked mode,
|
||||||
|
// final the request to complete the chunked encoding.
|
||||||
|
virtual int final_request() = 0;
|
||||||
|
|
||||||
// Header returns the header map that will be sent by WriteHeader.
|
// Header returns the header map that will be sent by WriteHeader.
|
||||||
// Changing the header after a call to WriteHeader (or Write) has
|
// Changing the header after a call to WriteHeader (or Write) has
|
||||||
// no effect.
|
// no effect.
|
||||||
|
@ -319,6 +323,7 @@ public:
|
||||||
SrsGoHttpResponseWriter(SrsStSocket* io);
|
SrsGoHttpResponseWriter(SrsStSocket* io);
|
||||||
virtual ~SrsGoHttpResponseWriter();
|
virtual ~SrsGoHttpResponseWriter();
|
||||||
public:
|
public:
|
||||||
|
virtual int final_request();
|
||||||
virtual SrsGoHttpHeader* header();
|
virtual SrsGoHttpHeader* header();
|
||||||
virtual int write(char* data, int size);
|
virtual int write(char* data, int size);
|
||||||
virtual void write_header(int code);
|
virtual void write_header(int code);
|
||||||
|
|
|
@ -304,7 +304,7 @@ int SrsLiveStream::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
||||||
// TODO: FIMXE: add pithy print.
|
// TODO: FIMXE: add pithy print.
|
||||||
|
|
||||||
// write http header for streaming.
|
// write http header for streaming.
|
||||||
w->header()->set_content_length((int64_t)2 * 1024 * 1024 * 1024);
|
// use chunked encoding, for we donot specifes the content length.
|
||||||
if (serve_flv_streaming) {
|
if (serve_flv_streaming) {
|
||||||
w->header()->set_content_type("video/x-flv");
|
w->header()->set_content_type("video/x-flv");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue