Example #1
0
func TestProxyService(t *testing.T) {
	var fs = httptest.NewServer(http.FileServer(http.Dir(".")))
	defer fs.Close()

	client, buf := proxyWithLog()

	get(t, fs, client, "/jquery_homepage.html")
	warnings := buf.String()
	if !strings.Contains(warnings, "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js") ||
		!strings.Contains(warnings, "http://code.jquery.com/jquery-1.4.2.min.js") ||
		!strings.Contains(warnings, "Contradicting") {
		t.Error("contradicting jquery versions does not issue warning")
	}
}
Example #2
0
func main() {
	flag.Parse()

	// The counter is published as a variable directly.
	ctr := new(Counter)
	expvar.Publish("counter", ctr)
	http.Handle("/counter", ctr)
	http.Handle("/", http.HandlerFunc(Logger))
	http.Handle("/go/", http.StripPrefix("/go/", http.FileServer(http.Dir(*webroot))))
	http.Handle("/chan", ChanCreate())
	http.HandleFunc("/flags", FlagServer)
	http.HandleFunc("/args", ArgServer)
	http.HandleFunc("/go/hello", HelloServer)
	http.HandleFunc("/date", DateServer)
	err := http.ListenAndServe(":12345", nil)
	if err != nil {
		log.Panicln("ListenAndServe:", err)
	}
}
Example #3
0
func TestProxyServiceTwoVersions(t *testing.T) {
	var fs = httptest.NewServer(http.FileServer(http.Dir(".")))
	defer fs.Close()

	client, buf := proxyWithLog()

	get(t, fs, client, "/w3schools.html")
	get(t, fs, client, "/php_man.html")
	if buf.String() != "" &&
		!strings.Contains(buf.String(), " uses jquery ") {
		t.Error("shouldn't warn on a single URL", buf.String())
	}
	get(t, fs, client, "/jquery1.html")
	warnings := buf.String()
	if !strings.Contains(warnings, "http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js") ||
		!strings.Contains(warnings, "jquery.1.4.js") ||
		!strings.Contains(warnings, "Contradicting") {
		t.Error("contradicting jquery versions (php_man.html, w3schools.html) does not issue warning", warnings)
	}
}
Example #4
0
	"strings"
	"testing"

	"github.com/renzuinc/goproxy"
	"github.com/renzuinc/goproxy/ext/image"
	"github.com/renzuinc/goproxy/http"
	"github.com/renzuinc/goproxy/http/httptest"
)

var acceptAllCerts = &tls.Config{InsecureSkipVerify: true}

var noProxyClient = &http.Client{Transport: &http.Transport{TLSClientConfig: acceptAllCerts}}

var https = httptest.NewTLSServer(nil)
var srv = httptest.NewServer(nil)
var fs = httptest.NewServer(http.FileServer(http.Dir(".")))

type QueryHandler struct{}

func (QueryHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	if err := req.ParseForm(); err != nil {
		panic(err)
	}
	io.WriteString(w, req.Form.Get("result"))
}

func init() {
	http.DefaultServeMux.Handle("/bobo", ConstantHanlder("bobo"))
	http.DefaultServeMux.Handle("/query", QueryHandler{})
}
Example #5
0
func ExampleStripPrefix() {
	// To serve a directory on disk (/tmp) under an alternate URL
	// path (/tmpfiles/), use StripPrefix to modify the request
	// URL's path before the FileServer sees it:
	http.Handle("/tmpfiles/", http.StripPrefix("/tmpfiles/", http.FileServer(http.Dir("/tmp"))))
}
Example #6
0
func ExampleFileServer() {
	// Simple static webserver:
	log.Fatal(http.ListenAndServe(":8080", http.FileServer(http.Dir("/usr/share/doc"))))
}