Example #1
0
func main() {
	flag.Parse()
	goquic.SetLogLevel(logLevel)

	if flag.NArg() != 1 {
		flag.Usage()
		return
	}

	proxyUrl := flag.Arg(0)

	log.Printf("About to listen on %d. Go to https://127.0.0.1:%d/", port, port)
	portStr := fmt.Sprintf(":%d", port)

	parsedUrl, err := url.Parse(proxyUrl)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("Starting reverse proxy for backend URL: %v", parsedUrl)

	err = goquic.ListenAndServe(portStr, cert, key, numOfServers, httputil.NewSingleHostReverseProxy(parsedUrl))
	if err != nil {
		log.Fatal(err)
	}
}
Example #2
0
func main() {
	flag.Parse()
	goquic.SetLogLevel(logLevel)

	useEncryption := false
	if len(cert) > 0 && len(key) > 0 {
		useEncryption = true
	}

	scheme := "http"
	if useEncryption {
		scheme = "https"
	}
	log.Printf("About to listen on %d. Go to %s://127.0.0.1:%d/", port, scheme, port)
	portStr := fmt.Sprintf(":%d", port)

	http.HandleFunc("/", httpHandler)
	http.Handle("/files/", http.StripPrefix("/files/", http.FileServer(http.Dir(serveRoot))))

	var err error

	if useEncryption {
		err = gospdyquic.ListenAndServeSecure(portStr, cert, key, numOfServers, nil)
	} else {
		err = gospdyquic.ListenAndServe(portStr, numOfServers, nil)
	}

	if err != nil {
		log.Fatal(err)
	}
}
Example #3
0
func main() {
	goquic.Initialize()
	goquic.SetLogLevel(logLevel)

	flag.Parse()

	conn, err := goquic.Dial("udp4", host)
	if err != nil {
		panic(err)
	}

	fmt.Println("Connect complete!", conn)

	st := conn.CreateStream()
	fmt.Println("CreateStream complete!", st)
	header := make(http.Header)
	header.Set(":host", "172.24.0.216:8080")
	header.Set(":version", "HTTP/1.0")
	header.Set(":method", "GET")
	header.Set(":path", "/")
	header.Set(":scheme", "http")
	st.WriteHeader(header, false)
	st.Write([]byte("GET / HTTP/1.0\r\n\r\n"))
	st.FinWrite()

	recvHeader, err := st.ReadHeader()
	if err != nil {
		panic(err)
	}
	fmt.Println("Header:", recvHeader)

	buf := make([]byte, 4096)
	n, err := st.Read(buf)
	if err != nil {
		panic(err)
	}
	fmt.Println("Response:", string(buf[:n]))

	n, err = st.Read(buf)
	if err == io.EOF {
		fmt.Println("Received EOF")
	} else if err != nil {
		panic(err)
	} else {
		fmt.Println("Response:", string(buf[:n]))
	}
}
Example #4
0
func main() {
	flag.Parse()
	goquic.SetLogLevel(logLevel)

	client := &http.Client{
		Transport: goquic.NewRoundTripper(false),
	}

	resp, err := client.Get(url)
	if err != nil {
		panic(err)
	}

	b, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}

	fmt.Println(string(b))
}
Example #5
0
func main() {
	startTime := time.Now()
	var done sync.WaitGroup
	results := make(map[int]*Result)

	signalChannel := make(chan os.Signal, 2)
	signal.Notify(signalChannel, os.Interrupt, syscall.SIGTERM)
	go func() {
		_ = <-signalChannel
		printResults(results, startTime)
		os.Exit(0)
	}()

	flag.Parse()

	if turnonLog {
		goquic.SetLogLevel(-1)
	}

	configuration := NewConfiguration()

	goMaxProcs := os.Getenv("GOMAXPROCS")

	if goMaxProcs == "" {
		runtime.GOMAXPROCS(runtime.NumCPU())
	}

	fmt.Printf("Dispatching %d clients\n", clients)

	done.Add(clients)
	for i := 0; i < clients; i++ {
		result := &Result{}
		results[i] = result
		go client(configuration, result, &done)

	}
	fmt.Println("Waiting for results...")
	done.Wait()
	printResults(results, startTime)
}
Example #6
0
func main() {
	flag.Parse()
	goquic.SetLogLevel(logLevel)

	if flag.NArg() != 1 {
		flag.Usage()
		return
	}

	useEncryption := false
	if len(cert) > 0 && len(key) > 0 {
		useEncryption = true
	}
	proxyUrl := flag.Arg(0)

	scheme := "http"
	if useEncryption {
		scheme = "https"
	}
	log.Printf("About to listen on %d. Go to %s://127.0.0.1:%d/", port, scheme, port)
	portStr := fmt.Sprintf(":%d", port)

	parsedUrl, err := url.Parse(proxyUrl)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("Starting reverse proxy for backend URL: %v", parsedUrl)

	if useEncryption {
		err = goquic.ListenAndServeSecure(portStr, cert, key, numOfServers, httputil.NewSingleHostReverseProxy(parsedUrl))
	} else {
		err = goquic.ListenAndServe(portStr, numOfServers, httputil.NewSingleHostReverseProxy(parsedUrl))
	}
	if err != nil {
		log.Fatal(err)
	}
}
Example #7
0
func main() {
	flag.Parse()
	goquic.SetLogLevel(logLevel)

	if len(cert) == 0 || len(key) == 0 {
		log.Fatal("QUIC doesn't support non-encrypted mode anymore. Please provide -cert and -key option!")
	}

	log.Printf("About to listen on %d. Go to https://127.0.0.1:%d/", port, port)
	portStr := fmt.Sprintf(":%d", port)

	http.HandleFunc("/", httpHandler)
	http.Handle("/files/", http.StripPrefix("/files/", http.FileServer(http.Dir(serveRoot))))

	server, err := goquic.NewServer(portStr, cert, key, numOfServers, http.DefaultServeMux, http.DefaultServeMux)
	if err != nil {
		log.Fatal(err)
	}

	http.Handle("/statistics/json", statisticsHandler(server))

	log.Fatal(server.ListenAndServe())
}