Make content-encoded plugin data work even if there is no content-length

header.  Bug 300438, r=jst, sr=darin, a=bsmedberg
This commit is contained in:
bzbarsky%mit.edu 2005-07-22 18:29:34 +00:00
Родитель 55fea90a44
Коммит c995b755c9
1 изменённых файлов: 29 добавлений и 28 удалений

Просмотреть файл

@ -2411,23 +2411,24 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIRequest *request,
if (httpChannel) { if (httpChannel) {
httpChannel->VisitResponseHeaders(this); httpChannel->VisitResponseHeaders(this);
// set seekability (seekable if the stream has a known length and if the
// http server accepts byte ranges).
PRBool bSeekable = PR_FALSE; PRBool bSeekable = PR_FALSE;
PRUint32 length; // first we look for a content-encoding header. If we find one, we tell the
mPluginStreamInfo->GetLength(&length); // plugin that stream is not seekable, because the plugin always sees
if (length) { // uncompressed data, so it can't make meaningful range requests on a
// first we look for a content-encoding header. If we find one, // compressed entity. Also, we force the plugin to use
// we tell the plugin that stream is not seekable, // nsPluginStreamType_AsFile stream type and we have to save decompressed
// because range request on compressed content is irrelevant, // file into local plugin cache, because necko cache contains original
// so we force the plugin to use nsPluginStreamType_AsFile stream type // compressed file.
// and we have to save decompressed file into local plugin cache, nsCAutoString contentEncoding;
// because necko cache contains original compressed file. if (NS_SUCCEEDED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Content-Encoding"),
nsCAutoString contentEncoding; contentEncoding))) {
if (NS_SUCCEEDED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Content-Encoding"), useLocalCache = PR_TRUE;
contentEncoding))) { } else {
useLocalCache = PR_TRUE; // set seekability (seekable if the stream has a known length and if the
} else { // http server accepts byte ranges).
PRUint32 length;
mPluginStreamInfo->GetLength(&length);
if (length) {
nsCAutoString range; nsCAutoString range;
if (NS_SUCCEEDED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("accept-ranges"), range)) && if (NS_SUCCEEDED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("accept-ranges"), range)) &&
range.Equals(NS_LITERAL_CSTRING("bytes"), nsCaseInsensitiveCStringComparator())) { range.Equals(NS_LITERAL_CSTRING("bytes"), nsCaseInsensitiveCStringComparator())) {
@ -2437,21 +2438,21 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIRequest *request,
mPluginStreamInfo->SetSeekable(bSeekable); mPluginStreamInfo->SetSeekable(bSeekable);
} }
} }
}
// we require a content len // we require a content len
// get Last-Modified header for plugin info // get Last-Modified header for plugin info
nsCAutoString lastModified; nsCAutoString lastModified;
if (NS_SUCCEEDED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("last-modified"), lastModified)) && if (NS_SUCCEEDED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("last-modified"), lastModified)) &&
!lastModified.IsEmpty()) !lastModified.IsEmpty())
{ {
PRTime time64; PRTime time64;
PR_ParseTimeString(lastModified.get(), PR_TRUE, &time64); //convert string time to interger time PR_ParseTimeString(lastModified.get(), PR_TRUE, &time64); //convert string time to interger time
// Convert PRTime to unix-style time_t, i.e. seconds since the epoch // Convert PRTime to unix-style time_t, i.e. seconds since the epoch
double fpTime; double fpTime;
LL_L2D(fpTime, time64); LL_L2D(fpTime, time64);
mPluginStreamInfo->SetLastModified((PRUint32)(fpTime * 1e-6 + 0.5)); mPluginStreamInfo->SetLastModified((PRUint32)(fpTime * 1e-6 + 0.5));
}
} }
} }