Exemple #1
0
func main() {
	flag.Parse()
	if *f == "" {
		log.Print("From required.")
		flag.Usage()
		os.Exit(1)
	}
	if *t == "" {
		log.Print("To required.")
		flag.Usage()
		os.Exit(1)
	}
	tu, err := url.Parse(*t)
	if err != nil {
		log.Fatalf("To address given (%v) is not a valid url %v", *t, err)
	}
	if tu.Scheme != "https" && tu.Scheme != "http" {
		log.Fatalf("To address given (%v) does not have http or https as scheme", *t)
	}
	http.HandleFunc("/", server.Mitm(tu))
	log.Fatal(http.ListenAndServe(*f, nil))
}
Exemple #2
0
func main() {
	rand.Seed(time.Now().UTC().UnixNano())
	log.Println("Testing mitm streaming with locks.")
	serverChunks := RandomChunks("DOWNLOAD")
	uploadChunks := RandomChunks("UPLOAD")

	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		log.Printf("request received")
		uploadChunks.readChunks(r.Body)
		log.Printf("%s upload stream check completed.", uploadChunks.mkr)
		serverChunks.sendChunks(w)
	}))
	defer ts.Close()

	tsurl, err := url.Parse(ts.URL)
	if err != nil {
		log.Fatalf("unable to parse local test url %v\n", ts.URL)
	}

	mitmts := httptest.NewServer(http.HandlerFunc(server.Mitm(tsurl)))
	defer mitmts.Close()

	req, err := http.NewRequest("POST", mitmts.URL, uploadChunks)
	if err != nil {
		log.Fatalf("unable to create request to server %v\n", err)
	}

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Fatalf("unable to get mitm server %v\n", err)
	}

	serverChunks.readChunks(res.Body)
	log.Printf("DOWNLOAD: verification of second greeting complete.\n")

	log.Println("All tests passed.")
}