You're viewing a comment by Jens Bauer and its responses.

Jens Bauer Permalink
June 18, 2017, 08:38

Here's my modification; this modification removes all HTML from the web-page.
(not very useful I think, but the goal is to modify the HTML on-the-fly):

#!/usr/bin/nodejs

var http = require('http');

http.createServer(function(request, response) {
  var proxy = http.createClient(80, request.headers['host'])
  var proxy_request = proxy.request(request.method, request.url, request.headers);

  proxy_request.addListener('response', function (proxy_response) {
    proxy_response.buf = "";
    proxy_response.process = function(chunk){
      chunk = this.buf + chunk;
      var match = /^(.*)(\<[^>]*?)$/.exec(chunk);
      this.buf = match ? match[2] : "";
      if(match) chunk = match[1];
      chunk = chunk.replace(/\<[^>]*?\>/g, "");
      response.write(chunk, 'binary');
    };
    proxy_response.addListener('data', function(chunk) {
      this.process(chunk);
    });
    proxy_response.addListener('end', function() {
      this.process("");
      response.end();
    });
    response.writeHead(proxy_response.statusCode, proxy_response.headers);
  });
  request.addListener('data', function(chunk) {
    proxy_request.write(chunk, 'binary');
  });
  request.addListener('end', function() {
    proxy_request.end();
  });
}).listen(8080);

What am I up to ?
-My web-browser is extremely slow (Apple Safari 5.0.6) and I cannot upgrade it because I'm on Mac OS X on a PowerMac.
Especially eBay is using extremely much CPU time (due to the hundreds of 'ad pictures' on a page for a single item).
As I tend to open more than 10 eBay windows/tabs when looking for stuff, I spend a lot of time with a spinning beachball.

So I'll try creating a proxy-server, which modifies my HTML (especially inserting width and height in IMG tags if they're missing ... perhaps an improved version could also check CSS - or do a real pre-rendering).
If I had my way, I'd have cloud-rendering (like Opera Turbo). ;)

-It's likely that I'll change the proxy port from 8080 to something else (my squid3 currently runs on port 3128).

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "server_215": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.