~jzs/aproxy

18a6f09cae7f280a2a9f506feceaad9e6ef27ef3 — Jens Zeilund 2 years ago d3c0922
Clean up and remove debug code
1 files changed, 13 insertions(+), 24 deletions(-)

M aproxy.go
M aproxy.go => aproxy.go +13 -24
@@ 1,6 1,7 @@
package main

import (
	"crypto/tls"
	"flag"
	"fmt"
	"keybase/sketchground/aproxygo/aproxy"


@@ 10,7 11,6 @@ import (
	"net/url"
	"strings"
	"sync"
	"time"

	"golang.org/x/crypto/acme/autocert"
)


@@ 114,15 114,13 @@ func main() {
	wg := sync.WaitGroup{}
	wg.Add(1)
	go func() {
		/*
			log.Println("Starting reverse proxy for ssl connections")
			s := &http.Server{
				Addr:      ":https",
				TLSConfig: &tls.Config{GetCertificate: mgr.GetCertificate},
				Handler:   NewP(true, tracker),
			}
			log.Fatal(s.ListenAndServeTLS("", ""))
		*/
		log.Println("Starting reverse proxy for ssl connections")
		s := &http.Server{
			Addr:      ":https",
			TLSConfig: &tls.Config{GetCertificate: mgr.GetCertificate},
			Handler:   NewP(true, tracker),
		}
		log.Fatal(s.ListenAndServeTLS("", ""))
		wg.Done()
	}()
	wg.Add(1)


@@ 133,14 131,7 @@ func main() {
	}()
	wg.Wait()

	// Shut down track channel...

	//TODO: Process left of logs for service. Then shut down.
	fmt.Println("SLeeping before shutdown")
	time.Sleep(10 * time.Second)
	fmt.Println("going down")
	tracker.Shutdown()
	fmt.Println("went down")
}

func NewP(secure bool, t *aproxy.Tracker) *P {


@@ 157,13 148,11 @@ type P struct {

func (p *P) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
	log.Printf("Receiving quest on path: %v", req.URL)
	/*
		if !p.secure { // Redirect always if not secure.
			u := fmt.Sprintf("https://%v%v", req.Host, req.URL.Path)
			http.Redirect(rw, req, u, http.StatusFound)
			return
		}
	*/
	if !p.secure { // Redirect always if not secure.
		u := fmt.Sprintf("https://%v%v", req.Host, req.URL.Path)
		http.Redirect(rw, req, u, http.StatusFound)
		return
	}

	// TODO: Investigate if this should be guarded for concurrent access?
	p.t.Track(req.Context(), req)