Another evil hack… [entries|reading|network|archive]
simont

[ userinfo | dreamwidth userinfo ]
[ archive | journal archive ]

Thu 2004-12-02 10:39
Another evil hack…

… only this time it's Owen's fault.

LiveJournal has the terribly annoying bug that not everybody is forced to use my sensible journal style, and instead the system allows everyone to use the illegible and eye-torturing monstrosity of their choice. Fortunately, I can render any individual LJ page sane-looking simply by adding ?style=mine (or &style=mine) at the appropriate point in its URL. Unfortunately, doing this by hand every time I find a page too hard to read is a total pain.

So I've been searching, for some time, for a means to make my web browser automatically rewrite some kinds of LiveJournal URL to add this vital ‘make it legible’ clause. I've looked into writing a Mozilla/Firefox plugin, but couldn't find enough documentation; I've even grubbed about in Firefox's own JavaScript internals, in the hope of finding just the right file to tweak. No luck there either.

On Monday, Owen suggested a much higher-level solution: create a custom web proxy which does the rewrite and returns a 302 Moved Temporarily response containing the altered URL. Then set up a proxy_config.pac file which directs URLs to that proxy if and only if they need a rewrite, and otherwise fetches them in the normal way.

Three days later, I have just such a thing running on my Linux boxes both at work and at home (I haven't ported it to my home Windows box yet, but might give it a go at some point), and so far I haven't been able to detect it not working perfectly. Woo!

The fun bit, though, was arranging synchronisation of configuration. The .pac file needs to know precisely what my URL rewriting requirements are, so that it can reliably direct things to the rewriting proxy if and only if they need a rewrite. (I can't have the proxy receive URLs that don't need rewriting, since then it would have to retrieve them itself, and that would mean implementing a real HTTP client in it.) And of course the proxy needs to know my URL rewriting requirements too, since it has to implement them. But maintaining two sets of configuration in parallel is just asking for an editing error to cause them to get out of sync.

My solution – and here's where I suppose the blame has to stop being Owen's – was to embed a JavaScript interpreter library in my custom web proxy. (Debian helpfully provides such a thing in the libjs0 package.) So my .pac file now doubles as the web proxy's URL rewriting script: it declares a function called RewriteURL(), and then implements FindProxyForURL() in terms of that:

    if (RewriteURL(url) != url)
return "PROXY localhost:XXXXX";

So Mozilla loads this file as its proxy configuration, calls FindProxyForURL(), and everything works there. My custom proxy (which I'm currently calling ick-proxy, for obvious reasons!) loads the same JavaScript file, and calls RewriteURL() every time it gets an HTTP request. And if I want to change my URL rewriting configuration, I edit it in just one place and both halves of the mechanism adapt.

I'm rather pleased with that, in a disgusting sort of way. And it's nice to be able to blame someone else for the basic idea for once :-)

LinkReply
[personal profile] sparrowsionThu 2004-12-02 12:28
I've recently added Opera's style-sheet-switching widget to the toolbar. One click, and all stupid colours and unreadable fonts go away. And "debug mode with outline" is excellent for debugging complex cgi output. Attention other browser writers: this is far more useful than hiding away a global "Use own/author's CSS" in advanced settings. As in, it really is useful.
Link Reply to this
[identity profile] filecoreinuse.livejournal.comThu 2004-12-02 13:18
Damn you -- I'd been hoping noone would suggest a suitable project for a Firefox extension I can try out and thus waste hours of precious time...
Link Reply to this
[identity profile] mart.livejournal.comMon 2004-12-13 00:40

I love it! ;)

Link Reply to this
[identity profile] senji.livejournal.comFri 2005-02-18 12:07
OK, I'm just trying to install this but am running into problems due to the lack of documentation :-)

Am I supposed to run ick-proxy as a daemon or out of inetd? :)
Link Reply to this | Thread
[personal profile] simontFri 2005-02-18 13:38
OK, I've just written a man page. I hope it answers your questions :-)
Link Reply to this | Parent
[identity profile] caliston.livejournal.comThu 2006-07-27 08:56
[seen your posting in chiark.chat]

No doubt it's all water under the bridge now, but it's very easy to do this with squid. You just have a redirect_program directive and a bit of perl than rewrites the URL. See the bottom of this page (http://www.chiark.greenend.org.uk/~theom/riscos/othersoft.html)

Of course this means running everything through squid as a proxy, but if you run it on the local machine it's not too much overhead.
Link Reply to this | Thread
[personal profile] simontThu 2006-07-27 09:16
In some of the situations I'm using this proxy, I'm already talking to another web proxy or forwarding my HTTP connections through PuTTY's SOCKS interface. I think I prefer configuring Firefox directly to talk to wherever the "real" web happens to be, rather than trying to persuade squid to do the same. I'll stick with ick-proxy, but thanks for the heads-up :-)
Link Reply to this | Parent
[identity profile] dvae.livejournal.comWed 2008-04-02 08:33
surely greasemonkey would have been easier? and it's cross platform.
Link Reply to this | Thread
[personal profile] simontWed 2008-04-02 09:12
Not cross browser, though. Also, the original version of ick-proxy predated greasemonkey, as far as I can find out. So no, it wouldn't have been easier at the time.
Link Reply to this | Parent | Thread
[identity profile] dvae.livejournal.comWed 2008-04-02 14:13
excuses, excuses! :-)
Link Reply to this | Parent
navigation
[ go | Previous Entry | Next Entry ]
[ add | to Memories ]