gtk webkit 设置user-agent
来源:互联网 发布:网络对人的影响 编辑:程序博客网 时间:2024/05/25 21:34
如果底层的网络模块使用的是soup
ResourceHandleSoup.cpp中
static bool startHttp(ResourceHandle* handle)
{
ASSERT(handle);
SoupSession* session = handle->defaultSession();
ensureSessionIsInitialized(session);
ResourceHandleInternal* d = handle->getInternal();
ResourceRequest request(handle->request());
KURL url(request.url());
url.removeFragmentIdentifier();
request.setURL(url);
request.setHTTPUserAgent("Mozilla/5.0 (iPad; U; CPU OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5");
d->m_msg = request.toSoupMessage();
if (!d->m_msg)
return false;
if(!handle->shouldContentSniff())
soup_message_disable_feature(d->m_msg, SOUP_TYPE_CONTENT_SNIFFER);
g_signal_connect(d->m_msg, "restarted", G_CALLBACK(restartedCallback), handle);
g_signal_connect(d->m_msg, "got-headers", G_CALLBACK(gotHeadersCallback), handle);
g_signal_connect(d->m_msg, "content-sniffed", G_CALLBACK(contentSniffedCallback), handle);
g_signal_connect(d->m_msg, "got-chunk", G_CALLBACK(gotChunkCallback), handle);
#ifdef HAVE_LIBSOUP_2_29_90
String firstPartyString = request.firstPartyForCookies().string();
if (!firstPartyString.isEmpty()) {
GOwnPtr<SoupURI> firstParty(soup_uri_new(firstPartyString.utf8().data()));
soup_message_set_first_party(d->m_msg, firstParty.get());
}
#endif
g_object_set_data(G_OBJECT(d->m_msg), "resourceHandle", reinterpret_cast<void*>(handle));
FormData* httpBody = d->m_request.httpBody();
if (httpBody && !httpBody->isEmpty()) {
size_t numElements = httpBody->elements().size();
// handle the most common case (i.e. no file upload)
if (numElements < 2) {
Vector<char> body;
httpBody->flatten(body);
soup_message_set_request(d->m_msg, d->m_request.httpContentType().utf8().data(),
SOUP_MEMORY_COPY, body.data(), body.size());
} else {
/*
* we have more than one element to upload, and some may
* be (big) files, which we will want to mmap instead of
* copying into memory; TODO: support upload of non-local
* (think sftp://) files by using GIO?
*/
soup_message_body_set_accumulate(d->m_msg->request_body, FALSE);
for (size_t i = 0; i < numElements; i++) {
const FormDataElement& element = httpBody->elements()[i];
if (element.m_type == FormDataElement::data)
soup_message_body_append(d->m_msg->request_body, SOUP_MEMORY_TEMPORARY, element.m_data.data(), element.m_data.size());
else {
/*
* mapping for uploaded files code inspired by technique used in
* libsoup's simple-httpd test
*/
GError* error = 0;
gchar* fileName = filenameFromString(element.m_filename);
GMappedFile* fileMapping = g_mapped_file_new(fileName, false, &error);
g_free(fileName);
if (error) {
g_error_free(error);
g_signal_handlers_disconnect_matched(d->m_msg, G_SIGNAL_MATCH_DATA,
0, 0, 0, 0, handle);
g_object_unref(d->m_msg);
d->m_msg = 0;
return false;
}
SoupBuffer* soupBuffer = soup_buffer_new_with_owner(g_mapped_file_get_contents(fileMapping),
g_mapped_file_get_length(fileMapping),
fileMapping,
#if GLIB_CHECK_VERSION(2, 21, 3)
reinterpret_cast<GDestroyNotify>(g_mapped_file_unref));
#else
reinterpret_cast<GDestroyNotify>(g_mapped_file_free));
#endif
soup_message_body_append_buffer(d->m_msg->request_body, soupBuffer);
soup_buffer_free(soupBuffer);
}
}
}
}
// balanced by a deref() in finishedCallback, which should always run
handle->ref();
// Balanced in ResourceHandleInternal's destructor; we need to
// keep our own ref, because after queueing the message, the
// session owns the initial reference.
g_object_ref(d->m_msg);
soup_session_queue_message(session, d->m_msg, finishedCallback, handle);
return true;
}
红色的部分就是设置user-agent的地方
- gtk webkit 设置user-agent
- 火狐设置User Agent
- PHP设置User Agent
- httpurlconnection设置user-agent参数
- py3 爬虫设置user-agent
- Firefox中User-Agent设置和用途
- c# 设置axwindows的User-agent信息
- chencang-----为爬虫设置User-Agent
- 设置 PhantomJs 的 User-Agent 的方法
- User Agent
- user agent
- User Agent
- User Agent
- User Agent
- 'User-Agent
- user-Agent
- User-Agent
- user--agent
- Spread WPF-Silverlight CTP 探秘
- 栅格那点儿事(三)---关于压缩
- 《深入理解Android》导读之JNI
- php面试题
- 美国某知名大学计算机博士家庭作业。。。
- gtk webkit 设置user-agent
- 窗口大小控制MINMAXINFO
- Thread.setDaemon设置说明
- java——(常量、变量、基本类型、进制、运算符)总结
- ClipCursor
- Eclipse反编译工具Jad及插件JadClipse配置
- 强力ROOT工具,适用于android 2.0 3.0 4.0
- HDOJ 1233:还是畅通工程 普里姆算法求最小生成树
- android2.3 内外sdcard切换