OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. | |
3 * Copyright (C) 2009 Google Inc. All rights reserved. | |
4 * | |
5 * Redistribution and use in source and binary forms, with or without | |
6 * modification, are permitted provided that the following conditions | |
7 * are met: | |
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. | |
13 * | |
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. | |
25 */ | |
26 | |
27 #include "config.h" | |
28 #include "core/platform/network/ResourceResponse.h" | |
29 | |
30 #include "platform/network/HTTPParsers.h" | |
31 #include "core/platform/network/ResourceResponse.h" | |
32 #include "wtf/CurrentTime.h" | |
33 #include "wtf/MathExtras.h" | |
34 #include "wtf/StdLibExtras.h" | |
35 | |
36 namespace WebCore { | |
37 | |
38 static void parseCacheHeader(const String& header, Vector<pair<String, String> >
& result); | |
39 | |
40 ResourceResponse::ResourceResponse() | |
41 : m_expectedContentLength(0) | |
42 , m_httpStatusCode(0) | |
43 , m_lastModifiedDate(0) | |
44 , m_wasCached(false) | |
45 , m_connectionID(0) | |
46 , m_connectionReused(false) | |
47 , m_isNull(true) | |
48 , m_haveParsedCacheControlHeader(false) | |
49 , m_haveParsedAgeHeader(false) | |
50 , m_haveParsedDateHeader(false) | |
51 , m_haveParsedExpiresHeader(false) | |
52 , m_haveParsedLastModifiedHeader(false) | |
53 , m_cacheControlContainsNoCache(false) | |
54 , m_cacheControlContainsNoStore(false) | |
55 , m_cacheControlContainsMustRevalidate(false) | |
56 , m_cacheControlMaxAge(0.0) | |
57 , m_age(0.0) | |
58 , m_date(0.0) | |
59 , m_expires(0.0) | |
60 , m_lastModified(0.0) | |
61 , m_httpVersion(Unknown) | |
62 , m_appCacheID(0) | |
63 , m_isMultipartPayload(false) | |
64 , m_wasFetchedViaSPDY(false) | |
65 , m_wasNpnNegotiated(false) | |
66 , m_wasAlternateProtocolAvailable(false) | |
67 , m_wasFetchedViaProxy(false) | |
68 , m_responseTime(0) | |
69 , m_remotePort(0) | |
70 { | |
71 } | |
72 | |
73 ResourceResponse::ResourceResponse(const KURL& url, const AtomicString& mimeType
, long long expectedLength, const AtomicString& textEncodingName, const String&
filename) | |
74 : m_url(url) | |
75 , m_mimeType(mimeType) | |
76 , m_expectedContentLength(expectedLength) | |
77 , m_textEncodingName(textEncodingName) | |
78 , m_suggestedFilename(filename) | |
79 , m_httpStatusCode(0) | |
80 , m_lastModifiedDate(0) | |
81 , m_wasCached(false) | |
82 , m_connectionID(0) | |
83 , m_connectionReused(false) | |
84 , m_isNull(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) | |
94 , m_age(0.0) | |
95 , m_date(0.0) | |
96 , m_expires(0.0) | |
97 , m_lastModified(0.0) | |
98 , m_httpVersion(Unknown) | |
99 , m_appCacheID(0) | |
100 , m_isMultipartPayload(false) | |
101 , m_wasFetchedViaSPDY(false) | |
102 , m_wasNpnNegotiated(false) | |
103 , m_wasAlternateProtocolAvailable(false) | |
104 , m_wasFetchedViaProxy(false) | |
105 , m_responseTime(0) | |
106 , m_remotePort(0) | |
107 { | |
108 } | |
109 | |
110 PassOwnPtr<ResourceResponse> ResourceResponse::adopt(PassOwnPtr<CrossThreadResou
rceResponseData> data) | |
111 { | |
112 OwnPtr<ResourceResponse> response = adoptPtr(new ResourceResponse); | |
113 response->setURL(data->m_url); | |
114 response->setMimeType(data->m_mimeType); | |
115 response->setExpectedContentLength(data->m_expectedContentLength); | |
116 response->setTextEncodingName(data->m_textEncodingName); | |
117 response->setSuggestedFilename(data->m_suggestedFilename); | |
118 | |
119 response->setHTTPStatusCode(data->m_httpStatusCode); | |
120 response->setHTTPStatusText(data->m_httpStatusText); | |
121 | |
122 response->m_httpHeaderFields.adopt(data->m_httpHeaders.release()); | |
123 response->setLastModifiedDate(data->m_lastModifiedDate); | |
124 response->setResourceLoadTiming(data->m_resourceLoadTiming.release()); | |
125 response->m_securityInfo = data->m_securityInfo; | |
126 response->m_httpVersion = data->m_httpVersion; | |
127 response->m_appCacheID = data->m_appCacheID; | |
128 response->m_appCacheManifestURL = data->m_appCacheManifestURL.copy(); | |
129 response->m_isMultipartPayload = data->m_isMultipartPayload; | |
130 response->m_wasFetchedViaSPDY = data->m_wasFetchedViaSPDY; | |
131 response->m_wasNpnNegotiated = data->m_wasNpnNegotiated; | |
132 response->m_wasAlternateProtocolAvailable = data->m_wasAlternateProtocolAvai
lable; | |
133 response->m_wasFetchedViaProxy = data->m_wasFetchedViaProxy; | |
134 response->m_responseTime = data->m_responseTime; | |
135 response->m_remoteIPAddress = data->m_remoteIPAddress; | |
136 response->m_remotePort = data->m_remotePort; | |
137 response->m_downloadedFilePath = data->m_downloadedFilePath; | |
138 response->m_downloadedFileHandle = data->m_downloadedFileHandle; | |
139 | |
140 // Bug https://bugs.webkit.org/show_bug.cgi?id=60397 this doesn't support | |
141 // whatever values may be present in the opaque m_extraData structure. | |
142 | |
143 return response.release(); | |
144 } | |
145 | |
146 PassOwnPtr<CrossThreadResourceResponseData> ResourceResponse::copyData() const | |
147 { | |
148 OwnPtr<CrossThreadResourceResponseData> data = adoptPtr(new CrossThreadResou
rceResponseData); | |
149 data->m_url = url().copy(); | |
150 data->m_mimeType = mimeType().string().isolatedCopy(); | |
151 data->m_expectedContentLength = expectedContentLength(); | |
152 data->m_textEncodingName = textEncodingName().string().isolatedCopy(); | |
153 data->m_suggestedFilename = suggestedFilename().isolatedCopy(); | |
154 data->m_httpStatusCode = httpStatusCode(); | |
155 data->m_httpStatusText = httpStatusText().string().isolatedCopy(); | |
156 data->m_httpHeaders = httpHeaderFields().copyData(); | |
157 data->m_lastModifiedDate = lastModifiedDate(); | |
158 if (m_resourceLoadTiming) | |
159 data->m_resourceLoadTiming = m_resourceLoadTiming->deepCopy(); | |
160 data->m_securityInfo = CString(m_securityInfo.data(), m_securityInfo.length(
)); | |
161 data->m_httpVersion = m_httpVersion; | |
162 data->m_appCacheID = m_appCacheID; | |
163 data->m_appCacheManifestURL = m_appCacheManifestURL.copy(); | |
164 data->m_isMultipartPayload = m_isMultipartPayload; | |
165 data->m_wasFetchedViaSPDY = m_wasFetchedViaSPDY; | |
166 data->m_wasNpnNegotiated = m_wasNpnNegotiated; | |
167 data->m_wasAlternateProtocolAvailable = m_wasAlternateProtocolAvailable; | |
168 data->m_wasFetchedViaProxy = m_wasFetchedViaProxy; | |
169 data->m_responseTime = m_responseTime; | |
170 data->m_remoteIPAddress = m_remoteIPAddress.string().isolatedCopy(); | |
171 data->m_remotePort = m_remotePort; | |
172 data->m_downloadedFilePath = m_downloadedFilePath.isolatedCopy(); | |
173 data->m_downloadedFileHandle = m_downloadedFileHandle; | |
174 | |
175 // Bug https://bugs.webkit.org/show_bug.cgi?id=60397 this doesn't support | |
176 // whatever values may be present in the opaque m_extraData structure. | |
177 | |
178 return data.release(); | |
179 } | |
180 | |
181 bool ResourceResponse::isHTTP() const | |
182 { | |
183 return m_url.protocolIsInHTTPFamily(); | |
184 } | |
185 | |
186 const KURL& ResourceResponse::url() const | |
187 { | |
188 return m_url; | |
189 } | |
190 | |
191 void ResourceResponse::setURL(const KURL& url) | |
192 { | |
193 m_isNull = false; | |
194 | |
195 m_url = url; | |
196 } | |
197 | |
198 const AtomicString& ResourceResponse::mimeType() const | |
199 { | |
200 return m_mimeType; | |
201 } | |
202 | |
203 void ResourceResponse::setMimeType(const AtomicString& mimeType) | |
204 { | |
205 m_isNull = false; | |
206 | |
207 // FIXME: MIME type is determined by HTTP Content-Type header. We should upd
ate the header, so that it doesn't disagree with m_mimeType. | |
208 m_mimeType = mimeType; | |
209 } | |
210 | |
211 long long ResourceResponse::expectedContentLength() const | |
212 { | |
213 return m_expectedContentLength; | |
214 } | |
215 | |
216 void ResourceResponse::setExpectedContentLength(long long expectedContentLength) | |
217 { | |
218 m_isNull = false; | |
219 | |
220 // FIXME: Content length is determined by HTTP Content-Length header. We sho
uld update the header, so that it doesn't disagree with m_expectedContentLength. | |
221 m_expectedContentLength = expectedContentLength; | |
222 } | |
223 | |
224 const AtomicString& ResourceResponse::textEncodingName() const | |
225 { | |
226 return m_textEncodingName; | |
227 } | |
228 | |
229 void ResourceResponse::setTextEncodingName(const AtomicString& encodingName) | |
230 { | |
231 m_isNull = false; | |
232 | |
233 // FIXME: Text encoding is determined by HTTP Content-Type header. We should
update the header, so that it doesn't disagree with m_textEncodingName. | |
234 m_textEncodingName = encodingName; | |
235 } | |
236 | |
237 // FIXME should compute this on the fly | |
238 const String& ResourceResponse::suggestedFilename() const | |
239 { | |
240 return m_suggestedFilename; | |
241 } | |
242 | |
243 void ResourceResponse::setSuggestedFilename(const String& suggestedName) | |
244 { | |
245 m_isNull = false; | |
246 | |
247 // FIXME: Suggested file name is calculated based on other headers. There sh
ould not be a setter for it. | |
248 m_suggestedFilename = suggestedName; | |
249 } | |
250 | |
251 int ResourceResponse::httpStatusCode() const | |
252 { | |
253 return m_httpStatusCode; | |
254 } | |
255 | |
256 void ResourceResponse::setHTTPStatusCode(int statusCode) | |
257 { | |
258 m_httpStatusCode = statusCode; | |
259 } | |
260 | |
261 const AtomicString& ResourceResponse::httpStatusText() const | |
262 { | |
263 return m_httpStatusText; | |
264 } | |
265 | |
266 void ResourceResponse::setHTTPStatusText(const AtomicString& statusText) | |
267 { | |
268 m_httpStatusText = statusText; | |
269 } | |
270 | |
271 String ResourceResponse::httpHeaderField(const AtomicString& name) const | |
272 { | |
273 return m_httpHeaderFields.get(name); | |
274 } | |
275 | |
276 String ResourceResponse::httpHeaderField(const char* name) const | |
277 { | |
278 return m_httpHeaderFields.get(name); | |
279 } | |
280 | |
281 void ResourceResponse::updateHeaderParsedState(const AtomicString& name) | |
282 { | |
283 DEFINE_STATIC_LOCAL(const AtomicString, ageHeader, ("age", AtomicString::Con
structFromLiteral)); | |
284 DEFINE_STATIC_LOCAL(const AtomicString, cacheControlHeader, ("cache-control"
, AtomicString::ConstructFromLiteral)); | |
285 DEFINE_STATIC_LOCAL(const AtomicString, dateHeader, ("date", AtomicString::C
onstructFromLiteral)); | |
286 DEFINE_STATIC_LOCAL(const AtomicString, expiresHeader, ("expires", AtomicStr
ing::ConstructFromLiteral)); | |
287 DEFINE_STATIC_LOCAL(const AtomicString, lastModifiedHeader, ("last-modified"
, AtomicString::ConstructFromLiteral)); | |
288 DEFINE_STATIC_LOCAL(const AtomicString, pragmaHeader, ("pragma", AtomicStrin
g::ConstructFromLiteral)); | |
289 | |
290 if (equalIgnoringCase(name, ageHeader)) | |
291 m_haveParsedAgeHeader = false; | |
292 else if (equalIgnoringCase(name, cacheControlHeader) || equalIgnoringCase(na
me, pragmaHeader)) | |
293 m_haveParsedCacheControlHeader = false; | |
294 else if (equalIgnoringCase(name, dateHeader)) | |
295 m_haveParsedDateHeader = false; | |
296 else if (equalIgnoringCase(name, expiresHeader)) | |
297 m_haveParsedExpiresHeader = false; | |
298 else if (equalIgnoringCase(name, lastModifiedHeader)) | |
299 m_haveParsedLastModifiedHeader = false; | |
300 } | |
301 | |
302 void ResourceResponse::setHTTPHeaderField(const AtomicString& name, const String
& value) | |
303 { | |
304 updateHeaderParsedState(name); | |
305 | |
306 m_httpHeaderFields.set(name, value); | |
307 } | |
308 | |
309 void ResourceResponse::addHTTPHeaderField(const AtomicString& name, const String
& value) | |
310 { | |
311 updateHeaderParsedState(name); | |
312 | |
313 HTTPHeaderMap::AddResult result = m_httpHeaderFields.add(name, value); | |
314 if (!result.isNewEntry) | |
315 result.iterator->value = result.iterator->value + ", " + value; | |
316 } | |
317 | |
318 void ResourceResponse::clearHTTPHeaderField(const AtomicString& name) | |
319 { | |
320 m_httpHeaderFields.remove(name); | |
321 } | |
322 | |
323 const HTTPHeaderMap& ResourceResponse::httpHeaderFields() const | |
324 { | |
325 return m_httpHeaderFields; | |
326 } | |
327 | |
328 void ResourceResponse::parseCacheControlDirectives() const | |
329 { | |
330 ASSERT(!m_haveParsedCacheControlHeader); | |
331 | |
332 m_haveParsedCacheControlHeader = true; | |
333 | |
334 m_cacheControlContainsMustRevalidate = false; | |
335 m_cacheControlContainsNoCache = false; | |
336 m_cacheControlMaxAge = std::numeric_limits<double>::quiet_NaN(); | |
337 | |
338 DEFINE_STATIC_LOCAL(const AtomicString, cacheControlString, ("cache-control"
, AtomicString::ConstructFromLiteral)); | |
339 DEFINE_STATIC_LOCAL(const AtomicString, noCacheDirective, ("no-cache", Atomi
cString::ConstructFromLiteral)); | |
340 DEFINE_STATIC_LOCAL(const AtomicString, noStoreDirective, ("no-store", Atomi
cString::ConstructFromLiteral)); | |
341 DEFINE_STATIC_LOCAL(const AtomicString, mustRevalidateDirective, ("must-reva
lidate", AtomicString::ConstructFromLiteral)); | |
342 DEFINE_STATIC_LOCAL(const AtomicString, maxAgeDirective, ("max-age", AtomicS
tring::ConstructFromLiteral)); | |
343 | |
344 String cacheControlValue = m_httpHeaderFields.get(cacheControlString); | |
345 if (!cacheControlValue.isEmpty()) { | |
346 Vector<pair<String, String> > directives; | |
347 parseCacheHeader(cacheControlValue, directives); | |
348 | |
349 size_t directivesSize = directives.size(); | |
350 for (size_t i = 0; i < directivesSize; ++i) { | |
351 // RFC2616 14.9.1: A no-cache directive with a value is only meaning
ful for proxy caches. | |
352 // It should be ignored by a browser level cache. | |
353 if (equalIgnoringCase(directives[i].first, noCacheDirective) && dire
ctives[i].second.isEmpty()) | |
354 m_cacheControlContainsNoCache = true; | |
355 else if (equalIgnoringCase(directives[i].first, noStoreDirective)) | |
356 m_cacheControlContainsNoStore = true; | |
357 else if (equalIgnoringCase(directives[i].first, mustRevalidateDirect
ive)) | |
358 m_cacheControlContainsMustRevalidate = true; | |
359 else if (equalIgnoringCase(directives[i].first, maxAgeDirective)) { | |
360 if (!std::isnan(m_cacheControlMaxAge)) { | |
361 // First max-age directive wins if there are multiple ones. | |
362 continue; | |
363 } | |
364 bool ok; | |
365 double maxAge = directives[i].second.toDouble(&ok); | |
366 if (ok) | |
367 m_cacheControlMaxAge = maxAge; | |
368 } | |
369 } | |
370 } | |
371 | |
372 if (!m_cacheControlContainsNoCache) { | |
373 // Handle Pragma: no-cache | |
374 // This is deprecated and equivalent to Cache-control: no-cache | |
375 // Don't bother tokenizing the value, it is not important | |
376 DEFINE_STATIC_LOCAL(const AtomicString, pragmaHeader, ("pragma", AtomicS
tring::ConstructFromLiteral)); | |
377 String pragmaValue = m_httpHeaderFields.get(pragmaHeader); | |
378 | |
379 m_cacheControlContainsNoCache = pragmaValue.lower().contains(noCacheDire
ctive); | |
380 } | |
381 } | |
382 | |
383 bool ResourceResponse::cacheControlContainsNoCache() const | |
384 { | |
385 if (!m_haveParsedCacheControlHeader) | |
386 parseCacheControlDirectives(); | |
387 return m_cacheControlContainsNoCache; | |
388 } | |
389 | |
390 bool ResourceResponse::cacheControlContainsNoStore() const | |
391 { | |
392 if (!m_haveParsedCacheControlHeader) | |
393 parseCacheControlDirectives(); | |
394 return m_cacheControlContainsNoStore; | |
395 } | |
396 | |
397 bool ResourceResponse::cacheControlContainsMustRevalidate() const | |
398 { | |
399 if (!m_haveParsedCacheControlHeader) | |
400 parseCacheControlDirectives(); | |
401 return m_cacheControlContainsMustRevalidate; | |
402 } | |
403 | |
404 bool ResourceResponse::hasCacheValidatorFields() const | |
405 { | |
406 DEFINE_STATIC_LOCAL(const AtomicString, lastModifiedHeader, ("last-modified"
, AtomicString::ConstructFromLiteral)); | |
407 DEFINE_STATIC_LOCAL(const AtomicString, eTagHeader, ("etag", AtomicString::C
onstructFromLiteral)); | |
408 return !m_httpHeaderFields.get(lastModifiedHeader).isEmpty() || !m_httpHeade
rFields.get(eTagHeader).isEmpty(); | |
409 } | |
410 | |
411 double ResourceResponse::cacheControlMaxAge() const | |
412 { | |
413 if (!m_haveParsedCacheControlHeader) | |
414 parseCacheControlDirectives(); | |
415 return m_cacheControlMaxAge; | |
416 } | |
417 | |
418 static double parseDateValueInHeader(const HTTPHeaderMap& headers, const AtomicS
tring& headerName) | |
419 { | |
420 String headerValue = headers.get(headerName); | |
421 if (headerValue.isEmpty()) | |
422 return std::numeric_limits<double>::quiet_NaN(); | |
423 // This handles all date formats required by RFC2616: | |
424 // Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 | |
425 // Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036 | |
426 // Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format | |
427 double dateInMilliseconds = parseDate(headerValue); | |
428 if (!std::isfinite(dateInMilliseconds)) | |
429 return std::numeric_limits<double>::quiet_NaN(); | |
430 return dateInMilliseconds / 1000; | |
431 } | |
432 | |
433 double ResourceResponse::date() const | |
434 { | |
435 if (!m_haveParsedDateHeader) { | |
436 DEFINE_STATIC_LOCAL(const AtomicString, headerName, ("date", AtomicStrin
g::ConstructFromLiteral)); | |
437 m_date = parseDateValueInHeader(m_httpHeaderFields, headerName); | |
438 m_haveParsedDateHeader = true; | |
439 } | |
440 return m_date; | |
441 } | |
442 | |
443 double ResourceResponse::age() const | |
444 { | |
445 if (!m_haveParsedAgeHeader) { | |
446 DEFINE_STATIC_LOCAL(const AtomicString, headerName, ("age", AtomicString
::ConstructFromLiteral)); | |
447 String headerValue = m_httpHeaderFields.get(headerName); | |
448 bool ok; | |
449 m_age = headerValue.toDouble(&ok); | |
450 if (!ok) | |
451 m_age = std::numeric_limits<double>::quiet_NaN(); | |
452 m_haveParsedAgeHeader = true; | |
453 } | |
454 return m_age; | |
455 } | |
456 | |
457 double ResourceResponse::expires() const | |
458 { | |
459 if (!m_haveParsedExpiresHeader) { | |
460 DEFINE_STATIC_LOCAL(const AtomicString, headerName, ("expires", AtomicSt
ring::ConstructFromLiteral)); | |
461 m_expires = parseDateValueInHeader(m_httpHeaderFields, headerName); | |
462 m_haveParsedExpiresHeader = true; | |
463 } | |
464 return m_expires; | |
465 } | |
466 | |
467 double ResourceResponse::lastModified() const | |
468 { | |
469 if (!m_haveParsedLastModifiedHeader) { | |
470 DEFINE_STATIC_LOCAL(const AtomicString, headerName, ("last-modified", At
omicString::ConstructFromLiteral)); | |
471 m_lastModified = parseDateValueInHeader(m_httpHeaderFields, headerName); | |
472 m_haveParsedLastModifiedHeader = true; | |
473 } | |
474 return m_lastModified; | |
475 } | |
476 | |
477 bool ResourceResponse::isAttachment() const | |
478 { | |
479 DEFINE_STATIC_LOCAL(const AtomicString, headerName, ("content-disposition",
AtomicString::ConstructFromLiteral)); | |
480 String value = m_httpHeaderFields.get(headerName); | |
481 size_t loc = value.find(';'); | |
482 if (loc != kNotFound) | |
483 value = value.left(loc); | |
484 value = value.stripWhiteSpace(); | |
485 DEFINE_STATIC_LOCAL(const AtomicString, attachmentString, ("attachment", Ato
micString::ConstructFromLiteral)); | |
486 return equalIgnoringCase(value, attachmentString); | |
487 } | |
488 | |
489 void ResourceResponse::setLastModifiedDate(time_t lastModifiedDate) | |
490 { | |
491 m_lastModifiedDate = lastModifiedDate; | |
492 } | |
493 | |
494 time_t ResourceResponse::lastModifiedDate() const | |
495 { | |
496 return m_lastModifiedDate; | |
497 } | |
498 | |
499 bool ResourceResponse::wasCached() const | |
500 { | |
501 return m_wasCached; | |
502 } | |
503 | |
504 void ResourceResponse::setWasCached(bool value) | |
505 { | |
506 m_wasCached = value; | |
507 } | |
508 | |
509 bool ResourceResponse::connectionReused() const | |
510 { | |
511 return m_connectionReused; | |
512 } | |
513 | |
514 void ResourceResponse::setConnectionReused(bool connectionReused) | |
515 { | |
516 m_connectionReused = connectionReused; | |
517 } | |
518 | |
519 unsigned ResourceResponse::connectionID() const | |
520 { | |
521 return m_connectionID; | |
522 } | |
523 | |
524 void ResourceResponse::setConnectionID(unsigned connectionID) | |
525 { | |
526 m_connectionID = connectionID; | |
527 } | |
528 | |
529 ResourceLoadTiming* ResourceResponse::resourceLoadTiming() const | |
530 { | |
531 return m_resourceLoadTiming.get(); | |
532 } | |
533 | |
534 void ResourceResponse::setResourceLoadTiming(PassRefPtr<ResourceLoadTiming> reso
urceLoadTiming) | |
535 { | |
536 m_resourceLoadTiming = resourceLoadTiming; | |
537 } | |
538 | |
539 PassRefPtr<ResourceLoadInfo> ResourceResponse::resourceLoadInfo() const | |
540 { | |
541 return m_resourceLoadInfo.get(); | |
542 } | |
543 | |
544 void ResourceResponse::setResourceLoadInfo(PassRefPtr<ResourceLoadInfo> loadInfo
) | |
545 { | |
546 m_resourceLoadInfo = loadInfo; | |
547 } | |
548 | |
549 void ResourceResponse::setDownloadedFilePath(const String& downloadedFilePath) | |
550 { | |
551 m_downloadedFilePath = downloadedFilePath; | |
552 if (m_downloadedFilePath.isEmpty()) { | |
553 m_downloadedFileHandle.clear(); | |
554 return; | |
555 } | |
556 OwnPtr<BlobData> blobData = BlobData::create(); | |
557 blobData->appendFile(m_downloadedFilePath); | |
558 blobData->detachFromCurrentThread(); | |
559 m_downloadedFileHandle = BlobDataHandle::create(blobData.release(), -1); | |
560 } | |
561 | |
562 bool ResourceResponse::compare(const ResourceResponse& a, const ResourceResponse
& b) | |
563 { | |
564 if (a.isNull() != b.isNull()) | |
565 return false; | |
566 if (a.url() != b.url()) | |
567 return false; | |
568 if (a.mimeType() != b.mimeType()) | |
569 return false; | |
570 if (a.expectedContentLength() != b.expectedContentLength()) | |
571 return false; | |
572 if (a.textEncodingName() != b.textEncodingName()) | |
573 return false; | |
574 if (a.suggestedFilename() != b.suggestedFilename()) | |
575 return false; | |
576 if (a.httpStatusCode() != b.httpStatusCode()) | |
577 return false; | |
578 if (a.httpStatusText() != b.httpStatusText()) | |
579 return false; | |
580 if (a.httpHeaderFields() != b.httpHeaderFields()) | |
581 return false; | |
582 if (a.resourceLoadTiming() && b.resourceLoadTiming() && *a.resourceLoadTimin
g() == *b.resourceLoadTiming()) | |
583 return true; | |
584 if (a.resourceLoadTiming() != b.resourceLoadTiming()) | |
585 return false; | |
586 return true; | |
587 } | |
588 | |
589 static bool isCacheHeaderSeparator(UChar c) | |
590 { | |
591 // See RFC 2616, Section 2.2 | |
592 switch (c) { | |
593 case '(': | |
594 case ')': | |
595 case '<': | |
596 case '>': | |
597 case '@': | |
598 case ',': | |
599 case ';': | |
600 case ':': | |
601 case '\\': | |
602 case '"': | |
603 case '/': | |
604 case '[': | |
605 case ']': | |
606 case '?': | |
607 case '=': | |
608 case '{': | |
609 case '}': | |
610 case ' ': | |
611 case '\t': | |
612 return true; | |
613 default: | |
614 return false; | |
615 } | |
616 } | |
617 | |
618 static bool isControlCharacter(UChar c) | |
619 { | |
620 return c < ' ' || c == 127; | |
621 } | |
622 | |
623 static inline String trimToNextSeparator(const String& str) | |
624 { | |
625 return str.substring(0, str.find(isCacheHeaderSeparator)); | |
626 } | |
627 | |
628 static void parseCacheHeader(const String& header, Vector<pair<String, String> >
& result) | |
629 { | |
630 const String safeHeader = header.removeCharacters(isControlCharacter); | |
631 unsigned max = safeHeader.length(); | |
632 for (unsigned pos = 0; pos < max; /* pos incremented in loop */) { | |
633 size_t nextCommaPosition = safeHeader.find(',', pos); | |
634 size_t nextEqualSignPosition = safeHeader.find('=', pos); | |
635 if (nextEqualSignPosition != kNotFound && (nextEqualSignPosition < nextC
ommaPosition || nextCommaPosition == kNotFound)) { | |
636 // Get directive name, parse right hand side of equal sign, then add
to map | |
637 String directive = trimToNextSeparator(safeHeader.substring(pos, nex
tEqualSignPosition - pos).stripWhiteSpace()); | |
638 pos += nextEqualSignPosition - pos + 1; | |
639 | |
640 String value = safeHeader.substring(pos, max - pos).stripWhiteSpace(
); | |
641 if (value[0] == '"') { | |
642 // The value is a quoted string | |
643 size_t nextDoubleQuotePosition = value.find('"', 1); | |
644 if (nextDoubleQuotePosition != kNotFound) { | |
645 // Store the value as a quoted string without quotes | |
646 result.append(pair<String, String>(directive, value.substrin
g(1, nextDoubleQuotePosition - 1).stripWhiteSpace())); | |
647 pos += (safeHeader.find('"', pos) - pos) + nextDoubleQuotePo
sition + 1; | |
648 // Move past next comma, if there is one | |
649 size_t nextCommaPosition2 = safeHeader.find(',', pos); | |
650 if (nextCommaPosition2 != kNotFound) | |
651 pos += nextCommaPosition2 - pos + 1; | |
652 else | |
653 return; // Parse error if there is anything left with no
comma | |
654 } else { | |
655 // Parse error; just use the rest as the value | |
656 result.append(pair<String, String>(directive, trimToNextSepa
rator(value.substring(1, value.length() - 1).stripWhiteSpace()))); | |
657 return; | |
658 } | |
659 } else { | |
660 // The value is a token until the next comma | |
661 size_t nextCommaPosition2 = value.find(','); | |
662 if (nextCommaPosition2 != kNotFound) { | |
663 // The value is delimited by the next comma | |
664 result.append(pair<String, String>(directive, trimToNextSepa
rator(value.substring(0, nextCommaPosition2).stripWhiteSpace()))); | |
665 pos += (safeHeader.find(',', pos) - pos) + 1; | |
666 } else { | |
667 // The rest is the value; no change to value needed | |
668 result.append(pair<String, String>(directive, trimToNextSepa
rator(value))); | |
669 return; | |
670 } | |
671 } | |
672 } else if (nextCommaPosition != kNotFound && (nextCommaPosition < nextEq
ualSignPosition || nextEqualSignPosition == kNotFound)) { | |
673 // Add directive to map with empty string as value | |
674 result.append(pair<String, String>(trimToNextSeparator(safeHeader.su
bstring(pos, nextCommaPosition - pos).stripWhiteSpace()), "")); | |
675 pos += nextCommaPosition - pos + 1; | |
676 } else { | |
677 // Add last directive to map with empty string as value | |
678 result.append(pair<String, String>(trimToNextSeparator(safeHeader.su
bstring(pos, max - pos).stripWhiteSpace()), "")); | |
679 return; | |
680 } | |
681 } | |
682 } | |
683 | |
684 } | |
OLD | NEW |