Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…图片提示CURLE_SEND_FAIL_REWIND

原因是没实现CURLOPT_IOCTLFUNCTION。这个会导致 Curl_readrewind里倒数几行返回错误。
* 增加新接口,可以强制decode url。方便electron模式
* m_cookieJarFileName的设置增加检测,这是为了修复三茅招聘提出的崩溃
  • Loading branch information
weolar committed Jun 12, 2018
1 parent 8b05035 commit c70da5a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
10 changes: 9 additions & 1 deletion net/FlattenHTTPBodyElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ class FlattenHTTPBodyElementStream {
fclose(m_file);
}
}

void reset()
{
m_formDataElementIndex = 0;
if (m_file)
fclose(m_file);
m_file = nullptr;
}

size_t read(void* ptr, size_t blockSize, size_t numberOfBlocks)
{
Expand Down Expand Up @@ -79,7 +87,7 @@ class FlattenHTTPBodyElementStream {
}
if (feof(m_file)) {
fclose(m_file);
m_file = 0;
m_file = nullptr;
m_formDataElementIndex++;
}
} else {
Expand Down
27 changes: 26 additions & 1 deletion net/WebURLLoaderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@

#if (defined ENABLE_WKE) && (ENABLE_WKE == 1)
#include "wke/wkeWebView.h"
extern bool g_isDecodeUrlRequest;
#endif
#include "wtf/RefCountedLeakCounter.h"

Expand Down Expand Up @@ -416,6 +417,22 @@ static size_t headerCallbackOnIoThread(char* ptr, size_t size, size_t nmemb, voi
return totalSize;
}

static curlioerr ioctlCallbackOnIoThread(CURL* handle, int cmd, void* data)
{
int jobId = (int)data;
AutoLockJob autoLockJob(WebURLLoaderManager::sharedInstance(), jobId);
WebURLLoaderInternal* job = autoLockJob.lock();
if (!job || job->isCancelled())
return CURLIOE_UNKNOWNCMD;

if (cmd == CURLIOCMD_RESTARTREAD) {
job->m_formDataStream->reset();

return CURLIOE_OK;
}
return CURLIOE_UNKNOWNCMD;
}

size_t readCallbackOnIoThread(void* ptr, size_t size, size_t nmemb, void* data)
{
int jobId = (int)data;
Expand Down Expand Up @@ -635,6 +652,9 @@ static void setupFormDataOnIoThread(WebURLLoaderInternal* job, SetupDataInfo* in
job->m_formDataStream = new FlattenHTTPBodyElementStream(info->flattenElements);
curl_easy_setopt(job->m_handle, CURLOPT_READFUNCTION, readCallbackOnIoThread);
curl_easy_setopt(job->m_handle, CURLOPT_READDATA, job->m_id);

curl_easy_setopt(job->m_handle, CURLOPT_IOCTLFUNCTION, ioctlCallbackOnIoThread);
curl_easy_setopt(job->m_handle, CURLOPT_IOCTLDATA, job->m_id);
}

static void flattenHTTPBodyBlobElement(const WebString& blobUUID, curl_off_t* size, WTF::Vector<FlattenHTTPBodyElement*>* flattenElements)
Expand Down Expand Up @@ -1005,6 +1025,11 @@ int WebURLLoaderManager::addAsynchronousJob(WebURLLoaderInternal* job)
}
#endif

if (g_isDecodeUrlRequest) {
url = blink::decodeURLEscapeSequences(url);
job->firstRequest()->setURL((blink::KURL(blink::ParsedURLString, url)));
}

String referer = job->firstRequest()->httpHeaderField(WebString::fromUTF8("referer"));
job->m_manager = this;

Expand Down Expand Up @@ -1373,7 +1398,7 @@ void WebURLLoaderManager::initializeHandleOnIoThread(int jobId, InitializeHandle

curl_easy_setopt(job->m_handle, CURLOPT_URL, job->m_url);

if (m_cookieJarFileName) {
if (m_cookieJarFileName && '\0' != m_cookieJarFileName[0]) {
curl_easy_setopt(job->m_handle, CURLOPT_COOKIEJAR, m_cookieJarFileName);
curl_easy_setopt(job->m_handle, CURLOPT_COOKIEFILE, m_cookieJarFileName);
}
Expand Down

0 comments on commit c70da5a

Please sign in to comment.