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 \
*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())
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;
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);
};
}
--- /dev/null
+/*
+ * 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;
+}
#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;
};
}
}
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)
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);
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;
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)
{
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;
static const int RETRY;
protected:
- virtual std::string prepareRequest (Chunk *chunk);
bool initChunk (Chunk *chunk);
bool reconnect (Chunk *chunk);
bool resendAllRequests ();