bug #87534. multipart/mixed handler doesn't parse content-type handler properly. r=dougt, sr=darin

This commit is contained in:
blizzard%redhat.com 2001-07-02 19:35:48 +00:00
Родитель be3a8988bc
Коммит 4517d2cbae
3 изменённых файлов: 57 добавлений и 1 удалений

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

@ -486,6 +486,9 @@ nsHttpResponseHead::ParseVersion(const char *str)
mVersion = NS_HTTP_VERSION_1_0;
}
// This code is duplicated in nsMultiMixedConv.cpp. If you change it
// here, change it there, too!
nsresult
nsHttpResponseHead::ParseContentType(char *type)
{

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

@ -827,7 +827,9 @@ nsMultiMixedConv::ParseHeaders(nsIChannel *aChannel, char *&aPtr,
// examine header
if (headerStr.EqualsIgnoreCase("content-type")) {
mContentType = headerVal;
char *tmpString = headerVal.ToNewCString();
ParseContentType(tmpString);
nsCRT::free(tmpString);
} else if (headerStr.EqualsIgnoreCase("content-length")) {
mContentLength = atoi(headerVal.get());
} else if (headerStr.EqualsIgnoreCase("set-cookie")) {
@ -884,6 +886,55 @@ nsMultiMixedConv::ParseHeaders(nsIChannel *aChannel, char *&aPtr,
return rv;
}
// This code is duplicated in nsHttpResponseHead.cpp. If you change it
// here, change it there, too!
nsresult
nsMultiMixedConv::ParseContentType(char *type)
{
char *p = PL_strchr(type, '(');
if (p)
// we don't care about comments (although they are invalid here)
*p = 0;
// check if the content-type has additional fields...
if ((p = PL_strchr(type, ';')) != nsnull) {
char *p2, *p3;
// is there a charset field?
if ((p2 = PL_strcasestr(p, "charset=")) != nsnull) {
p2 += 8;
// check end of charset parameter
if ((p3 = PL_strchr(p2, ';')) == nsnull)
p3 = p2 + PL_strlen(p2);
// trim any trailing whitespace
do {
--p3;
} while ((*p3 == ' ') || (*p3 == '\t'));
*++p3 = 0; // overwrite first char after the charset field
mContentCharset = p2;
}
}
else
p = type + PL_strlen(type);
// trim any trailing whitespace
while (--p >= type && ((*p == ' ') || (*p == '\t')))
;
*++p = 0; // overwrite first char after the media type
// force the content-type to lowercase
while (--p >= type)
*p = nsCRT::ToLower(*p);
mContentType = type;
return NS_OK;
}
char *
nsMultiMixedConv::FindToken(char *aCursor, PRUint32 aLen) {
// strnstr without looking for null termination

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

@ -92,6 +92,7 @@ protected:
nsresult SendData(char *aBuffer, PRUint32 aLen);
nsresult ParseHeaders(nsIChannel *aChannel, char *&aPtr,
PRUint32 &aLen, PRBool *_retval);
nsresult ParseContentType(char *type);
PRInt32 PushOverLine(char *&aPtr, PRUint32 &aLen);
char *FindToken(char *aCursor, PRUint32 aLen);
nsresult BufferData(char *aData, PRUint32 aLen);
@ -108,6 +109,7 @@ protected:
// one channel per part.
nsCOMPtr<nsISupports> mContext;
nsCString mContentType;
nsCString mContentCharset;
PRInt32 mContentLength;
char *mBuffer;