fixes bug 59016 "jpg don't display" r=gagan, sr=dougt

This commit is contained in:
darin%netscape.com 2001-09-04 23:11:46 +00:00
Родитель 83a819dd32
Коммит 522af22bbd
2 изменённых файлов: 90 добавлений и 53 удалений

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

@ -453,6 +453,50 @@ nsHttpResponseHead::Reset()
mContentCharset.Adopt(0);
}
nsresult
nsHttpResponseHead::ParseDateHeader(nsHttpAtom header, PRUint32 *result)
{
const char *val = PeekHeader(header);
if (!val)
return NS_ERROR_NOT_AVAILABLE;
PRTime time;
PRStatus st = PR_ParseTimeString(val, PR_TRUE, &time);
if (st != PR_SUCCESS)
return NS_ERROR_NOT_AVAILABLE;
*result = PRTimeToSeconds(time);
return NS_OK;
}
nsresult
nsHttpResponseHead::GetAgeValue(PRUint32 *result)
{
const char *val = PeekHeader(nsHttp::Age);
if (!val)
return NS_ERROR_NOT_AVAILABLE;
*result = (PRUint32) atoi(val);
return NS_OK;
}
// Return the value of the (HTTP 1.1) max-age directive, which itself is a
// component of the Cache-Control response header
nsresult
nsHttpResponseHead::GetMaxAgeValue(PRUint32 *result)
{
const char *val = PeekHeader(nsHttp::Cache_Control);
if (!val)
return NS_ERROR_NOT_AVAILABLE;
const char *p = PL_strcasestr(val, "max-age=");
if (!p)
return NS_ERROR_NOT_AVAILABLE;
*result = (PRUint32) atoi(p + 8);
return NS_OK;
}
//-----------------------------------------------------------------------------
// nsHttpResponseHead <private>
//-----------------------------------------------------------------------------
@ -462,6 +506,8 @@ nsHttpResponseHead::ParseVersion(const char *str)
{
// Parse HTTP-Version:: "HTTP" "/" 1*DIGIT "." 1*DIGIT
LOG(("nsHttpResponseHead::ParseVersion [version=%s]\n", str));
// make sure we have HTTP at the beginning
if (PL_strncasecmp(str, "HTTP", 4) != 0) {
LOG(("looks like a HTTP/0.9 response\n"));
@ -551,46 +597,3 @@ nsHttpResponseHead::ParseContentType(char *type)
return NS_OK;
}
nsresult
nsHttpResponseHead::ParseDateHeader(nsHttpAtom header, PRUint32 *result)
{
const char *val = PeekHeader(header);
if (!val)
return NS_ERROR_NOT_AVAILABLE;
PRTime time;
PRStatus st = PR_ParseTimeString(val, PR_TRUE, &time);
if (st != PR_SUCCESS)
return NS_ERROR_NOT_AVAILABLE;
*result = PRTimeToSeconds(time);
return NS_OK;
}
nsresult
nsHttpResponseHead::GetAgeValue(PRUint32 *result)
{
const char *val = PeekHeader(nsHttp::Age);
if (!val)
return NS_ERROR_NOT_AVAILABLE;
*result = (PRUint32) atoi(val);
return NS_OK;
}
// Return the value of the (HTTP 1.1) max-age directive, which itself is a
// component of the Cache-Control response header
nsresult nsHttpResponseHead::GetMaxAgeValue(PRUint32 *result)
{
const char *val = PeekHeader(nsHttp::Cache_Control);
if (!val)
return NS_ERROR_NOT_AVAILABLE;
const char *p = PL_strcasestr(val, "max-age=");
if (!p)
return NS_ERROR_NOT_AVAILABLE;
*result = (PRUint32) atoi(p + 8);
return NS_OK;
}

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

@ -34,7 +34,30 @@
#include "plevent.h"
//-----------------------------------------------------------------------------
// nsHttpTransaction
// helpers
//-----------------------------------------------------------------------------
static char *
LocateHttpStart(char *buf, PRUint32 len)
{
// if we have received less than 4 bytes of data, then we'll have to
// just accept a partial match, which may not be correct.
if (len < 4)
return (PL_strncasecmp(buf, "HTTP", len) == 0) ? buf : 0;
// PL_strncasestr would be perfect for this, but unfortunately bug 96571
// prevents its use here.
while (len >= 4) {
if (PL_strncasecmp(buf, "HTTP", 4) == 0)
return buf;
buf++;
len--;
}
return 0;
}
//-----------------------------------------------------------------------------
// nsHttpTransaction <public>
//-----------------------------------------------------------------------------
nsHttpTransaction::nsHttpTransaction(nsIStreamListener *listener,
@ -250,6 +273,10 @@ nsHttpTransaction::OnStopTransaction(nsresult status)
return NS_OK;
}
//-----------------------------------------------------------------------------
// nsHttpTransaction <private>
//-----------------------------------------------------------------------------
void
nsHttpTransaction::ParseLine(char *line)
{
@ -326,15 +353,22 @@ nsHttpTransaction::ParseHead(char *buf,
// if we don't have a status line and the line buf is empty, then
// this must be the first time we've been called.
if (!mHaveStatusLine && mLineBuf.IsEmpty() &&
PL_strncasecmp(buf, "HTTP", PR_MIN(count, 4)) != 0) {
// XXX this check may fail for certain 0.9 content if we haven't
// received at least 4 bytes of data.
if (!mHaveStatusLine && mLineBuf.IsEmpty()) {
// tolerate some junk before the status line
char *p = LocateHttpStart(buf, PR_MIN(count, 32));
if (!p) {
mResponseHead->ParseStatusLine("");
mHaveStatusLine = PR_TRUE;
mHaveAllHeaders = PR_TRUE;
return NS_OK;
}
if (p > buf) {
// skip over the junk
*countRead = p - buf;
count -= *countRead;
buf = p;
}
}
// otherwise we can assume that we don't have a HTTP/0.9 response.
while ((eol = NS_STATIC_CAST(char *, memchr(buf, '\n', count - *countRead))) != nsnull) {
@ -735,7 +769,7 @@ nsHttpTransaction::Read(char *buf, PRUint32 count, PRUint32 *bytesWritten)
LOG(("nsHttpTransaction: mSource->Read() returned [rv=%x]\n", rv));
return rv;
}
if (NS_SUCCEEDED(rv) && (*bytesWritten == 0)) {
if (*bytesWritten == 0) {
LOG(("nsHttpTransaction: reached EOF\n"));
if (!mHaveStatusLine) {
// we've read nothing from the socket...