void ResourceRequest::updateFromSoupMessage(SoupMessage* soupMessage) { SoupURI* soupURI = soup_message_get_uri(soupMessage); GOwnPtr<gchar> uri(soup_uri_to_string(soupURI, FALSE)); m_url = KURL(KURL(), String::fromUTF8(uri.get())); m_httpMethod = String::fromUTF8(soupMessage->method); SoupMessageHeadersIter headersIter; const char* headerName; const char* headerValue; soup_message_headers_iter_init(&headersIter, soupMessage->request_headers); while (soup_message_headers_iter_next(&headersIter, &headerName, &headerValue)) m_httpHeaderFields.set(String::fromUTF8(headerName), String::fromUTF8(headerValue)); if (soupMessage->request_body->data) m_httpBody = FormData::create(soupMessage->request_body->data, soupMessage->request_body->length); #ifdef HAVE_LIBSOUP_2_29_90 SoupURI* firstParty = soup_message_get_first_party(soupMessage); if (firstParty) { GOwnPtr<gchar> firstPartyURI(soup_uri_to_string(firstParty, FALSE)); m_firstPartyForCookies = KURL(KURL(), String::fromUTF8(firstPartyURI.get())); } #endif m_soupFlags = soup_message_get_flags(soupMessage); // FIXME: m_allowCookies should probably be handled here and on // doUpdatePlatformRequest somehow. }
void setCookiesFromDOM(NetworkingContext* context, const KURL& firstParty, const KURL& url, const String& value) { SoupCookieJar* jar = context ? cookieJarForContext(context) : soupCookieJar(); if (!jar) return; GOwnPtr<SoupURI> origin(soup_uri_new(url.string().utf8().data())); GOwnPtr<SoupURI> firstPartyURI(soup_uri_new(firstParty.string().utf8().data())); // Get existing cookies for this origin. GSList* existingCookies = soup_cookie_jar_get_cookie_list(jar, origin.get(), TRUE); Vector<String> cookies; value.split('\n', cookies); const size_t cookiesCount = cookies.size(); for (size_t i = 0; i < cookiesCount; ++i) { GOwnPtr<SoupCookie> cookie(soup_cookie_parse(cookies[i].utf8().data(), origin.get())); if (!cookie) continue; // Make sure the cookie is not httpOnly since such cookies should not be set from JavaScript. if (soup_cookie_get_http_only(cookie.get())) continue; // Make sure we do not overwrite httpOnly cookies from JavaScript. if (httpOnlyCookieExists(existingCookies, soup_cookie_get_name(cookie.get()), soup_cookie_get_path(cookie.get()))) continue; soup_cookie_jar_add_cookie_with_first_party(jar, firstPartyURI.get(), cookie.release()); } soup_cookies_free(existingCookies); }