2006-11-02 Anders Carlsson <acarlsson@apple.com>
authorandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Nov 2006 01:30:24 +0000 (01:30 +0000)
committerandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Nov 2006 01:30:24 +0000 (01:30 +0000)
        Reviewed by Geoff.

        Use CFMutableURLRequestRef instead of CFHTTPMessageRef since not all URL requests are http requests.

        * platform/network/cf/ResourceHandleCFNet.cpp:
        (WebCore::addHeadersFromHashMap):
        Don't set all headers at once since that clears any previous headers set.

        (WebCore::ResourceHandle::start):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@17549 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/platform/network/cf/ResourceHandleCFNet.cpp

index 8bd468f8bd7e1083313e4c3b0cdca47188a9fa3a..3d03642d9f89fef7159721a41edb82ccecb669cb 100644 (file)
@@ -1,3 +1,15 @@
+2006-11-02  Anders Carlsson  <acarlsson@apple.com>
+
+        Reviewed by Geoff.
+
+        Use CFMutableURLRequestRef instead of CFHTTPMessageRef since not all URL requests are http requests.
+        
+        * platform/network/cf/ResourceHandleCFNet.cpp:
+        (WebCore::addHeadersFromHashMap):
+        Don't set all headers at once since that clears any previous headers set.
+        
+        (WebCore::ResourceHandle::start):
+
 2006-11-02  Adele Peterson  <adele@apple.com>
 
         Reviewed by Mitz and Geoff.
index e761a3746a259159bfc44e8a257312c864f4eca3..6d76f4ffa549e5eb23905febe51b3b46cdda90fa 100644 (file)
@@ -157,22 +157,19 @@ void didReceiveChallenge(CFURLConnectionRef conn, CFURLAuthChallengeRef challeng
     // Do nothing right now
 }
 
-void addHeadersFromHashMap(CFHTTPMessageRef request, const HTTPHeaderMap& requestHeaders) 
+void addHeadersFromHashMap(CFMutableURLRequestRef request, const HTTPHeaderMap& requestHeaders) 
 {
     if (!requestHeaders.size())
         return;
 
-    CFMutableDictionaryRef allHeaders = CFDictionaryCreateMutable(0, requestHeaders.size(), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
     HTTPHeaderMap::const_iterator end = requestHeaders.end();
     for (HTTPHeaderMap::const_iterator it = requestHeaders.begin(); it != end; ++it) {
         CFStringRef key = it->first.createCFString();
         CFStringRef value = it->second.createCFString();
-        CFDictionaryAddValue(allHeaders, key, value);
+        CFURLRequestSetHTTPHeaderFieldValue(request, key, value);
         CFRelease(key);
         CFRelease(value);
     }
-    _CFHTTPMessageSetMultipleHeaderFields(request, allHeaders);
-    CFRelease(allHeaders);
 }
 
 ResourceHandleInternal::~ResourceHandleInternal()
@@ -240,22 +237,24 @@ void runLoaderThread(void *unused)
 bool ResourceHandle::start(DocLoader* docLoader)
 {
     CFURLRef url = d->m_request.url().createCFURL();
+
     CFStringRef requestMethod = d->m_request.httpMethod().createCFString();
+    CFMutableURLRequestRef request = CFURLRequestCreateMutable(0, url, kCFURLRequestCachePolicyProtocolDefault, 30.0, 0);
     Boolean isPost = CFStringCompare(requestMethod, CFSTR("POST"), kCFCompareCaseInsensitive);
-    CFHTTPMessageRef httpRequest = CFHTTPMessageCreateRequest(0, requestMethod, url, kCFHTTPVersion1_1);
-    CFStringRef userAgentString = docLoader->frame()->userAgent().createCFString();
-    CFHTTPMessageSetHeaderFieldValue(httpRequest, CFSTR("User-Agent"), userAgentString);
     CFRelease(requestMethod);
+    
+    CFStringRef userAgentString = docLoader->frame()->userAgent().createCFString();
+    CFURLRequestSetHTTPHeaderFieldValue(request, CFSTR("User-Agent"), userAgentString);
     CFRelease(userAgentString);
 
     ref();
     d->m_loading = true;
-    addHeadersFromHashMap(httpRequest, d->m_request.httpHeaderFields());
+    addHeadersFromHashMap(request, d->m_request.httpHeaderFields());
 
     String referrer = docLoader->frame()->referrer();
-    if (!referrer.isEmpty()) {
+    if (!referrer.isEmpty() && referrer.find("file:", 0, false) != 0) {
         CFStringRef str = referrer.createCFString();
-        CFHTTPMessageSetHeaderFieldValue(httpRequest, CFSTR("Referer"),str);
+        CFURLRequestSetHTTPHeaderFieldValue(request, CFSTR("Referer"),str);
         CFRelease(str);
     }
     
@@ -269,7 +268,7 @@ bool ResourceHandle::start(DocLoader* docLoader)
             // Handle the common special case of one piece of form data, with no files.
             CFTypeRef d = CFArrayGetValueAtIndex(formArray, 0);
             if (CFGetTypeID(d) == CFDataGetTypeID()) {
-                CFHTTPMessageSetBody(httpRequest, (CFDataRef)d);
+                CFURLRequestSetHTTPRequestBody(request, (CFDataRef)d);
                 done = true;
             }
         }
@@ -305,7 +304,7 @@ bool ResourceHandle::start(DocLoader* docLoader)
             }
             if (success) {
                 CFStringRef lengthStr = CFStringCreateWithFormat(0, 0, CFSTR("%lld"), length);
-                CFHTTPMessageSetHeaderFieldValue(httpRequest, CFSTR("Content-Length"), lengthStr);
+                CFURLRequestSetHTTPHeaderFieldValue(request, CFSTR("Content-Length"), lengthStr);
                 CFRelease(lengthStr);
             }
             bodyStream = CFReadStreamCreateWithFormArray(0, formArray);
@@ -313,7 +312,8 @@ bool ResourceHandle::start(DocLoader* docLoader)
         CFRelease(formArray);
     }
 
-    CFURLRequestRef request = CFURLRequestCreateHTTPRequest(0, httpRequest, bodyStream, kCFURLRequestCachePolicyProtocolDefault, 30.0, 0);
+    if (bodyStream)
+        CFURLRequestSetHTTPRequestBodyStream(request, bodyStream);
     CFURLConnectionClient client = {0, this, 0, 0, 0, willSendRequest, didReceiveResponse, didReceiveData, NULL, didFinishLoading, didFail, willCacheResponse, didReceiveChallenge};
     d->m_connection = CFURLConnectionCreate(0, request, &client);
     CFRelease(request);