vlc | branch: master | Francois Cartegnie <fcvlc...@free.fr> | Thu Nov 20 14:52:56 2014 +0100| [5b85664ebad831d7a77b8cad8e2fc94cd316e18c] | committer: Francois Cartegnie
stream_filter: dash: factorize http header stuff > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5b85664ebad831d7a77b8cad8e2fc94cd316e18c --- modules/stream_filter/Makefile.am | 1 + modules/stream_filter/dash/http/HTTPConnection.cpp | 28 +++--------- modules/stream_filter/dash/http/HTTPConnection.h | 2 +- .../stream_filter/dash/http/IHTTPConnection.cpp | 46 ++++++++++++++++++++ modules/stream_filter/dash/http/IHTTPConnection.h | 4 ++ .../dash/http/PersistentConnection.cpp | 26 ++--------- .../stream_filter/dash/http/PersistentConnection.h | 1 - 7 files changed, 62 insertions(+), 46 deletions(-) diff --git a/modules/stream_filter/Makefile.am b/modules/stream_filter/Makefile.am index bb8b61e..b0a8aaa 100644 --- a/modules/stream_filter/Makefile.am +++ b/modules/stream_filter/Makefile.am @@ -30,6 +30,7 @@ libdash_plugin_la_SOURCES = \ stream_filter/dash/http/HTTPConnection.h \ stream_filter/dash/http/HTTPConnectionManager.cpp \ stream_filter/dash/http/HTTPConnectionManager.h \ + stream_filter/dash/http/IHTTPConnection.cpp \ stream_filter/dash/http/IHTTPConnection.h \ stream_filter/dash/http/PersistentConnection.cpp \ stream_filter/dash/http/PersistentConnection.h \ diff --git a/modules/stream_filter/dash/http/HTTPConnection.cpp b/modules/stream_filter/dash/http/HTTPConnection.cpp index 30a6427..d545caa 100644 --- a/modules/stream_filter/dash/http/HTTPConnection.cpp +++ b/modules/stream_filter/dash/http/HTTPConnection.cpp @@ -72,29 +72,13 @@ int HTTPConnection::peek (const uint8_t **pp_peek, size_t *pp_peek = peek; return size; } -std::string HTTPConnection::prepareRequest (Chunk *chunk) -{ - std::string request; - - if(!chunk->usesByteRange()) - { - request = "GET " + chunk->getPath() + " HTTP/1.1" + "\r\n" + - "Host: " + chunk->getHostname() + "\r\n" + - "Connection: close\r\n\r\n"; - } - else - { - std::stringstream req; - req << "GET " << chunk->getPath() << " HTTP/1.1\r\n" << - "Host: " << chunk->getHostname() << "\r\n" << - "Range: bytes=" << chunk->getStartByte() << "-" << chunk->getEndByte() << "\r\n" << - "Connection: close\r\n\r\n"; - request = req.str(); - } - - return request; +std::string HTTPConnection::getRequestHeader (const Chunk *chunk) const +{ + return IHTTPConnection::getRequestHeader(chunk) + .append("Connection: close\r\n"); } + bool HTTPConnection::init (Chunk *chunk) { if(!chunk->hasHostname()) @@ -106,7 +90,7 @@ bool HTTPConnection::init (Chunk *chunk) if(this->httpSocket == -1) return false; - if(this->sendData(this->prepareRequest(chunk))) + if(this->sendData(this->getRequestHeader(chunk).append("\r\n"))) return this->parseHeader(); return false; diff --git a/modules/stream_filter/dash/http/HTTPConnection.h b/modules/stream_filter/dash/http/HTTPConnection.h index 81a3dd5..316f612 100644 --- a/modules/stream_filter/dash/http/HTTPConnection.h +++ b/modules/stream_filter/dash/http/HTTPConnection.h @@ -66,7 +66,7 @@ namespace dash bool sendData (const std::string& data); bool parseHeader (); std::string readLine (); - virtual std::string prepareRequest (Chunk *chunk); + virtual std::string getRequestHeader(const Chunk *chunk) const; /* reimpl */ bool setUrlRelative (Chunk *chunk); }; } diff --git a/modules/stream_filter/dash/http/IHTTPConnection.cpp b/modules/stream_filter/dash/http/IHTTPConnection.cpp new file mode 100644 index 0000000..a72e480 --- /dev/null +++ b/modules/stream_filter/dash/http/IHTTPConnection.cpp @@ -0,0 +1,46 @@ +/* + * IHTTPConnection.cpp + ***************************************************************************** + * Copyright (C) 2014 - VideoLAN Authors + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#include "IHTTPConnection.h" +#include "Chunk.h" + +#include <sstream> + +using namespace dash::http; + +std::string IHTTPConnection::getRequestHeader(const Chunk *chunk) const +{ + std::string request; + if(!chunk->usesByteRange()) + { + request = "GET " + chunk->getPath() + " HTTP/1.1" + "\r\n" + + "Host: " + chunk->getHostname() + "\r\n"; + } + else + { + std::stringstream req; + req << "GET " << chunk->getPath() << " HTTP/1.1\r\n" << + "Host: " << chunk->getHostname() << "\r\n" << + "Range: bytes=" << chunk->getStartByte() << "-" << chunk->getEndByte() << "\r\n"; + + request = req.str(); + } + return request; +} diff --git a/modules/stream_filter/dash/http/IHTTPConnection.h b/modules/stream_filter/dash/http/IHTTPConnection.h index cc69e90..8c46f57 100644 --- a/modules/stream_filter/dash/http/IHTTPConnection.h +++ b/modules/stream_filter/dash/http/IHTTPConnection.h @@ -27,17 +27,21 @@ #include <stdint.h> #include <unistd.h> +#include <string> namespace dash { namespace http { + class Chunk; class IHTTPConnection { public: virtual int read (void *p_buffer, size_t len) = 0; virtual int peek (const uint8_t **pp_peek, size_t i_peek) = 0; virtual ~IHTTPConnection() {} + protected: + virtual std::string getRequestHeader(const Chunk *chunk) const; }; } } diff --git a/modules/stream_filter/dash/http/PersistentConnection.cpp b/modules/stream_filter/dash/http/PersistentConnection.cpp index 689986e..55851d0 100644 --- a/modules/stream_filter/dash/http/PersistentConnection.cpp +++ b/modules/stream_filter/dash/http/PersistentConnection.cpp @@ -85,25 +85,7 @@ int PersistentConnection::read (void *p_buffer, siz return ret; } -std::string PersistentConnection::prepareRequest (Chunk *chunk) -{ - std::string request; - if(!chunk->usesByteRange()) - { - request = "GET " + chunk->getPath() + " HTTP/1.1" + "\r\n" + - "Host: " + chunk->getHostname() + "\r\n\r\n"; - } - else - { - std::stringstream req; - req << "GET " << chunk->getPath() << " HTTP/1.1\r\n" << - "Host: " << chunk->getHostname() << "\r\n" << - "Range: bytes=" << chunk->getStartByte() << "-" << chunk->getEndByte() << "\r\n\r\n"; - request = req.str(); - } - return request; -} bool PersistentConnection::init (Chunk *chunk) { if(this->isInit) @@ -121,7 +103,7 @@ bool PersistentConnection::init (Chunk *chunk) if(this->httpSocket == -1) return false; - if(this->sendData(this->prepareRequest(chunk))) + if(this->sendData(this->getRequestHeader(chunk).append("\r\n"))) this->isInit = true; this->chunkQueue.push_back(chunk); @@ -144,7 +126,7 @@ bool PersistentConnection::addChunk (Chunk *chunk) if(chunk->getHostname().compare(this->hostname)) return false; - if(this->sendData(this->prepareRequest(chunk))) + if(this->sendData(this->getRequestHeader(chunk).append("\r\n"))) { this->chunkQueue.push_back(chunk); return true; @@ -174,7 +156,7 @@ bool PersistentConnection::initChunk (Chunk *chunk) bool PersistentConnection::reconnect (Chunk *chunk) { int count = 0; - std::string request = this->prepareRequest(chunk); + std::string request = this->getRequestHeader(chunk).append("\r\n"); while(count < this->RETRY) { @@ -199,7 +181,7 @@ bool PersistentConnection::isConnected () const bool PersistentConnection::resendAllRequests () { for(size_t i = 0; i < this->chunkQueue.size(); i++) - if(!this->sendData((this->prepareRequest(this->chunkQueue.at(i))))) + if(!this->sendData(this->getRequestHeader(this->chunkQueue.at(i)).append("\r\n"))) return false; return true; diff --git a/modules/stream_filter/dash/http/PersistentConnection.h b/modules/stream_filter/dash/http/PersistentConnection.h index c1fe936..dd5ac70 100644 --- a/modules/stream_filter/dash/http/PersistentConnection.h +++ b/modules/stream_filter/dash/http/PersistentConnection.h @@ -52,7 +52,6 @@ namespace dash static const int RETRY; protected: - virtual std::string prepareRequest (Chunk *chunk); bool initChunk (Chunk *chunk); bool reconnect (Chunk *chunk); bool resendAllRequests (); _______________________________________________ vlc-commits mailing list vlc-commits@videolan.org https://mailman.videolan.org/listinfo/vlc-commits