Commit 65393c1b authored by François Cartegnie's avatar François Cartegnie 🤞
Browse files

demux: adaptive: handle redirections

parent 80a2314a
......@@ -203,7 +203,7 @@ block_t * HTTPChunkSource::read(size_t readsize)
return p_block;
}
bool HTTPChunkSource::prepare()
bool HTTPChunkSource::prepare(int i_redir)
{
if(prepared)
return true;
......@@ -218,8 +218,13 @@ bool HTTPChunkSource::prepare()
return false;
}
if( connection->request(params.getPath(), bytesRange) != VLC_SUCCESS )
int i_ret = connection->request(params.getPath(), bytesRange);
if(i_ret != VLC_SUCCESS)
{
if(i_ret == VLC_ETIMEOUT && i_redir < 3)
return HTTPChunkSource::prepare(i_redir + 1);
return false;
}
/* Because we don't know Chunk size at start, we need to get size
from content length */
contentLength = connection->getContentLength();
......
......@@ -94,7 +94,7 @@ namespace adaptive
static const size_t CHUNK_SIZE = 32768;
protected:
virtual bool prepare();
virtual bool prepare(int = 0);
AbstractConnection *connection;
AbstractConnectionManager *connManager;
size_t consumed; /* read pointer */
......
......@@ -150,6 +150,15 @@ int HTTPConnection::request(const std::string &path, const BytesRange &range)
{
queryOk = true;
}
else if(i_ret == VLC_ETIMEOUT) /* redir */
{
socket->disconnect();
if(locationparams.getScheme().empty())
params.setPath(locationparams.getPath());
else
params = locationparams;
locationparams = ConnectionParams();
}
else if(i_ret == VLC_EGENERIC)
{
socket->disconnect();
......@@ -225,11 +234,7 @@ int HTTPConnection::parseReply()
ss.imbue(std::locale("C"));
int replycode;
ss >> replycode;
if (replycode != 200 && replycode != 206)
{
msg_Err(p_object, "Failed reading %s: %s", params.getUrl().c_str(), line.c_str());
return VLC_ENOOBJ;
}
line = readLine();
......@@ -245,6 +250,18 @@ int HTTPConnection::parseReply()
line = readLine();
}
if((replycode == 301 || replycode == 307) &&
!locationparams.getUrl().empty())
{
msg_Info(p_object, "%d redirection to %s", replycode, locationparams.getUrl().c_str());
return VLC_ETIMEOUT;
}
else if (replycode != 200 && replycode != 206)
{
msg_Err(p_object, "Failed reading %s: %s", params.getUrl().c_str(), line.c_str());
return VLC_ENOOBJ;
}
return VLC_SUCCESS;
}
......@@ -337,6 +354,10 @@ void HTTPConnection::onHeader(const std::string &key,
{
chunked = true;
}
else if(key == "Location")
{
locationparams = ConnectionParams( value );
}
}
std::string HTTPConnection::buildRequestHeader(const std::string &path) const
......
......@@ -89,6 +89,7 @@ namespace adaptive
std::string readLine();
char * psz_useragent;
ConnectionParams locationparams;
bool connectionClose;
bool chunked;
bool chunked_eof;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment