2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #import "ResourceResponse.h"
31 #import "HTTPParsers.h"
32 #import "WebCoreURLResponse.h"
33 #import "WebCoreSystemInterface.h"
34 #import <Foundation/Foundation.h>
35 #import <wtf/StdLibExtras.h>
38 @interface NSURLResponse (FoundationSecretsWebCoreKnowsAbout)
39 - (NSTimeInterval)_calculatedExpiration;
42 #ifdef BUILDING_ON_TIGER
43 typedef int NSInteger;
48 NSURLResponse *ResourceResponse::nsURLResponse() const
50 if (!m_nsResponse && !m_isNull) {
51 // Work around a mistake in the NSURLResponse class.
52 // The init function takes an NSInteger, even though the accessor returns a long long.
53 // For values that won't fit in an NSInteger, pass -1 instead.
54 NSInteger expectedContentLength;
55 if (m_expectedContentLength < 0 || m_expectedContentLength > std::numeric_limits<NSInteger>::max())
56 expectedContentLength = -1;
58 expectedContentLength = static_cast<NSInteger>(m_expectedContentLength);
59 const_cast<ResourceResponse*>(this)->m_nsResponse.adoptNS([[NSURLResponse alloc] initWithURL:m_url MIMEType:m_mimeType expectedContentLength:expectedContentLength textEncodingName:m_textEncodingName]);
61 return m_nsResponse.get();
64 void ResourceResponse::platformLazyInit()
71 ASSERT(!m_nsResponse);
75 m_url = [m_nsResponse.get() URL];
76 m_mimeType = [m_nsResponse.get() MIMEType];
77 m_expectedContentLength = [m_nsResponse.get() expectedContentLength];
78 m_textEncodingName = [m_nsResponse.get() textEncodingName];
80 // Workaround for <rdar://problem/8757088>, can be removed once that is fixed.
81 unsigned textEncodingNameLength = m_textEncodingName.length();
82 if (textEncodingNameLength >= 2 && m_textEncodingName[0U] == '"' && m_textEncodingName[textEncodingNameLength - 1] == '"')
83 m_textEncodingName = m_textEncodingName.substring(1, textEncodingNameLength - 2);
85 m_suggestedFilename = [m_nsResponse.get() suggestedFilename];
87 if ([m_nsResponse.get() isKindOfClass:[NSHTTPURLResponse class]]) {
88 NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)m_nsResponse.get();
90 m_httpStatusCode = [httpResponse statusCode];
92 RetainPtr<NSString> httpStatusLine(AdoptNS, wkCopyNSURLResponseStatusLine(m_nsResponse.get()));
94 m_httpStatusText = extractReasonPhraseFromHTTPStatusLine(httpStatusLine.get());
96 m_httpStatusText = "OK";
98 NSDictionary *headers = [httpResponse allHeaderFields];
99 NSEnumerator *e = [headers keyEnumerator];
100 while (NSString *name = [e nextObject])
101 m_httpHeaderFields.set(name, [headers objectForKey:name]);
103 m_httpStatusCode = 0;
106 bool ResourceResponse::platformCompare(const ResourceResponse& a, const ResourceResponse& b)
108 return a.nsURLResponse() == b.nsURLResponse();
111 } // namespace WebCore
113 #endif // !USE(CFNETWORK)