在IE中Hook http/https协议导致GET请求是顺序的
我正在使用 PassthruAPP挂钩 IE 发出的 HTTP/HTTPS 请求的方法。
它在大多数情况下运行良好,但我注意到一个问题。一次只有一个下载线程处于活动状态,通常 IE 使用两个下载线程。我可以看到创建了两个 IInternetProtocol 对象,但 IE 一次只使用一个。
IE7出现这种情况,其他版本还没试过。
问题似乎是,当为任何默认处理程序调用 IInternetSession::RegisterNameSpace 时,IE 会回退到一次下载一个项目。即使我正在注册 HTTPS 处理程序,下面的代码也会导致 HTTP 下载按顺序进行。注册“file://”会导致同样的问题。
CComPtr<IInternetSession> spSession;
CoInternetGetSession(0, &spSession, 0);
MetaFactory::CreateInstance(CLSID_HttpSProtocol, &m_spCFHTTPS);
spSession->RegisterNameSpace(m_spCFHTTPS, CLSID_NULL, L"https", 0, 0, 0)
页面上的前几项总是会发生这种情况,但似乎在发布文档完整后,可以再次发生并发下载。例如,页面加载完成后执行的 JavaScript 代码可以同时加载图像。
I'm using the PassthruAPP method to hook into HTTP/HTTPS requests made by IE.
It's working well for the most part, however I noticed a problem. Only one download thread is active at a time, normally IE uses two download threads. I can see two IInternetProtocol objects getting created, but IE uses only one at a time.
This is happening with IE7, I haven't tried with other versions yet.
The problem seems to be that IE falls back to downloading items one at a time when IInternetSession::RegisterNameSpace
is called for any of its default handlers. The code below causes HTTP downloads to be sequential even though I am registering a HTTPS handler. Registering for 'file://' causes the same problem.
CComPtr<IInternetSession> spSession;
CoInternetGetSession(0, &spSession, 0);
MetaFactory::CreateInstance(CLSID_HttpSProtocol, &m_spCFHTTPS);
spSession->RegisterNameSpace(m_spCFHTTPS, CLSID_NULL, L"https", 0, 0, 0)
This always happens for the first few items on the page, but it seems that after the document complete is issued, concurrent downloads can occur again. For example Javascript code that is executed after the page has finished loading can load images concurrently just fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以通过在已注册的 HTTP/HTTPS 协议上修补
InternetProtocolRootEx::StartEx()
的 COM VTable 来解决此问题。由于这不会直接替换协议处理程序,因此 IE 不会回退到单线程模型。该技术的描述如下:
http: //web.archive.org/web/20130313164317/http://www.blackfishsoftware.com/blog/don/passthroughapp_bho_toolbar_intercepting_requests_responses
It's possible to get around this problem by patching the COM VTable for
InternetProtocolRootEx::StartEx()
on the registered HTTP/HTTPS protocols. Since this does not replace the protocol handler directly, IE won't fallback to the single thread model.The technique is described here:
http://web.archive.org/web/20130313164317/http://www.blackfishsoftware.com/blog/don/passthroughapp_bho_toolbar_intercepting_requests_responses
是的,这是设计上已知的,并且在不同的地方都有记录。 (这样做是因为我们无法对协议处理程序的线程安全性做出假设)
这是建议您不要尝试包装 HTTP/HTTPS 协议的众多原因之一。
Yes, this is known, by design, and documented in various places. (It's done because we cannot make assumptions about the thread safety of protocol handlers)
This is one of MANY reasons that it's suggested that you do not attempt to wrap the HTTP/HTTPS protocols.