void ResourceRequest::updateFromDelegatePreservingOldHTTPBody(const ResourceRequest& delegateProvidedRequest) { RefPtr<FormData> oldHTTPBody = httpBody(); *this = delegateProvidedRequest; setHTTPBody(oldHTTPBody.release()); }
void ResourceRequest::doUpdatePlatformHTTPBody() { CFMutableURLRequestRef cfRequest; RetainPtr<CFURLRef> url = ResourceRequest::url().createCFURL(); RetainPtr<CFURLRef> firstPartyForCookies = ResourceRequest::firstPartyForCookies().createCFURL(); if (m_cfRequest) { cfRequest = CFURLRequestCreateMutableCopy(0, m_cfRequest.get()); CFURLRequestSetURL(cfRequest, url.get()); CFURLRequestSetMainDocumentURL(cfRequest, firstPartyForCookies.get()); CFURLRequestSetCachePolicy(cfRequest, (CFURLRequestCachePolicy)cachePolicy()); CFURLRequestSetTimeoutInterval(cfRequest, timeoutInterval()); } else cfRequest = CFURLRequestCreateMutable(0, url.get(), (CFURLRequestCachePolicy)cachePolicy(), timeoutInterval(), firstPartyForCookies.get()); FormData* formData = httpBody(); if (formData && !formData->isEmpty()) WebCore::setHTTPBody(cfRequest, formData); if (RetainPtr<CFReadStreamRef> bodyStream = adoptCF(CFURLRequestCopyHTTPRequestBodyStream(cfRequest))) { // For streams, provide a Content-Length to avoid using chunked encoding, and to get accurate total length in callbacks. if (RetainPtr<CFStringRef> lengthString = adoptCF(static_cast<CFStringRef>(CFReadStreamCopyProperty(bodyStream.get(), formDataStreamLengthPropertyName())))) { CFURLRequestSetHTTPHeaderFieldValue(cfRequest, CFSTR("Content-Length"), lengthString.get()); // Since resource request is already marked updated, we need to keep it up to date too. ASSERT(m_resourceRequestUpdated); m_httpHeaderFields.set(HTTPHeaderName::ContentLength, lengthString.get()); } } m_cfRequest = adoptCF(cfRequest); #if PLATFORM(COCOA) clearOrUpdateNSURLRequest(); #endif }
void ResourceRequest::doUpdatePlatformRequest() { CFMutableURLRequestRef cfRequest; RetainPtr<CFURLRef> url(AdoptCF, ResourceRequest::url().createCFURL()); RetainPtr<CFURLRef> firstPartyForCookies(AdoptCF, ResourceRequest::firstPartyForCookies().createCFURL()); if (m_cfRequest) { cfRequest = CFURLRequestCreateMutableCopy(0, m_cfRequest.get()); CFURLRequestSetURL(cfRequest, url.get()); CFURLRequestSetMainDocumentURL(cfRequest, firstPartyForCookies.get()); CFURLRequestSetCachePolicy(cfRequest, (CFURLRequestCachePolicy)cachePolicy()); CFURLRequestSetTimeoutInterval(cfRequest, timeoutInterval()); } else cfRequest = CFURLRequestCreateMutable(0, url.get(), (CFURLRequestCachePolicy)cachePolicy(), timeoutInterval(), firstPartyForCookies.get()); CFURLRequestSetHTTPRequestMethod(cfRequest, httpMethod().createCFString().get()); if (httpPipeliningEnabled()) wkSetHTTPPipeliningPriority(cfRequest, toHTTPPipeliningPriority(m_priority)); #if !PLATFORM(WIN) wkCFURLRequestAllowAllPostCaching(cfRequest); #endif setHeaderFields(cfRequest, httpHeaderFields()); RefPtr<FormData> formData = httpBody(); if (formData && !formData->isEmpty()) WebCore::setHTTPBody(cfRequest, formData); CFURLRequestSetShouldHandleHTTPCookies(cfRequest, allowCookies()); unsigned fallbackCount = m_responseContentDispositionEncodingFallbackArray.size(); RetainPtr<CFMutableArrayRef> encodingFallbacks(AdoptCF, CFArrayCreateMutable(kCFAllocatorDefault, fallbackCount, 0)); for (unsigned i = 0; i != fallbackCount; ++i) { RetainPtr<CFStringRef> encodingName = m_responseContentDispositionEncodingFallbackArray[i].createCFString(); CFStringEncoding encoding = CFStringConvertIANACharSetNameToEncoding(encodingName.get()); if (encoding != kCFStringEncodingInvalidId) CFArrayAppendValue(encodingFallbacks.get(), reinterpret_cast<const void*>(encoding)); } setContentDispositionEncodingFallbackArray(cfRequest, encodingFallbacks.get()); if (m_cfRequest) { RetainPtr<CFHTTPCookieStorageRef> cookieStorage(AdoptCF, CFURLRequestCopyHTTPCookieStorage(m_cfRequest.get())); if (cookieStorage) CFURLRequestSetHTTPCookieStorage(cfRequest, cookieStorage.get()); CFURLRequestSetHTTPCookieStorageAcceptPolicy(cfRequest, CFURLRequestGetHTTPCookieStorageAcceptPolicy(m_cfRequest.get())); CFURLRequestSetSSLProperties(cfRequest, CFURLRequestGetSSLProperties(m_cfRequest.get())); } m_cfRequest.adoptCF(cfRequest); #if PLATFORM(MAC) updateNSURLRequest(); #endif }
void ResourceRequest::updateFromDelegatePreservingOldProperties(const ResourceRequest& delegateProvidedRequest) { RefPtr<FormData> oldHTTPBody = httpBody(); #if ENABLE(INSPECTOR) bool isHiddenFromInspector = hiddenFromInspector(); #endif *this = delegateProvidedRequest; setHTTPBody(oldHTTPBody.release()); #if ENABLE(INSPECTOR) setHiddenFromInspector(isHiddenFromInspector); #endif }
void ResourceRequest::updateFromDelegatePreservingOldProperties(const ResourceRequest& delegateProvidedRequest) { // These are things we don't want willSendRequest delegate to mutate or reset. ResourceLoadPriority oldPriority = priority(); RefPtr<FormData> oldHTTPBody = httpBody(); bool isHiddenFromInspector = hiddenFromInspector(); auto oldRequester = requester(); *this = delegateProvidedRequest; setPriority(oldPriority); setHTTPBody(WTFMove(oldHTTPBody)); setHiddenFromInspector(isHiddenFromInspector); setRequester(oldRequester); }
void ResourceRequest::doUpdatePlatformRequest() { CFMutableURLRequestRef cfRequest; RetainPtr<CFURLRef> url(AdoptCF, ResourceRequest::url().createCFURL()); RetainPtr<CFURLRef> firstPartyForCookies(AdoptCF, ResourceRequest::firstPartyForCookies().createCFURL()); if (m_cfRequest) { cfRequest = CFURLRequestCreateMutableCopy(0, m_cfRequest.get()); CFURLRequestSetURL(cfRequest, url.get()); CFURLRequestSetMainDocumentURL(cfRequest, firstPartyForCookies.get()); CFURLRequestSetCachePolicy(cfRequest, (CFURLRequestCachePolicy)cachePolicy()); CFURLRequestSetTimeoutInterval(cfRequest, timeoutInterval()); } else { cfRequest = CFURLRequestCreateMutable(0, url.get(), (CFURLRequestCachePolicy)cachePolicy(), timeoutInterval(), firstPartyForCookies.get()); } RetainPtr<CFStringRef> requestMethod(AdoptCF, httpMethod().createCFString()); CFURLRequestSetHTTPRequestMethod(cfRequest, requestMethod.get()); addHeadersFromHashMap(cfRequest, httpHeaderFields()); WebCore::setHTTPBody(cfRequest, httpBody()); CFURLRequestSetShouldHandleHTTPCookies(cfRequest, allowHTTPCookies()); unsigned fallbackCount = m_responseContentDispositionEncodingFallbackArray.size(); RetainPtr<CFMutableArrayRef> encodingFallbacks(AdoptCF, CFArrayCreateMutable(kCFAllocatorDefault, fallbackCount, 0)); for (unsigned i = 0; i != fallbackCount; ++i) { RetainPtr<CFStringRef> encodingName(AdoptCF, m_responseContentDispositionEncodingFallbackArray[i].createCFString()); CFStringEncoding encoding = CFStringConvertIANACharSetNameToEncoding(encodingName.get()); if (encoding != kCFStringEncodingInvalidId) CFArrayAppendValue(encodingFallbacks.get(), reinterpret_cast<const void*>(encoding)); } setContentDispositionEncodingFallbackArray(cfRequest, encodingFallbacks.get()); if (m_cfRequest) { RetainPtr<CFHTTPCookieStorageRef> cookieStorage(AdoptCF, CFURLRequestCopyHTTPCookieStorage(m_cfRequest.get())); if (cookieStorage) CFURLRequestSetHTTPCookieStorage(cfRequest, cookieStorage.get()); CFURLRequestSetHTTPCookieStorageAcceptPolicy(cfRequest, CFURLRequestGetHTTPCookieStorageAcceptPolicy(m_cfRequest.get())); CFURLRequestSetSSLProperties(cfRequest, CFURLRequestGetSSLProperties(m_cfRequest.get())); } m_cfRequest.adoptCF(cfRequest); }
void ResourceRequest::initializePlatformRequest(NetworkRequest& platformRequest, bool cookiesEnabled, bool isInitial, bool isRedirect) const { // If this is the initial load, skip the request body and headers. if (isInitial) platformRequest.setRequestInitial(timeoutInterval()); else { ReadOnlyLatin1String latin1URL(url().string()); ReadOnlyLatin1String latin1HttpMethod(httpMethod()); platformRequest.setRequestUrl(latin1URL.data(), latin1URL.length(), latin1HttpMethod.data(), latin1HttpMethod.length(), platformCachePolicyForRequest(*this), platformTargetTypeForRequest(*this), timeoutInterval()); platformRequest.setConditional(isConditional()); platformRequest.setSuggestedSaveName(suggestedSaveName().utf8().data()); if (httpBody() && !httpBody()->isEmpty()) { const Vector<FormDataElement>& elements = httpBody()->elements(); // Use setData for simple forms because it is slightly more efficient. if (elements.size() == 1 && elements[0].m_type == FormDataElement::data) platformRequest.setData(elements[0].m_data.data(), elements[0].m_data.size()); else { for (unsigned i = 0; i < elements.size(); ++i) { const FormDataElement& element = elements[i]; if (element.m_type == FormDataElement::data) platformRequest.addMultipartData(element.m_data.data(), element.m_data.size()); else if (element.m_type == FormDataElement::encodedFile) platformRequest.addMultipartFilename(element.m_filename.characters(), element.m_filename.length()); #if ENABLE(BLOB) else if (element.m_type == FormDataElement::encodedBlob) { RefPtr<BlobStorageData> blobData = static_cast<BlobRegistryImpl&>(blobRegistry()).getBlobDataFromURL(KURL(ParsedURLString, element.m_url)); if (blobData) { for (size_t j = 0; j < blobData->items().size(); ++j) { const BlobDataItem& blobItem = blobData->items()[j]; if (blobItem.type == BlobDataItem::Data) platformRequest.addMultipartData(blobItem.data->data() + static_cast<int>(blobItem.offset), static_cast<int>(blobItem.length)); else { ASSERT(blobItem.type == BlobDataItem::File); platformRequest.addMultipartFilename(blobItem.path.characters(), blobItem.path.length(), blobItem.offset, blobItem.length, blobItem.expectedModificationTime); } } } } #endif else ASSERT_NOT_REACHED(); // unknown type } } } // When ResourceRequest is reused by CacheResourceLoader, page refreshing or redirection, its cookies may be dirtied. We won't use these cookies any more. bool cookieHeaderMayBeDirty = isRedirect || cachePolicy() == WebCore::ReloadIgnoringCacheData || cachePolicy() == WebCore::ReturnCacheDataElseLoad; for (HTTPHeaderMap::const_iterator it = httpHeaderFields().begin(); it != httpHeaderFields().end(); ++it) { String key = it->first; String value = it->second; if (!key.isEmpty()) { if (equalIgnoringCase(key, "Cookie")) { // We won't use the old cookies of resourceRequest for new location because these cookies may be changed by redirection. if (cookieHeaderMayBeDirty) continue; // We need to check the encoding and encode the cookie's value using latin1 or utf8 to support unicode data. if (!value.containsOnlyLatin1()) { platformRequest.addHeader("Cookie", value.utf8().data()); continue; } } ReadOnlyLatin1String latin1Key(key); ReadOnlyLatin1String latin1Value(value); platformRequest.addHeader(latin1Key.data(), latin1Key.length(), latin1Value.data(), latin1Value.length()); } } // If request's cookies may be dirty, they must be set again. // If there aren't cookies in the header list, we need trying to add cookies. if (cookiesEnabled && (cookieHeaderMayBeDirty || !httpHeaderFields().contains("Cookie")) && !url().isNull()) { // Prepare a cookie header if there are cookies related to this url. String cookiePairs = cookieManager().getCookie(url(), WithHttpOnlyCookies); if (!cookiePairs.isEmpty()) platformRequest.addHeader("Cookie", cookiePairs.containsOnlyLatin1() ? cookiePairs.latin1().data() : cookiePairs.utf8().data()); } if (!httpHeaderFields().contains("Accept-Language")) platformRequest.addAcceptLanguageHeader(); } }
void ResourceRequest::initializePlatformRequest(NetworkRequest& platformRequest, bool cookiesEnabled, bool isInitial, bool isRedirect) const { // If this is the initial load, skip the request body and headers. if (isInitial) platformRequest.setRequestInitial(timeoutInterval()); else { platformRequest.setRequestUrl(url().string().utf8().data(), httpMethod().latin1().data(), platformCachePolicyForRequest(*this), platformTargetTypeForRequest(*this), timeoutInterval()); platformRequest.setConditional(isConditional()); if (httpBody() && !httpBody()->isEmpty()) { const Vector<FormDataElement>& elements = httpBody()->elements(); // Use setData for simple forms because it is slightly more efficient. if (elements.size() == 1 && elements[0].m_type == FormDataElement::data) platformRequest.setData(elements[0].m_data.data(), elements[0].m_data.size()); else { for (unsigned i = 0; i < elements.size(); ++i) { const FormDataElement& element = elements[i]; if (element.m_type == FormDataElement::data) platformRequest.addMultipartData(element.m_data.data(), element.m_data.size()); else if (element.m_type == FormDataElement::encodedFile) platformRequest.addMultipartFilename(element.m_filename.characters(), element.m_filename.length()); #if ENABLE(BLOB) else if (element.m_type == FormDataElement::encodedBlob) { RefPtr<BlobStorageData> blobData = static_cast<BlobRegistryImpl&>(blobRegistry()).getBlobDataFromURL(KURL(ParsedURLString, element.m_blobURL)); if (blobData) { for (size_t j = 0; j < blobData->items().size(); ++j) { const BlobDataItem& blobItem = blobData->items()[j]; if (blobItem.type == BlobDataItem::Data) platformRequest.addMultipartData(blobItem.data->data() + static_cast<int>(blobItem.offset), static_cast<int>(blobItem.length)); else { ASSERT(blobItem.type == BlobDataItem::File); platformRequest.addMultipartFilename(blobItem.path.characters(), blobItem.path.length(), blobItem.offset, blobItem.length, blobItem.expectedModificationTime); } } } } #endif else ASSERT_NOT_REACHED(); // unknown type } } } for (HTTPHeaderMap::const_iterator it = httpHeaderFields().begin(); it != httpHeaderFields().end(); ++it) { String key = it->first; String value = it->second; if (!key.isEmpty() && !value.isEmpty()) { // We need to check the encoding and encode the cookie's value using latin1 or utf8 to support unicode characters. if (equalIgnoringCase(key, "Cookie")) platformRequest.addHeader(key.latin1().data(), value.containsOnlyLatin1() ? value.latin1().data() : value.utf8().data()); else platformRequest.addHeader(key.latin1().data(), value.latin1().data()); } } // Redirection's response may contain new cookies, so add cookies again. // If there aren't cookies in the header list, we need trying to add cookies. if (cookiesEnabled && (isRedirect || !httpHeaderFields().contains("Cookie")) && !url().isNull()) { // Prepare a cookie header if there are cookies related to this url. String cookiePairs = cookieManager().getCookie(url(), WithHttpOnlyCookies); if (!cookiePairs.isEmpty()) platformRequest.addHeader("Cookie", cookiePairs.containsOnlyLatin1() ? cookiePairs.latin1().data() : cookiePairs.utf8().data()); } // Locale has the form "en-US". Construct accept language like "en-US, en;q=0.8". std::string locale = BlackBerry::Platform::Client::get()->getLocale(); // POSIX locale has '_' instead of '-'. // Replace to conform to HTTP spec. size_t underscore = locale.find('_'); if (underscore != std::string::npos) locale.replace(underscore, 1, "-"); std::string acceptLanguage = locale + ", " + locale.substr(0, 2) + ";q=0.8"; platformRequest.addHeader("Accept-Language", acceptLanguage.c_str()); } }
void FetchManager::Loader::performHTTPFetch(bool corsFlag, bool corsPreflightFlag) { ASSERT(m_request->url().protocolIsInHTTPFamily()); // CORS preflight fetch procedure is implemented inside DocumentThreadableLoader. // "1. Let |HTTPRequest| be a copy of |request|, except that |HTTPRequest|'s // body is a tee of |request|'s body." // We use ResourceRequest class for HTTPRequest. // FIXME: Support body. ResourceRequest request(m_request->url()); request.setRequestContext(m_request->context()); request.setHTTPMethod(m_request->method()); const Vector<OwnPtr<FetchHeaderList::Header>>& list = m_request->headerList()->list(); for (size_t i = 0; i < list.size(); ++i) { request.addHTTPHeaderField(AtomicString(list[i]->first), AtomicString(list[i]->second)); } if (m_request->method() != "GET" && m_request->method() != "HEAD") { if (BodyStreamBuffer* buffer = m_request->buffer()) { RefPtr<BlobDataHandle> blobDataHandle = buffer->handle()->obtainReader(nullptr)->drainAsBlobDataHandle(FetchDataConsumerHandle::Reader::AllowBlobWithInvalidSize); RefPtr<FormData> httpBody(FormData::create()); if (blobDataHandle) httpBody->appendBlob(blobDataHandle->uuid(), blobDataHandle); request.setHTTPBody(httpBody); } } request.setUseStreamOnResponse(true); // "2. Append `Referer`/empty byte sequence, if |HTTPRequest|'s |referrer| // is none, and `Referer`/|HTTPRequest|'s referrer, serialized and utf-8 // encoded, otherwise, to HTTPRequest's header list. // We set the referrer using workerGlobalScope's URL in // WorkerThreadableLoader. // "3. Append `Host`, ..." // FIXME: Implement this when the spec is fixed. // "4.If |HTTPRequest|'s force Origin header flag is set, append `Origin`/ // |HTTPRequest|'s origin, serialized and utf-8 encoded, to |HTTPRequest|'s // header list." // We set Origin header in updateRequestForAccessControl() called from // DocumentThreadableLoader::makeCrossOriginAccessRequest // "5. Let |credentials flag| be set if either |HTTPRequest|'s credentials // mode is |include|, or |HTTPRequest|'s credentials mode is |same-origin| // and the |CORS flag| is unset, and unset otherwise. ResourceLoaderOptions resourceLoaderOptions; resourceLoaderOptions.dataBufferingPolicy = DoNotBufferData; if (m_request->credentials() == WebURLRequest::FetchCredentialsModeInclude || (m_request->credentials() == WebURLRequest::FetchCredentialsModeSameOrigin && !corsFlag)) { resourceLoaderOptions.allowCredentials = AllowStoredCredentials; } if (m_request->credentials() == WebURLRequest::FetchCredentialsModeInclude) resourceLoaderOptions.credentialsRequested = ClientRequestedCredentials; resourceLoaderOptions.securityOrigin = m_request->origin().get(); ThreadableLoaderOptions threadableLoaderOptions; threadableLoaderOptions.contentSecurityPolicyEnforcement = ContentSecurityPolicy::shouldBypassMainWorld(executionContext()) ? DoNotEnforceContentSecurityPolicy : EnforceConnectSrcDirective; if (corsPreflightFlag) threadableLoaderOptions.preflightPolicy = ForcePreflight; switch (m_request->mode()) { case WebURLRequest::FetchRequestModeSameOrigin: threadableLoaderOptions.crossOriginRequestPolicy = DenyCrossOriginRequests; break; case WebURLRequest::FetchRequestModeNoCORS: threadableLoaderOptions.crossOriginRequestPolicy = AllowCrossOriginRequests; break; case WebURLRequest::FetchRequestModeCORS: case WebURLRequest::FetchRequestModeCORSWithForcedPreflight: threadableLoaderOptions.crossOriginRequestPolicy = UseAccessControl; break; } m_loader = ThreadableLoader::create(*executionContext(), this, request, threadableLoaderOptions, resourceLoaderOptions); if (!m_loader) performNetworkError("Can't create ThreadableLoader"); }
void FetchManager::Loader::performHTTPFetch() { ASSERT(m_request->url().protocolIsInHTTPFamily()); // CORS preflight fetch procedure is implemented inside DocumentThreadableLoader. // "1. Let |HTTPRequest| be a copy of |request|, except that |HTTPRequest|'s // body is a tee of |request|'s body." // We use ResourceRequest class for HTTPRequest. // FIXME: Support body. ResourceRequest request(m_request->url()); request.setRequestContext(WebURLRequest::RequestContextFetch); request.setDownloadToFile(true); request.setHTTPMethod(m_request->method()); const Vector<OwnPtr<FetchHeaderList::Header> >& list = m_request->headerList()->list(); for (size_t i = 0; i < list.size(); ++i) { request.addHTTPHeaderField(AtomicString(list[i]->first), AtomicString(list[i]->second)); } if (m_request->method() != "GET" && m_request->method() != "HEAD") { RefPtr<BlobDataHandle> blobDataHandle = m_request->blobDataHandle(); if (blobDataHandle.get()) { RefPtr<FormData> httpBody(FormData::create()); httpBody->appendBlob(blobDataHandle->uuid(), blobDataHandle); request.setHTTPBody(httpBody); } } // "2. Append `Referer`/empty byte sequence, if |HTTPRequest|'s |referrer| // is none, and `Referer`/|HTTPRequest|'s referrer, serialized and utf-8 // encoded, otherwise, to HTTPRequest's header list. // We set the referrer using workerGlobalScope's URL in // WorkerThreadableLoader. // "3. Append `Host`, ..." // FIXME: Implement this when the spec is fixed. // "4.If |HTTPRequest|'s force Origin header flag is set, append `Origin`/ // |HTTPRequest|'s origin, serialized and utf-8 encoded, to |HTTPRequest|'s // header list." // We set Origin header in updateRequestForAccessControl() called from // DocumentThreadableLoader::makeCrossOriginAccessRequest // "5. Let |credentials flag| be set if either |HTTPRequest|'s credentials // mode is |include|, or |HTTPRequest|'s credentials mode is |same-origin| // and the |CORS flag| is unset, and unset otherwise. ResourceLoaderOptions resourceLoaderOptions; resourceLoaderOptions.dataBufferingPolicy = DoNotBufferData; if (m_request->credentials() == FetchRequestData::IncludeCredentials || (m_request->credentials() == FetchRequestData::SameOriginCredentials && !m_corsFlag)) { resourceLoaderOptions.allowCredentials = AllowStoredCredentials; } ThreadableLoaderOptions threadableLoaderOptions; if (m_corsPreflightFlag) threadableLoaderOptions.preflightPolicy = ForcePreflight; if (m_corsFlag) threadableLoaderOptions.crossOriginRequestPolicy = UseAccessControl; else threadableLoaderOptions.crossOriginRequestPolicy = AllowCrossOriginRequests; m_loader = ThreadableLoader::create(*m_executionContext, this, request, threadableLoaderOptions, resourceLoaderOptions); }
void ResourceRequest::initializePlatformRequest(NetworkRequest& platformRequest, bool cookiesEnabled, bool isInitial, bool isRedirect) const { // If this is the initial load, skip the request body and headers. if (isInitial) platformRequest.setRequestInitial(timeoutInterval()); else { platformRequest.setRequestUrl(url().string(), httpMethod(), platformCachePolicyForRequest(*this), platformTargetTypeForRequest(*this), timeoutInterval()); platformRequest.setConditional(isConditional()); platformRequest.setSuggestedSaveName(suggestedSaveName()); if (httpBody() && !httpBody()->isEmpty()) { RefPtr<FormData> formData = httpBody(); #if ENABLE(BLOB) formData = formData->resolveBlobReferences(); #endif const Vector<FormDataElement>& elements = formData->elements(); // Use setData for simple forms because it is slightly more efficient. if (elements.size() == 1 && elements[0].m_type == FormDataElement::data) platformRequest.setData(elements[0].m_data.data(), elements[0].m_data.size()); else { for (unsigned i = 0; i < elements.size(); ++i) { const FormDataElement& element = elements[i]; if (element.m_type == FormDataElement::data) platformRequest.addMultipartData(element.m_data.data(), element.m_data.size()); else if (element.m_type == FormDataElement::encodedFile) platformRequest.addMultipartFilename(element.m_filename.characters(), element.m_filename.length()); else ASSERT_NOT_REACHED(); // Blobs should be resolved at this point. } } } // When ResourceRequest is reused by CacheResourceLoader, page refreshing or redirection, its cookies may be dirtied. We won't use these cookies any more. bool cookieHeaderMayBeDirty = isRedirect || cachePolicy() == WebCore::ReloadIgnoringCacheData || cachePolicy() == WebCore::ReturnCacheDataElseLoad; for (HTTPHeaderMap::const_iterator it = httpHeaderFields().begin(); it != httpHeaderFields().end(); ++it) { String key = it->key; String value = it->value; if (!key.isEmpty()) { if (equalIgnoringCase(key, "Cookie")) { // We won't use the old cookies of resourceRequest for new location because these cookies may be changed by redirection. if (cookieHeaderMayBeDirty) continue; // We need to check the encoding and encode the cookie's value using latin1 or utf8 to support unicode data. if (!value.containsOnlyLatin1()) { platformRequest.addHeader("Cookie", value.utf8().data()); continue; } } platformRequest.addHeader(key, value); } } // If request's cookies may be dirty, they must be set again. // If there aren't cookies in the header list, we need trying to add cookies. if (cookiesEnabled && (cookieHeaderMayBeDirty || !httpHeaderFields().contains("Cookie")) && !url().isNull()) { // Prepare a cookie header if there are cookies related to this url. String cookiePairs = cookieManager().getCookie(url(), WithHttpOnlyCookies); if (!cookiePairs.isEmpty()) platformRequest.addHeader("Cookie", cookiePairs.containsOnlyLatin1() ? cookiePairs.latin1().data() : cookiePairs.utf8().data()); } if (!httpHeaderFields().contains("Accept-Language")) platformRequest.addAcceptLanguageHeader(); } }