2006-10-19 Anders Carlsson <acarlsson@apple.com>
authorandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Oct 2006 04:24:30 +0000 (04:24 +0000)
committerandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Oct 2006 04:24:30 +0000 (04:24 +0000)
        Reviewed by Daddy Hyatt.

        Use a real hash map for the headers.

        * loader/LoaderFunctions.h:
        * loader/mac/LoaderFunctionsMac.mm:
        (WebCore::ServeSynchronousRequest):
        * platform/ResourceLoader.cpp:
        (WebCore::ResourceLoader::setRequestHeaders):
        (WebCore::ResourceLoader::requestHeaders):
        * platform/ResourceLoader.h:
        * platform/ResourceLoaderInternal.h:
        * platform/mac/ResourceLoaderMac.mm:
        (WebCore::ResourceLoader::start):
        * xml/xmlhttprequest.cpp:
        (WebCore::XMLHttpRequest::open):
        (WebCore::XMLHttpRequest::send):
        (WebCore::XMLHttpRequest::setRequestHeader):
        (WebCore::XMLHttpRequest::getRequestHeader):
        * xml/xmlhttprequest.h:

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

WebCore/ChangeLog
WebCore/loader/LoaderFunctions.h
WebCore/loader/mac/LoaderFunctionsMac.mm
WebCore/platform/ResourceLoader.cpp
WebCore/platform/ResourceLoader.h
WebCore/platform/ResourceLoaderInternal.h
WebCore/platform/mac/ResourceLoaderMac.mm
WebCore/xml/xmlhttprequest.cpp
WebCore/xml/xmlhttprequest.h

index 0bb6cf99afea5ac10c8601111eee50d0850d838c..8d7fa6c68cc586c3377a1963445262333a627da9 100644 (file)
@@ -1,3 +1,26 @@
+2006-10-19  Anders Carlsson  <acarlsson@apple.com>
+
+        Reviewed by Daddy Hyatt.
+
+        Use a real hash map for the headers.
+
+        * loader/LoaderFunctions.h:
+        * loader/mac/LoaderFunctionsMac.mm:
+        (WebCore::ServeSynchronousRequest):
+        * platform/ResourceLoader.cpp:
+        (WebCore::ResourceLoader::setRequestHeaders):
+        (WebCore::ResourceLoader::requestHeaders):
+        * platform/ResourceLoader.h:
+        * platform/ResourceLoaderInternal.h:
+        * platform/mac/ResourceLoaderMac.mm:
+        (WebCore::ResourceLoader::start):
+        * xml/xmlhttprequest.cpp:
+        (WebCore::XMLHttpRequest::open):
+        (WebCore::XMLHttpRequest::send):
+        (WebCore::XMLHttpRequest::setRequestHeader):
+        (WebCore::XMLHttpRequest::getRequestHeader):
+        * xml/xmlhttprequest.h:
+
 2006-10-19  Adam Roben  <aroben@apple.com>
 
         Reviewed by Ada.
index 891063afa558d953f5879be50959b0cd59960b7a..b411c4c967400cb079833ec7dd134524668d7f1b 100644 (file)
@@ -24,6 +24,8 @@
  */
 
 #include <wtf/Vector.h>
+#include <wtf/HashMap.h>
+#include "PlatformString.h"
 #include "ResourceLoaderClient.h"  // Defines PlatformResponse
 
 #ifdef __OBJC__
@@ -31,7 +33,7 @@
 @class NSString;
 
 @interface NSDictionary (WebCore_Extras)
-+ (id)_webcore_dictionaryWithHeaderString:(NSString *)string;
++ (id)_webcore_dictionaryWithHeaderMap:(const HashMap<WebCore::String, WebCore::String>&)headerMap;
 @end
 
 #else
@@ -46,7 +48,7 @@ class DeprecatedString;
 class DocLoader;
 class Loader;
 class Request;
-class String;
+
 
 Vector<char> ServeSynchronousRequest(Loader*, DocLoader*, ResourceLoader*, KURL& finalURL, DeprecatedString& headers);
 
index 48b28dfc77fa2c7623d63b906245b8df48032707..39cbb6a746223da6d2922ee80cf93053b017fab8 100644 (file)
@@ -47,51 +47,15 @@ using namespace WebCore;
 
 @implementation NSDictionary (WebCore_Extras)
 
-+ (id)_webcore_dictionaryWithHeaderString:(NSString *)string
++ (id)_webcore_dictionaryWithHeaderMap:(const HashMap<String, String>&)headerMap
 {
     NSMutableDictionary *headers = [[NSMutableDictionary alloc] init];
-
-    NSArray *lines = [string componentsSeparatedByString:@"\r\n"];
-    NSEnumerator *e = [lines objectEnumerator];
-    NSString *lastHeaderName = nil;
-
-    while (NSString *line = (NSString *)[e nextObject]) {
-        if ([line length]) {
-            unichar firstChar = [line characterAtIndex:0];
-            if ((firstChar == ' ' || firstChar == '\t') && lastHeaderName != nil) {
-                // lines that start with space or tab continue the previous header value
-                NSString *oldVal = [headers objectForKey:lastHeaderName];
-                ASSERT(oldVal);
-                NSString *newVal = [line stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" \t"]];
-                [headers setObject:[NSString stringWithFormat:@"%@ %@", oldVal, newVal]
-                            forKey:lastHeaderName];
-                continue;
-            }
-        }
-
-        NSRange colonRange = [line rangeOfString:@":"];
-        if (colonRange.location != NSNotFound) {
-            // don't worry about case, assume lower levels will take care of it
-
-            NSString *headerName = [[line substringToIndex:colonRange.location] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" \t"]];
-            NSString *headerValue = [[line substringFromIndex:colonRange.location + 1] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" \t"]];
-            
-            NSString *oldVal = [headers objectForKey:headerName];
-            if (oldVal) {
-                headerValue = [NSString stringWithFormat:@"%@, %@", oldVal, headerValue];
-            }
-
-            [headers setObject:headerValue forKey:headerName];
-            
-            lastHeaderName = headerName;
-        }
-    }
-
-    NSDictionary *dictionary = [NSDictionary dictionaryWithDictionary:headers];
     
-    [headers release];
+    HashMap<String, String>::const_iterator end = headerMap.end();
+    for (HashMap<String, String>::const_iterator it = headerMap.begin(); it != end; ++it)
+        [headers setValue:it->second forKey:it->first];
     
-    return dictionary;
+    return headers;
 }
 
 @end
@@ -136,11 +100,11 @@ Vector<char> ServeSynchronousRequest(Loader *loader, DocLoader *docLoader, Resou
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
     NSDictionary *headerDict = nil;
-    String headerString = job->queryMetaData("customHTTPHeader");
-
-    if (!headerString.isEmpty())
-        headerDict = [[NSDictionary _webcore_dictionaryWithHeaderString:headerString] retain];
+    const HashMap<String, String>& requestHeaders = job->requestHeaders();
 
+    if (!requestHeaders.isEmpty())
+        headerDict = [[NSDictionary _webcore_dictionaryWithHeaderMap:requestHeaders] retain];
+    
     NSArray *postData = nil;
     if (!job->postData().elements().isEmpty())
         postData = arrayFromFormData(job->postData());
index 57fba67e5e2923e210f7368d99fd3d0d28d912da..ae8620439f508ab143c5814dae28739084fc46f3 100644 (file)
@@ -74,6 +74,16 @@ String ResourceLoader::responseEncoding() const
     return d->m_responseEncoding;
 }
 
+void ResourceLoader::setRequestHeaders(const HashMap<String, String>& requestHeaders)
+{
+    d->m_requestHeaders = requestHeaders;
+}
+
+const HashMap<String, String>& ResourceLoader::requestHeaders() const
+{
+    return d->m_requestHeaders;
+}
+
 String ResourceLoader::queryMetaData(const String& key) const
 {
     if (key == "HTTP-Headers") {
index 1fd6291dfe4cbb5706a6d3f3e30e91b2f4d16f8f..c226f9f03233d8269675db5e1fae06f2466d86e2 100644 (file)
@@ -77,6 +77,10 @@ public:
     void setError(int);
     String errorText() const;
     bool isErrorPage() const;
+    
+    void setRequestHeaders(const HashMap<String, String>& requestHeaders);
+    const HashMap<String, String>& requestHeaders() const;
+    
     String responseEncoding() const;
     String queryMetaData(const String&) const;
     void addMetaData(const String& key, const String& value);
index 18f1a49061ec9531d11fc7ee9cf48bec003a9f37..c965c0f87133874aa14253524d6b84763b4438ce 100644 (file)
@@ -139,6 +139,8 @@ namespace WebCore {
         String method;
         FormData postData;
         
+        HashMap<String, String> m_requestHeaders;
+        
         String m_responseEncoding;
         DeprecatedString responseHeaders;
 
index c6faf4f77e388c74ba1080399beacd7b6c54e335..6388bf123345773b217dfc35e4c777bf99374ef1 100644 (file)
@@ -79,10 +79,9 @@ bool ResourceLoader::start(DocLoader* docLoader)
     id <WebCoreResourceHandle> handle;
 
     NSDictionary* headerDict = nil;
-    String headerString = queryMetaData("customHTTPHeader");
-
-    if (!headerString.isEmpty())
-        headerDict = [NSDictionary _webcore_dictionaryWithHeaderString:headerString];
+    
+    if (!d->m_requestHeaders.isEmpty())
+        headerDict = [[NSDictionary _webcore_dictionaryWithHeaderMap:d->m_requestHeaders] retain];
 
     if (!postData().elements().isEmpty())
         handle = [bridge startLoadingResource:resourceLoader withMethod:method() URL:url().getNSURL() customHeaders:headerDict postData:arrayFromFormData(postData())];
index dc001248c6c91717b416451a694b6886c988bbb4..4b16247dcedf6f538d4724bd3f6ea76c2381b3ed 100644 (file)
@@ -245,7 +245,7 @@ void XMLHttpRequest::open(const String& method, const KURL& url, bool async, con
     m_aborted = false;
 
     // clear stuff from possible previous load
-    m_requestHeaders = DeprecatedString();
+    m_requestHeaders.clear();
     m_responseHeaders = String();
     m_response = "";
     m_createdDocument = false;
@@ -322,8 +322,8 @@ void XMLHttpRequest::send(const String& body, ExceptionCode& ec)
         m_loader = ResourceLoader::create(m_async ? this : 0, m_method, m_url);
     }
 
-    if (m_requestHeaders.length())
-        m_loader->addMetaData("customHTTPHeader", m_requestHeaders);
+    if (m_requestHeaders.size() > 0)
+        m_loader->setRequestHeaders(m_requestHeaders);
 
     if (!m_async) {
         Vector<char> data;
@@ -388,16 +388,18 @@ void XMLHttpRequest::setRequestHeader(const String& name, const String& value, E
         // rdar 4758577: XHR spec says an exception should be thrown here.  However, doing so breaks the Business and People widgets.
         return;
 
-    if (m_requestHeaders.length() > 0)
-        m_requestHeaders += "\r\n";
-    m_requestHeaders += name.deprecatedString();
-    m_requestHeaders += ": ";
-    m_requestHeaders += value.deprecatedString();
+    if (!m_requestHeaders.contains(name)) {
+        m_requestHeaders.set(name, value);
+        return;
+    }
+    
+    String oldValue = m_requestHeaders.get(name);
+    m_requestHeaders.set(name, oldValue + ", " + value);
 }
 
-DeprecatedString XMLHttpRequest::getRequestHeader(const DeprecatedString& name) const
+String XMLHttpRequest::getRequestHeader(const String& name) const
 {
-    return getSpecificHeader(m_requestHeaders, name);
+    return m_requestHeaders.get(name);
 }
 
 String XMLHttpRequest::getAllResponseHeaders() const
index fa932a01cf8c5813a45d33bb29d31cd8b84fdb10..1406eb431e0ef23ab5b34a2ea76b5a70fbe63b24 100644 (file)
 #ifndef XMLHTTPREQUEST_H_
 #define XMLHTTPREQUEST_H_
 
+#include <wtf/HashMap.h>
+#include <wtf/Vector.h>
 #include "KURL.h"
-#include "PlatformString.h"
 #include "ResourceLoaderClient.h"
-#include <wtf/Vector.h>
+#include "PlatformString.h"
+#include "StringHash.h"
 
 namespace WebCore {
 
@@ -86,7 +88,7 @@ private:
 
     bool responseIsXML() const;
 
-    DeprecatedString getRequestHeader(const DeprecatedString& name) const;
+    String getRequestHeader(const String& name) const;
     static DeprecatedString getSpecificHeader(const DeprecatedString& headers, const DeprecatedString& name);
 
     void changeState(XMLHttpRequestState newState);
@@ -99,7 +101,7 @@ private:
     KURL m_url;
     DeprecatedString m_method;
     bool m_async;
-    DeprecatedString m_requestHeaders;
+    HashMap<String, String> m_requestHeaders;
 
     RefPtr<ResourceLoader> m_loader;