2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Google Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "ResourceResponseBase.h"
30 #include "HTTPParsers.h"
31 #include "PlatformMemoryInstrumentation.h"
32 #include "ResourceResponse.h"
33 #include <wtf/CurrentTime.h>
34 #include <wtf/MathExtras.h>
35 #include <wtf/MemoryInstrumentationHashMap.h>
36 #include <wtf/StdLibExtras.h>
42 static void parseCacheHeader(const String& header, Vector<pair<String, String> >& result);
44 inline const ResourceResponse& ResourceResponseBase::asResourceResponse() const
46 return *static_cast<const ResourceResponse*>(this);
49 ResourceResponseBase::ResourceResponseBase()
50 : m_expectedContentLength(0)
52 , m_lastModifiedDate(0)
55 , m_connectionReused(false)
57 , m_haveParsedCacheControlHeader(false)
58 , m_haveParsedAgeHeader(false)
59 , m_haveParsedDateHeader(false)
60 , m_haveParsedExpiresHeader(false)
61 , m_haveParsedLastModifiedHeader(false)
62 , m_cacheControlContainsNoCache(false)
63 , m_cacheControlContainsNoStore(false)
64 , m_cacheControlContainsMustRevalidate(false)
65 , m_cacheControlMaxAge(0.0)
73 ResourceResponseBase::ResourceResponseBase(const KURL& url, const String& mimeType, long long expectedLength, const String& textEncodingName, const String& filename)
75 , m_mimeType(mimeType)
76 , m_expectedContentLength(expectedLength)
77 , m_textEncodingName(textEncodingName)
78 , m_suggestedFilename(filename)
80 , m_lastModifiedDate(0)
83 , m_connectionReused(false)
85 , m_haveParsedCacheControlHeader(false)
86 , m_haveParsedAgeHeader(false)
87 , m_haveParsedDateHeader(false)
88 , m_haveParsedExpiresHeader(false)
89 , m_haveParsedLastModifiedHeader(false)
90 , m_cacheControlContainsNoCache(false)
91 , m_cacheControlContainsNoStore(false)
92 , m_cacheControlContainsMustRevalidate(false)
93 , m_cacheControlMaxAge(0.0)
101 PassOwnPtr<ResourceResponse> ResourceResponseBase::adopt(PassOwnPtr<CrossThreadResourceResponseData> data)
103 OwnPtr<ResourceResponse> response = adoptPtr(new ResourceResponse);
104 response->setURL(data->m_url);
105 response->setMimeType(data->m_mimeType);
106 response->setExpectedContentLength(data->m_expectedContentLength);
107 response->setTextEncodingName(data->m_textEncodingName);
108 response->setSuggestedFilename(data->m_suggestedFilename);
110 response->setHTTPStatusCode(data->m_httpStatusCode);
111 response->setHTTPStatusText(data->m_httpStatusText);
113 response->lazyInit(CommonAndUncommonFields);
114 response->m_httpHeaderFields.adopt(data->m_httpHeaders.release());
115 response->setLastModifiedDate(data->m_lastModifiedDate);
116 response->setResourceLoadTiming(data->m_resourceLoadTiming.release());
117 response->doPlatformAdopt(data);
118 return response.release();
121 PassOwnPtr<CrossThreadResourceResponseData> ResourceResponseBase::copyData() const
123 OwnPtr<CrossThreadResourceResponseData> data = adoptPtr(new CrossThreadResourceResponseData);
124 data->m_url = url().copy();
125 data->m_mimeType = mimeType().isolatedCopy();
126 data->m_expectedContentLength = expectedContentLength();
127 data->m_textEncodingName = textEncodingName().isolatedCopy();
128 data->m_suggestedFilename = suggestedFilename().isolatedCopy();
129 data->m_httpStatusCode = httpStatusCode();
130 data->m_httpStatusText = httpStatusText().isolatedCopy();
131 data->m_httpHeaders = httpHeaderFields().copyData();
132 data->m_lastModifiedDate = lastModifiedDate();
133 if (m_resourceLoadTiming)
134 data->m_resourceLoadTiming = m_resourceLoadTiming->deepCopy();
135 return asResourceResponse().doPlatformCopyData(data.release());
138 bool ResourceResponseBase::isHTTP() const
140 lazyInit(CommonFieldsOnly);
142 String protocol = m_url.protocol();
144 return equalIgnoringCase(protocol, "http") || equalIgnoringCase(protocol, "https");
147 const KURL& ResourceResponseBase::url() const
149 lazyInit(CommonFieldsOnly);
154 void ResourceResponseBase::setURL(const KURL& url)
156 lazyInit(CommonFieldsOnly);
161 // FIXME: Should invalidate or update platform response if present.
164 const String& ResourceResponseBase::mimeType() const
166 lazyInit(CommonFieldsOnly);
171 void ResourceResponseBase::setMimeType(const String& mimeType)
173 lazyInit(CommonFieldsOnly);
176 // FIXME: MIME type is determined by HTTP Content-Type header. We should update the header, so that it doesn't disagree with m_mimeType.
177 m_mimeType = mimeType;
179 // FIXME: Should invalidate or update platform response if present.
182 long long ResourceResponseBase::expectedContentLength() const
184 lazyInit(CommonFieldsOnly);
186 return m_expectedContentLength;
189 void ResourceResponseBase::setExpectedContentLength(long long expectedContentLength)
191 lazyInit(CommonFieldsOnly);
194 // FIXME: Content length is determined by HTTP Content-Length header. We should update the header, so that it doesn't disagree with m_expectedContentLength.
195 m_expectedContentLength = expectedContentLength;
197 // FIXME: Should invalidate or update platform response if present.
200 const String& ResourceResponseBase::textEncodingName() const
202 lazyInit(CommonFieldsOnly);
204 return m_textEncodingName;
207 void ResourceResponseBase::setTextEncodingName(const String& encodingName)
209 lazyInit(CommonFieldsOnly);
212 // FIXME: Text encoding is determined by HTTP Content-Type header. We should update the header, so that it doesn't disagree with m_textEncodingName.
213 m_textEncodingName = encodingName;
215 // FIXME: Should invalidate or update platform response if present.
218 // FIXME should compute this on the fly
219 const String& ResourceResponseBase::suggestedFilename() const
223 return m_suggestedFilename;
226 void ResourceResponseBase::setSuggestedFilename(const String& suggestedName)
231 // FIXME: Suggested file name is calculated based on other headers. There should not be a setter for it.
232 m_suggestedFilename = suggestedName;
234 // FIXME: Should invalidate or update platform response if present.
237 int ResourceResponseBase::httpStatusCode() const
239 lazyInit(CommonFieldsOnly);
241 return m_httpStatusCode;
244 void ResourceResponseBase::setHTTPStatusCode(int statusCode)
246 lazyInit(CommonFieldsOnly);
248 m_httpStatusCode = statusCode;
250 // FIXME: Should invalidate or update platform response if present.
253 const String& ResourceResponseBase::httpStatusText() const
255 lazyInit(CommonAndUncommonFields);
257 return m_httpStatusText;
260 void ResourceResponseBase::setHTTPStatusText(const String& statusText)
262 lazyInit(CommonAndUncommonFields);
264 m_httpStatusText = statusText;
266 // FIXME: Should invalidate or update platform response if present.
269 String ResourceResponseBase::httpHeaderField(const AtomicString& name) const
271 lazyInit(CommonFieldsOnly);
273 // If we already have the header, just return it instead of consuming memory by grabing all headers.
274 String value = m_httpHeaderFields.get(name);
275 if (!value.isEmpty())
278 lazyInit(CommonAndUncommonFields);
280 return m_httpHeaderFields.get(name);
283 String ResourceResponseBase::httpHeaderField(const char* name) const
285 lazyInit(CommonFieldsOnly);
287 // If we already have the header, just return it instead of consuming memory by grabing all headers.
288 String value = m_httpHeaderFields.get(name);
289 if (!value.isEmpty())
292 lazyInit(CommonAndUncommonFields);
294 return m_httpHeaderFields.get(name);
297 void ResourceResponseBase::updateHeaderParsedState(const AtomicString& name)
299 DEFINE_STATIC_LOCAL(const AtomicString, ageHeader, ("age", AtomicString::ConstructFromLiteral));
300 DEFINE_STATIC_LOCAL(const AtomicString, cacheControlHeader, ("cache-control", AtomicString::ConstructFromLiteral));
301 DEFINE_STATIC_LOCAL(const AtomicString, dateHeader, ("date", AtomicString::ConstructFromLiteral));
302 DEFINE_STATIC_LOCAL(const AtomicString, expiresHeader, ("expires", AtomicString::ConstructFromLiteral));
303 DEFINE_STATIC_LOCAL(const AtomicString, lastModifiedHeader, ("last-modified", AtomicString::ConstructFromLiteral));
304 DEFINE_STATIC_LOCAL(const AtomicString, pragmaHeader, ("pragma", AtomicString::ConstructFromLiteral));
306 if (equalIgnoringCase(name, ageHeader))
307 m_haveParsedAgeHeader = false;
308 else if (equalIgnoringCase(name, cacheControlHeader) || equalIgnoringCase(name, pragmaHeader))
309 m_haveParsedCacheControlHeader = false;
310 else if (equalIgnoringCase(name, dateHeader))
311 m_haveParsedDateHeader = false;
312 else if (equalIgnoringCase(name, expiresHeader))
313 m_haveParsedExpiresHeader = false;
314 else if (equalIgnoringCase(name, lastModifiedHeader))
315 m_haveParsedLastModifiedHeader = false;
318 void ResourceResponseBase::setHTTPHeaderField(const AtomicString& name, const String& value)
320 lazyInit(CommonAndUncommonFields);
322 updateHeaderParsedState(name);
324 m_httpHeaderFields.set(name, value);
326 // FIXME: Should invalidate or update platform response if present.
329 void ResourceResponseBase::addHTTPHeaderField(const AtomicString& name, const String& value)
331 lazyInit(CommonAndUncommonFields);
333 updateHeaderParsedState(name);
335 HTTPHeaderMap::AddResult result = m_httpHeaderFields.add(name, value);
336 if (!result.isNewEntry)
337 result.iterator->value.append(", " + value);
340 const HTTPHeaderMap& ResourceResponseBase::httpHeaderFields() const
342 lazyInit(CommonAndUncommonFields);
344 return m_httpHeaderFields;
347 void ResourceResponseBase::parseCacheControlDirectives() const
349 ASSERT(!m_haveParsedCacheControlHeader);
351 lazyInit(CommonFieldsOnly);
353 m_haveParsedCacheControlHeader = true;
355 m_cacheControlContainsMustRevalidate = false;
356 m_cacheControlContainsNoCache = false;
357 m_cacheControlMaxAge = numeric_limits<double>::quiet_NaN();
359 DEFINE_STATIC_LOCAL(const AtomicString, cacheControlString, ("cache-control", AtomicString::ConstructFromLiteral));
360 DEFINE_STATIC_LOCAL(const AtomicString, noCacheDirective, ("no-cache", AtomicString::ConstructFromLiteral));
361 DEFINE_STATIC_LOCAL(const AtomicString, noStoreDirective, ("no-store", AtomicString::ConstructFromLiteral));
362 DEFINE_STATIC_LOCAL(const AtomicString, mustRevalidateDirective, ("must-revalidate", AtomicString::ConstructFromLiteral));
363 DEFINE_STATIC_LOCAL(const AtomicString, maxAgeDirective, ("max-age", AtomicString::ConstructFromLiteral));
365 String cacheControlValue = m_httpHeaderFields.get(cacheControlString);
366 if (!cacheControlValue.isEmpty()) {
367 Vector<pair<String, String> > directives;
368 parseCacheHeader(cacheControlValue, directives);
370 size_t directivesSize = directives.size();
371 for (size_t i = 0; i < directivesSize; ++i) {
372 // RFC2616 14.9.1: A no-cache directive with a value is only meaningful for proxy caches.
373 // It should be ignored by a browser level cache.
374 if (equalIgnoringCase(directives[i].first, noCacheDirective) && directives[i].second.isEmpty())
375 m_cacheControlContainsNoCache = true;
376 else if (equalIgnoringCase(directives[i].first, noStoreDirective))
377 m_cacheControlContainsNoStore = true;
378 else if (equalIgnoringCase(directives[i].first, mustRevalidateDirective))
379 m_cacheControlContainsMustRevalidate = true;
380 else if (equalIgnoringCase(directives[i].first, maxAgeDirective)) {
381 if (!std::isnan(m_cacheControlMaxAge)) {
382 // First max-age directive wins if there are multiple ones.
386 double maxAge = directives[i].second.toDouble(&ok);
388 m_cacheControlMaxAge = maxAge;
393 if (!m_cacheControlContainsNoCache) {
394 // Handle Pragma: no-cache
395 // This is deprecated and equivalent to Cache-control: no-cache
396 // Don't bother tokenizing the value, it is not important
397 DEFINE_STATIC_LOCAL(const AtomicString, pragmaHeader, ("pragma", AtomicString::ConstructFromLiteral));
398 String pragmaValue = m_httpHeaderFields.get(pragmaHeader);
400 m_cacheControlContainsNoCache = pragmaValue.lower().contains(noCacheDirective);
404 bool ResourceResponseBase::cacheControlContainsNoCache() const
406 if (!m_haveParsedCacheControlHeader)
407 parseCacheControlDirectives();
408 return m_cacheControlContainsNoCache;
411 bool ResourceResponseBase::cacheControlContainsNoStore() const
413 if (!m_haveParsedCacheControlHeader)
414 parseCacheControlDirectives();
415 return m_cacheControlContainsNoStore;
418 bool ResourceResponseBase::cacheControlContainsMustRevalidate() const
420 if (!m_haveParsedCacheControlHeader)
421 parseCacheControlDirectives();
422 return m_cacheControlContainsMustRevalidate;
425 bool ResourceResponseBase::hasCacheValidatorFields() const
427 lazyInit(CommonFieldsOnly);
429 DEFINE_STATIC_LOCAL(const AtomicString, lastModifiedHeader, ("last-modified", AtomicString::ConstructFromLiteral));
430 DEFINE_STATIC_LOCAL(const AtomicString, eTagHeader, ("etag", AtomicString::ConstructFromLiteral));
431 return !m_httpHeaderFields.get(lastModifiedHeader).isEmpty() || !m_httpHeaderFields.get(eTagHeader).isEmpty();
434 double ResourceResponseBase::cacheControlMaxAge() const
436 if (!m_haveParsedCacheControlHeader)
437 parseCacheControlDirectives();
438 return m_cacheControlMaxAge;
441 static double parseDateValueInHeader(const HTTPHeaderMap& headers, const AtomicString& headerName)
443 String headerValue = headers.get(headerName);
444 if (headerValue.isEmpty())
445 return std::numeric_limits<double>::quiet_NaN();
446 // This handles all date formats required by RFC2616:
447 // Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
448 // Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
449 // Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
450 double dateInMilliseconds = parseDate(headerValue);
451 if (!std::isfinite(dateInMilliseconds))
452 return std::numeric_limits<double>::quiet_NaN();
453 return dateInMilliseconds / 1000;
456 double ResourceResponseBase::date() const
458 lazyInit(CommonFieldsOnly);
460 if (!m_haveParsedDateHeader) {
461 DEFINE_STATIC_LOCAL(const AtomicString, headerName, ("date", AtomicString::ConstructFromLiteral));
462 m_date = parseDateValueInHeader(m_httpHeaderFields, headerName);
463 m_haveParsedDateHeader = true;
468 double ResourceResponseBase::age() const
470 lazyInit(CommonFieldsOnly);
472 if (!m_haveParsedAgeHeader) {
473 DEFINE_STATIC_LOCAL(const AtomicString, headerName, ("age", AtomicString::ConstructFromLiteral));
474 String headerValue = m_httpHeaderFields.get(headerName);
476 m_age = headerValue.toDouble(&ok);
478 m_age = std::numeric_limits<double>::quiet_NaN();
479 m_haveParsedAgeHeader = true;
484 double ResourceResponseBase::expires() const
486 lazyInit(CommonFieldsOnly);
488 if (!m_haveParsedExpiresHeader) {
489 DEFINE_STATIC_LOCAL(const AtomicString, headerName, ("expires", AtomicString::ConstructFromLiteral));
490 m_expires = parseDateValueInHeader(m_httpHeaderFields, headerName);
491 m_haveParsedExpiresHeader = true;
496 double ResourceResponseBase::lastModified() const
498 lazyInit(CommonFieldsOnly);
500 if (!m_haveParsedLastModifiedHeader) {
501 DEFINE_STATIC_LOCAL(const AtomicString, headerName, ("last-modified", AtomicString::ConstructFromLiteral));
502 m_lastModified = parseDateValueInHeader(m_httpHeaderFields, headerName);
503 m_haveParsedLastModifiedHeader = true;
505 return m_lastModified;
508 bool ResourceResponseBase::isAttachment() const
510 lazyInit(CommonAndUncommonFields);
512 DEFINE_STATIC_LOCAL(const AtomicString, headerName, ("content-disposition", AtomicString::ConstructFromLiteral));
513 String value = m_httpHeaderFields.get(headerName);
514 size_t loc = value.find(';');
516 value = value.left(loc);
517 value = value.stripWhiteSpace();
518 DEFINE_STATIC_LOCAL(const AtomicString, attachmentString, ("attachment", AtomicString::ConstructFromLiteral));
519 return equalIgnoringCase(value, attachmentString);
522 void ResourceResponseBase::setLastModifiedDate(time_t lastModifiedDate)
524 lazyInit(CommonAndUncommonFields);
526 m_lastModifiedDate = lastModifiedDate;
528 // FIXME: Should invalidate or update platform response if present.
531 time_t ResourceResponseBase::lastModifiedDate() const
533 lazyInit(CommonAndUncommonFields);
535 return m_lastModifiedDate;
538 bool ResourceResponseBase::wasCached() const
540 lazyInit(CommonAndUncommonFields);
545 void ResourceResponseBase::setWasCached(bool value)
550 bool ResourceResponseBase::connectionReused() const
552 lazyInit(CommonAndUncommonFields);
554 return m_connectionReused;
557 void ResourceResponseBase::setConnectionReused(bool connectionReused)
559 lazyInit(CommonAndUncommonFields);
561 m_connectionReused = connectionReused;
564 unsigned ResourceResponseBase::connectionID() const
566 lazyInit(CommonAndUncommonFields);
568 return m_connectionID;
571 void ResourceResponseBase::setConnectionID(unsigned connectionID)
573 lazyInit(CommonAndUncommonFields);
575 m_connectionID = connectionID;
578 ResourceLoadTiming* ResourceResponseBase::resourceLoadTiming() const
580 lazyInit(CommonAndUncommonFields);
582 return m_resourceLoadTiming.get();
585 void ResourceResponseBase::setResourceLoadTiming(PassRefPtr<ResourceLoadTiming> resourceLoadTiming)
587 lazyInit(CommonAndUncommonFields);
589 m_resourceLoadTiming = resourceLoadTiming;
592 PassRefPtr<ResourceLoadInfo> ResourceResponseBase::resourceLoadInfo() const
594 lazyInit(CommonAndUncommonFields);
596 return m_resourceLoadInfo.get();
599 void ResourceResponseBase::setResourceLoadInfo(PassRefPtr<ResourceLoadInfo> loadInfo)
601 lazyInit(CommonAndUncommonFields);
603 m_resourceLoadInfo = loadInfo;
606 void ResourceResponseBase::lazyInit(InitLevel initLevel) const
608 const_cast<ResourceResponse*>(static_cast<const ResourceResponse*>(this))->platformLazyInit(initLevel);
611 void ResourceResponseBase::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
613 MemoryClassInfo info(memoryObjectInfo, this, PlatformMemoryTypes::Loader);
614 info.addMember(m_url, "url");
615 info.addMember(m_mimeType, "mimeType");
616 info.addMember(m_textEncodingName, "textEncodingName");
617 info.addMember(m_suggestedFilename, "suggestedFilename");
618 info.addMember(m_httpStatusText, "httpStatusText");
619 info.addMember(m_httpHeaderFields, "httpHeaderFields");
620 info.addMember(m_resourceLoadTiming, "resourceLoadTiming");
621 info.addMember(m_resourceLoadInfo, "resourceLoadInfo");
624 bool ResourceResponseBase::compare(const ResourceResponse& a, const ResourceResponse& b)
626 if (a.isNull() != b.isNull())
628 if (a.url() != b.url())
630 if (a.mimeType() != b.mimeType())
632 if (a.expectedContentLength() != b.expectedContentLength())
634 if (a.textEncodingName() != b.textEncodingName())
636 if (a.suggestedFilename() != b.suggestedFilename())
638 if (a.httpStatusCode() != b.httpStatusCode())
640 if (a.httpStatusText() != b.httpStatusText())
642 if (a.httpHeaderFields() != b.httpHeaderFields())
644 if (a.resourceLoadTiming() && b.resourceLoadTiming() && *a.resourceLoadTiming() == *b.resourceLoadTiming())
645 return ResourceResponse::platformCompare(a, b);
646 if (a.resourceLoadTiming() != b.resourceLoadTiming())
648 return ResourceResponse::platformCompare(a, b);
651 static bool isCacheHeaderSeparator(UChar c)
653 // See RFC 2616, Section 2.2
680 static bool isControlCharacter(UChar c)
682 return c < ' ' || c == 127;
685 static inline String trimToNextSeparator(const String& str)
687 return str.substring(0, str.find(isCacheHeaderSeparator));
690 static void parseCacheHeader(const String& header, Vector<pair<String, String> >& result)
692 const String safeHeader = header.removeCharacters(isControlCharacter);
693 unsigned max = safeHeader.length();
694 for (unsigned pos = 0; pos < max; /* pos incremented in loop */) {
695 size_t nextCommaPosition = safeHeader.find(',', pos);
696 size_t nextEqualSignPosition = safeHeader.find('=', pos);
697 if (nextEqualSignPosition != notFound && (nextEqualSignPosition < nextCommaPosition || nextCommaPosition == notFound)) {
698 // Get directive name, parse right hand side of equal sign, then add to map
699 String directive = trimToNextSeparator(safeHeader.substring(pos, nextEqualSignPosition - pos).stripWhiteSpace());
700 pos += nextEqualSignPosition - pos + 1;
702 String value = safeHeader.substring(pos, max - pos).stripWhiteSpace();
703 if (value[0] == '"') {
704 // The value is a quoted string
705 size_t nextDoubleQuotePosition = value.find('"', 1);
706 if (nextDoubleQuotePosition != notFound) {
707 // Store the value as a quoted string without quotes
708 result.append(pair<String, String>(directive, value.substring(1, nextDoubleQuotePosition - 1).stripWhiteSpace()));
709 pos += (safeHeader.find('"', pos) - pos) + nextDoubleQuotePosition + 1;
710 // Move past next comma, if there is one
711 size_t nextCommaPosition2 = safeHeader.find(',', pos);
712 if (nextCommaPosition2 != notFound)
713 pos += nextCommaPosition2 - pos + 1;
715 return; // Parse error if there is anything left with no comma
717 // Parse error; just use the rest as the value
718 result.append(pair<String, String>(directive, trimToNextSeparator(value.substring(1, value.length() - 1).stripWhiteSpace())));
722 // The value is a token until the next comma
723 size_t nextCommaPosition2 = value.find(',');
724 if (nextCommaPosition2 != notFound) {
725 // The value is delimited by the next comma
726 result.append(pair<String, String>(directive, trimToNextSeparator(value.substring(0, nextCommaPosition2).stripWhiteSpace())));
727 pos += (safeHeader.find(',', pos) - pos) + 1;
729 // The rest is the value; no change to value needed
730 result.append(pair<String, String>(directive, trimToNextSeparator(value)));
734 } else if (nextCommaPosition != notFound && (nextCommaPosition < nextEqualSignPosition || nextEqualSignPosition == notFound)) {
735 // Add directive to map with empty string as value
736 result.append(pair<String, String>(trimToNextSeparator(safeHeader.substring(pos, nextCommaPosition - pos).stripWhiteSpace()), ""));
737 pos += nextCommaPosition - pos + 1;
739 // Add last directive to map with empty string as value
740 result.append(pair<String, String>(trimToNextSeparator(safeHeader.substring(pos, max - pos).stripWhiteSpace()), ""));