Igor Tandetnik's Passthrough APP... Now on Github!
One of the many frustrations things about developing extensions for Internet Explorer is that certain seemingly...
Table of Contents
One of the many frustrations things about developing extensions for Internet Explorer is that certain seemingly essential capabilities are completely lacking. For example, you can see the headers being send with an HTTP request using the BeforeNavigate2 event. But you can't modify the headers. What's more, this event is only received for page or frame requests, not images, scripts and the like. Oh, and it is not fired for the main page when the user presses refresh, so it is extremely difficult to get consistent behavior even if you can live with its limited capabilities.
One of the nice things about developing extensions for Internet Explorer is that with sufficient effort you can do pretty much anything. The key phrase is "sufficient effort", and it many cases this means an orgy of trial-and-error and reverse engineering that would daunt even most developers expert in Windows development and COM.
Such is the case with the passthrough APP (Asynchronous Pluggable Protocol). The idea is simple. By implementing our own protocol handler (a capability supported by Windows) and registering it in place of the normal HTTP and HTTPS handlers, we can spy on and modify method invocations before forwarding them to the default implementation. This lets us claw back some of the missing features mentioned above, like modifying the HTTP headers of a request. The problem is that there are a lot of interfaces to support in order to mimic the default protocol implementation. Miss one and the whole browser will come crashing down around you.
Luckily famed IE guru Igor Tandetnik implemented a fully functional "Passthrough APP development toolkit" many years ago. This toolkit does the heavily lifting and is fairly easy to drop into an IE extension (known as a Browser Helper Object or BHO). The main problem is that Igor hasn't maintained the toolkit for years (although he kindly answers questions about it in the MSDN forums and elsewhere). There's a copy in the now-defunct Google Gears and some others floating around the web, but no one canonical location to get the latest version.
So I went ahead and posted a version on Github. I started with Igor's "beta" sources and updated them to work in IE8 and IE9 in a separate changeset so the changes are made are easily visible. I hope that hosting in Github will make it easier for people to find the sources and potentially post updates and improvements.
Speaking of which, the big drawback of the Passthrough APP is that it doesn't work if more than one BHO is using it in the same browser since it is only possible to register one HTTP handler (and no possibility for daisy-chaining). The generally accepted solution is to use API thunking instead, something that Google Gears also does. I'm planning to update the Passthrough APP to provide API thunking as an option with the same functionality (so I'll thunk all the IInternetProtocolRoot and IInternetProtocolEx methods and weave them into the passthrough sink).