WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
CURL rework headerCallback
curl-rework-header-handling-r1.patch (text/plain), 11.06 KB, created by
Holger Freyther
on 2007-07-10 17:35:40 PDT
(
hide
)
Description:
CURL rework headerCallback
Filename:
MIME Type:
Creator:
Holger Freyther
Created:
2007-07-10 17:35:40 PDT
Size:
11.06 KB
patch
obsolete
>Index: WebCore/ChangeLog >=================================================================== >--- WebCore/ChangeLog (revision 24175) >+++ WebCore/ChangeLog (working copy) >@@ -1,3 +1,37 @@ >+2007-07-11 Holger Hans Peter Freyther <zecke@selfish.org> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Implement the callback responsible for handling HTTP headers. This >+ callback gets called for every header. >+ We will add these headers to our ResourceResponse and on the 'end-of-header' >+ indicator we will update the ResourceResponse and dispatch it. >+ >+ This patch adds various set methods to ResourceResponse. This improves >+ the readability of the headerCallback and avoids storing a CURL handle inside >+ the ResourceResponse which would be needed to implement ResourceResponse::doUpdateResourceResponse >+ >+ Add a destructor for ResourceHandleManager which would free the resources and remove >+ a unused variable. >+ >+ >+ * platform/network/ResourceHandleInternal.h: >+ (WebCore::ResourceHandleInternal::ResourceHandleInternal): >+ * platform/network/ResourceResponse.cpp: >+ (WebCore::ResourceResponse::setUrl): >+ (WebCore::ResourceResponse::setMimeType): >+ (WebCore::ResourceResponse::setExpectedContentLength): >+ (WebCore::ResourceResponse::setTextEncodingName): >+ (WebCore::ResourceResponse::setSuggestedFilename): >+ * platform/network/ResourceResponse.h: >+ * platform/network/curl/ResourceHandleCurl.cpp: >+ (WebCore::ResourceHandleInternal::~ResourceHandleInternal): >+ * platform/network/curl/ResourceHandleManager.cpp: >+ (WebCore::ResourceHandleManager::~ResourceHandleManager): >+ (WebCore::ResourceHandleManager::sharedInstance): >+ (WebCore::headerCallback): >+ * platform/network/curl/ResourceHandleManager.h: >+ > 2007-07-10 Oliver Hunt <oliver@apple.com> > > Reviewed by Maciej. >Index: WebCore/platform/network/ResourceHandleInternal.h >=================================================================== >--- WebCore/platform/network/ResourceHandleInternal.h (revision 24174) >+++ WebCore/platform/network/ResourceHandleInternal.h (working copy) >@@ -94,7 +94,6 @@ namespace WebCore { > , m_url(0) > , m_fileName(0) > , m_customHeaders(0) >- , m_customPostHeader(0) > #endif > #if PLATFORM(QT) > , m_job(0) >@@ -146,8 +145,8 @@ namespace WebCore { > char* m_url; > char* m_fileName; > struct curl_slist* m_customHeaders; >- struct curl_slist* m_customPostHeader; > Vector<char> m_postBytes; >+ ResourceResponse m_response; > #endif > #if PLATFORM(QT) > QWebNetworkJob *m_job; >Index: WebCore/platform/network/ResourceResponse.cpp >=================================================================== >--- WebCore/platform/network/ResourceResponse.cpp (revision 24174) >+++ WebCore/platform/network/ResourceResponse.cpp (working copy) >@@ -45,6 +45,14 @@ const KURL& ResourceResponse::url() cons > return m_url; > } > >+void ResourceResponse::setUrl(const KURL& url) >+{ >+ updateResourceResponse(); >+ m_isNull = false; >+ >+ m_url = url; >+} >+ > const String& ResourceResponse::mimeType() const > { > updateResourceResponse(); >@@ -52,6 +60,14 @@ const String& ResourceResponse::mimeType > return m_mimeType; > } > >+void ResourceResponse::setMimeType(const String& mimeType) >+{ >+ updateResourceResponse(); >+ m_isNull = false; >+ >+ m_mimeType = mimeType; >+} >+ > long long ResourceResponse::expectedContentLength() const > { > updateResourceResponse(); >@@ -59,6 +75,14 @@ long long ResourceResponse::expectedCont > return m_expectedContentLength; > } > >+void ResourceResponse::setExpectedContentLength(long long expectedContentLength) >+{ >+ updateResourceResponse(); >+ m_isNull = false; >+ >+ m_expectedContentLength = expectedContentLength; >+} >+ > const String& ResourceResponse::textEncodingName() const > { > updateResourceResponse(); >@@ -66,6 +90,14 @@ const String& ResourceResponse::textEnco > return m_textEncodingName; > } > >+void ResourceResponse::setTextEncodingName(const String& encodingName) >+{ >+ updateResourceResponse(); >+ m_isNull = false; >+ >+ m_textEncodingName = encodingName; >+} >+ > // FIXME should compute this on the fly > const String& ResourceResponse::suggestedFilename() const > { >@@ -74,6 +106,14 @@ const String& ResourceResponse::suggeste > return m_suggestedFilename; > } > >+void ResourceResponse::setSuggestedFilename(const String& suggestedName) >+{ >+ updateResourceResponse(); >+ m_isNull = false; >+ >+ m_suggestedFilename = suggestedName; >+} >+ > int ResourceResponse::httpStatusCode() const > { > updateResourceResponse(); >Index: WebCore/platform/network/ResourceResponse.h >=================================================================== >--- WebCore/platform/network/ResourceResponse.h (revision 24174) >+++ WebCore/platform/network/ResourceResponse.h (working copy) >@@ -73,12 +73,20 @@ public: > bool isHTTP() const; > > const KURL& url() const; >+ void setUrl(const KURL& url); >+ > const String& mimeType() const; >+ void setMimeType(const String& mimeType); >+ > long long expectedContentLength() const; >+ void setExpectedContentLength(long long expectedContentLength); >+ > const String& textEncodingName() const; >+ void setTextEncodingName(const String& name); > > // FIXME should compute this on the fly > const String& suggestedFilename() const; >+ void setSuggestedFilename(const String&); > > int httpStatusCode() const; > void setHTTPStatusCode(int); >Index: WebCore/platform/network/curl/ResourceHandleCurl.cpp >=================================================================== >--- WebCore/platform/network/curl/ResourceHandleCurl.cpp (revision 24174) >+++ WebCore/platform/network/curl/ResourceHandleCurl.cpp (working copy) >@@ -41,8 +41,6 @@ ResourceHandleInternal::~ResourceHandleI > free(m_fileName); > if (m_customHeaders) > curl_slist_free_all(m_customHeaders); >- if (m_customPostHeader) >- curl_slist_free_all(m_customPostHeader); > } > > ResourceHandle::~ResourceHandle() >Index: WebCore/platform/network/curl/ResourceHandleManager.cpp >=================================================================== >--- WebCore/platform/network/curl/ResourceHandleManager.cpp (revision 24174) >+++ WebCore/platform/network/curl/ResourceHandleManager.cpp (working copy) >@@ -1,6 +1,8 @@ > /* > * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved. > * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com >+ * Copyright (C) 2007 Alp Toker <alp.toker@collabora.co.uk> >+ * Copyright (C) 2007 Holger Hans Peter Freyther > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without >@@ -32,6 +34,8 @@ > #include "NotImplemented.h" > #include "ResourceHandle.h" > #include "ResourceHandleInternal.h" >+#include "HTTPParsers.h" >+ > #include <wtf/Vector.h> > > namespace WebCore { >@@ -51,6 +55,14 @@ ResourceHandleManager::ResourceHandleMan > curl_share_setopt(m_curlShareHandle, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS); > } > >+ResourceHandleManager::~ResourceHandleManager() >+{ >+ curl_multi_cleanup(m_curlMultiHandle); >+ curl_share_cleanup(m_curlShareHandle); >+ if (m_cookieJarFileName) >+ free(m_cookieJarFileName); >+} >+ > void ResourceHandleManager::setCookieJarFileName(const char* cookieJarFileName) > { > m_cookieJarFileName = strdup(cookieJarFileName); >@@ -58,7 +70,7 @@ void ResourceHandleManager::setCookieJar > > ResourceHandleManager* ResourceHandleManager::sharedInstance() > { >- static ResourceHandleManager* sharedInstance; >+ static ResourceHandleManager* sharedInstance = 0; > if (!sharedInstance) > sharedInstance = new ResourceHandleManager(); > return sharedInstance; >@@ -85,11 +97,60 @@ static size_t writeCallback(void* ptr, s > return totalSize; > } > >-// This is being called for each HTTP header in the response so it'll be called >-// multiple times for a given response. >+/* >+ * This is being called for each HTTP header in the response. This includes '\r\n' >+ * for the last line of the header. >+ * >+ * We will add each HTTP Header to the ResourceResponse and on the termination >+ * of the header (\r\n) we will parse Content-Type and Content-Disposition and >+ * update the ResourceResponse and then send it away. >+ * >+ */ > static size_t headerCallback(char* ptr, size_t size, size_t nmemb, void* data) > { >- int totalSize = size * nmemb; >+ ResourceHandle* job = static_cast<ResourceHandle*>(data); >+ ResourceHandleInternal* d = job->getInternal(); >+ >+ unsigned int totalSize = size * nmemb; >+ ResourceHandleClient* client = d->client(); >+ if (!client) { >+ return totalSize; >+ } >+ >+ >+ String header(static_cast<const char*>(ptr), totalSize); >+ >+ /* >+ * a) We can finish and send the ResourceResponse >+ * b) We will add the current header to the HTTPHeaderMap of the ResourceResponse >+ */ >+ if (header == String("\r\n")) { >+ CURL* h = d->m_handle; >+ CURLcode err; >+ >+ double contentLength = 0; >+ err = curl_easy_getinfo(h, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &contentLength); >+ d->m_response.setExpectedContentLength(static_cast<long long int>(contentLength)); >+ >+ const char* hdr; >+ err = curl_easy_getinfo(h, CURLINFO_EFFECTIVE_URL, &hdr); >+ d->m_response.setUrl(KURL(hdr)); >+ >+ long httpCode = 0; >+ err = curl_easy_getinfo(h, CURLINFO_RESPONSE_CODE, &httpCode); >+ d->m_response.setHTTPStatusCode(httpCode); >+ >+ d->m_response.setMimeType(parseMIMEType(d->m_response.httpHeaderField("Content-Type"))); >+ d->m_response.setTextEncodingName(parseCharset(d->m_response.httpHeaderField("Content-Type"))); >+ d->m_response.setSuggestedFilename(filenameFromHTTPContentDisposition(d->m_response.httpHeaderField("Content-Disposition"))); >+ >+ client->didReceiveResponse(job, d->m_response); >+ } else { >+ int splitPos = header.find(":"); >+ if (splitPos != -1) >+ d->m_response.setHTTPHeaderField(header.left(splitPos), header.substring(splitPos+1).stripWhiteSpace()); >+ } >+ > return totalSize; > } > >Index: WebCore/platform/network/curl/ResourceHandleManager.h >=================================================================== >--- WebCore/platform/network/curl/ResourceHandleManager.h (revision 24174) >+++ WebCore/platform/network/curl/ResourceHandleManager.h (working copy) >@@ -65,6 +65,7 @@ public: > > private: > ResourceHandleManager(); >+ ~ResourceHandleManager(); > void downloadTimerCallback(Timer<ResourceHandleManager>*); > void removeFromCurl(ResourceHandle*); > bool removeScheduledJob(ResourceHandle*); >@@ -72,9 +73,9 @@ private: > bool startScheduledJobs(); > > Timer<ResourceHandleManager> m_downloadTimer; >- CURLM* m_curlMultiHandle; // FIXME: never freed >- CURLSH* m_curlShareHandle; // FIXME: never freed >- char* m_cookieJarFileName; // FIXME: never freed >+ CURLM* m_curlMultiHandle; >+ CURLSH* m_curlShareHandle; >+ char* m_cookieJarFileName; > char m_curlErrorBuffer[CURL_ERROR_SIZE]; > ResourceHandleList* m_resourceHandleListHead; > };
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 14059
:
14924
|
15396
|
15470
|
15477