This is an example of using goproxy, a fast and robust multithread proxy engine to develop an HTTP proxy that rewrites content on the fly, with multiple search and substitutions. It can be useful for debugging and other less noble (but useful) purposes …

// rewriting_proxy project main.go
package main

import (


var replacements = []struct {
	from []byte
	to   []byte
	{[]byte("#e8ecec"), []byte("Red")},                       // ugly colors!!
	{[]byte("Comic Sans MS"), []byte("Lucida Sans Unicode")}, // for eyes sanity
	{[]byte("Java "), []byte("Golang ")},                     // just joking

func myHandler(resp *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
	readBody, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		//TODO handle read error gracefully
		return resp
	for _, elem := range replacements {
		readBody = bytes.Replace(readBody, elem.from,, -1)
	resp.Body = ioutil.NopCloser(bytes.NewReader(readBody))
	return resp

func main() {
	verbose := flag.Bool("v", true, "should every proxy request be logged to stdout")
	proxy := goproxy.NewProxyHttpServer()
	proxy.Verbose = *verbose
	log.Fatal(http.ListenAndServe(":8081", proxy))