Skip to content

Commit

Permalink
disable google clicktracking for search, add gunzipping for that
Browse files Browse the repository at this point in the history
  • Loading branch information
thejh committed Feb 10, 2012
1 parent 1b3a32e commit e4313c9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions injections/google-noclicktrack.coffee
@@ -0,0 +1,5 @@
{
urlregex: /www\.google\.de\/search/
search: ' onmousedown="return'
append: ';'
}
23 changes: 19 additions & 4 deletions proxy.coffee
Expand Up @@ -3,6 +3,7 @@ coffee = require 'coffee-script'
async = require 'async'
fs = require 'fs'
http = require 'http'
{createGunzip} = require 'zlib'
{checkURL} = require './urlcheck'
{InsertingStream} = require './streaminsert'

Expand Down Expand Up @@ -46,17 +47,31 @@ server_cb = (request, response) ->
proxy_request.on 'error', (err) ->
denyRequest response, err+'', 404
proxy_request.addListener 'response', (proxy_response) ->
writeToClient = (chunk) -> response.write chunk
writeToClient = (chunk) ->
return response.end() if chunk is null
response.write chunk
console.error "request for '#{fullurl}'"
#console.error " HEADERS: #{JSON.stringify request.headers}"
if not proxy_response.headers["content-type"]?.indexOf("text/")
if proxy_response.headers["content-type"]?.indexOf("text/") is 0 or proxy_response.headers["content-type"]?.indexOf("javascript") isnt -1
for injection in injections when ~fullurl.search injection.urlregex
writeToClient = do (writeToClient) ->
inserter = new InsertingStream injection.search, injection.append, writeToClient
(chunk) -> inserter.write chunk
(chunk) ->
return writeToClient null if chunk is null
inserter.write chunk
console.error " bugging '#{fullurl}'"
if proxy_response.headers['content-encoding'] is 'gzip'
console.error " unzipping"
delete proxy_response.headers['content-encoding']
writeToClient = do (writeToClient) ->
unzipper = createGunzip()
unzipper.on 'data', writeToClient
unzipper.on 'end', -> writeToClient null
(chunk) ->
return unzipper.end() if chunk is null
unzipper.write chunk
proxy_response.addListener 'data', writeToClient
proxy_response.addListener 'end', -> response.end()
proxy_response.addListener 'end', -> writeToClient null
delete proxy_response.headers['content-length']
delete proxy_response.headers['content-range']
response.writeHead proxy_response.statusCode, proxy_response.headers
Expand Down

0 comments on commit e4313c9

Please sign in to comment.