diff --git a/src/Http/HttpSession.cpp b/src/Http/HttpSession.cpp index 05a56488710d23eb5dbb372675fef0c5ff13b333..bb0a967a7b5a29200f38da1f4c180183682369a2 100644 --- a/src/Http/HttpSession.cpp +++ b/src/Http/HttpSession.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved. * * This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit). @@ -378,7 +378,10 @@ bool HttpSession::checkLiveStreamFMP4(const function &cb) { if (!cb) { // 找到源,发送http头,负载后续发送 [AUTO-TRANSLATED:ac272410] // Found the source, send the http header, and send the load later - sendResponse(200, false, HttpFileManager::getContentType(".mp4").data(), KeyValue(), nullptr, true); + _is_chunked = true; + KeyValue headerOut; + headerOut["Transfer-Encoding"] = "chunked"; + sendResponse(200, false, HttpFileManager::getContentType(".mp4").data(), headerOut, nullptr, true); } else { // 自定义发送http头 [AUTO-TRANSLATED:b8a8f683] // Custom send http header @@ -849,8 +852,26 @@ void HttpSession::onWrite(const Buffer::Ptr &buffer, bool flush) { _ticker.resetTime(); if (!_live_over_websocket) { - _total_bytes_usage += buffer->size(); - send(buffer); + if (_is_chunked) { + std::stringstream ss; + ss << hex << buffer->size(); + string sizeStr = ss.str(); + + auto sizeBuffer = make_shared(); + sizeBuffer->assign(sizeStr.data(), sizeStr.size()); + sizeBuffer->append("\r\n"); + send(sizeBuffer); + send(buffer); + + auto lfcf = make_shared(); + lfcf->assign("\r\n"); + send(lfcf); + + _total_bytes_usage += buffer->size() + sizeStr.size() + 4; + } else { + _total_bytes_usage += buffer->size(); + send(buffer); + } } else { WebSocketHeader header; header._fin = true; diff --git a/src/Http/HttpSession.h b/src/Http/HttpSession.h index b714e4b643b9fd480d446b2d1fcfaa93487beaeb..0fba87944d60f05777d0809c57b5ba5351830a87 100644 --- a/src/Http/HttpSession.h +++ b/src/Http/HttpSession.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved. * * This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit). @@ -159,6 +159,7 @@ private: bool _is_live_stream = false; bool _live_over_websocket = false; bool _is_websocket = false; + bool _is_chunked = false; // 超时时间 [AUTO-TRANSLATED:f15e2672] // Timeout size_t _keep_alive_sec = 0;