diff options
Diffstat (limited to 'WebCore/platform/network/HTTPParsers.cpp')
-rw-r--r-- | WebCore/platform/network/HTTPParsers.cpp | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/WebCore/platform/network/HTTPParsers.cpp b/WebCore/platform/network/HTTPParsers.cpp index f36e9fb..e57401e 100644 --- a/WebCore/platform/network/HTTPParsers.cpp +++ b/WebCore/platform/network/HTTPParsers.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) - * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. * Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,11 @@ #include "config.h" #include "HTTPParsers.h" +#include "CString.h" #include "PlatformString.h" +#include <wtf/DateMath.h> + +using namespace WTF; namespace WebCore { @@ -40,12 +44,13 @@ static inline bool skipWhiteSpace(const String& str, int& pos, bool fromHttpEqui { int len = str.length(); - if (fromHttpEquivMeta) + if (fromHttpEquivMeta) { while (pos != len && str[pos] <= ' ') ++pos; - else + } else { while (pos != len && (str[pos] == '\t' || str[pos] == ' ')) ++pos; + } return pos != len; } @@ -102,6 +107,11 @@ bool parseHTTPRefresh(const String& refresh, bool fromHttpEquivMeta, double& del } } +double parseDate(const String& value) +{ + return parseDateFromNullTerminatedCharacters(value.utf8().data()); +} + String filenameFromHTTPContentDisposition(const String& value) { Vector<String> keyValuePairs; @@ -135,14 +145,33 @@ String extractMIMETypeFromMediaType(const String& mediaType) Vector<UChar, 64> mimeType; unsigned length = mediaType.length(); mimeType.reserveCapacity(length); - for (unsigned offset = 0; offset < length; offset++) { - UChar c = mediaType[offset]; + for (unsigned i = 0; i < length; i++) { + UChar c = mediaType[i]; + if (c == ';') break; - else if (isSpaceOrNewline(c)) // FIXME: This seems wrong, " " is an invalid MIME type character according to RFC 2045. bug 8644 + + // While RFC 2616 does not allow it, other browsers allow multiple values in the HTTP media + // type header field, Content-Type. In such cases, the media type string passed here may contain + // the multiple values separated by commas. For now, this code ignores text after the first comma, + // which prevents it from simply failing to parse such types altogether. Later for better + // compatibility we could consider using the first or last valid MIME type instead. + // See https://bugs.webkit.org/show_bug.cgi?id=25352 for more discussion. + if (c == ',') + break; + + // FIXME: The following is not correct. RFC 2616 allows linear white space before and + // after the MIME type, but not within the MIME type itself. And linear white space + // includes only a few specific ASCII characters; a small subset of isSpaceOrNewline. + // See https://bugs.webkit.org/show_bug.cgi?id=8644 for a bug tracking part of this. + if (isSpaceOrNewline(c)) continue; + mimeType.append(c); } + + if (mimeType.size() == length) + return mediaType; return String(mimeType.data(), mimeType.size()); } |