use string instead of *string for Proxy.cert

Makes it easier to check for default values.
Fixes #37.
This commit is contained in:
Barna Csorogi 2018-04-06 12:37:45 +08:00
parent fa9a01f4fe
commit 6760ec46a2
2 changed files with 7 additions and 7 deletions

View File

@ -32,7 +32,7 @@ var (
func main() { func main() {
flag.Parse() flag.Parse()
p := proxy.New(*host, cert) p := proxy.New(*host, *cert)
if (*ca == "") != (*caKey == "") { if (*ca == "") != (*caKey == "") {
log.Fatalln("must specify both CA certificate and key") log.Fatalln("must specify both CA certificate and key")

View File

@ -24,14 +24,14 @@ type Proxy struct {
user string user string
pass string pass string
host string host string
cert *string cert string
} }
type Transcoder interface { type Transcoder interface {
Transcode(*ResponseWriter, *ResponseReader, http.Header) error Transcode(*ResponseWriter, *ResponseReader, http.Header) error
} }
func New(host string, cert *string) *Proxy { func New(host string, cert string) *Proxy {
p := &Proxy{ p := &Proxy{
transcoders: make(map[string]Transcoder), transcoders: make(map[string]Transcoder),
ml: nil, ml: nil,
@ -48,12 +48,12 @@ func (p *Proxy) EnableMitm(ca, key string) error {
} }
var config *tls.Config var config *tls.Config
if p.cert != nil { if p.cert != "" {
roots, err := x509.SystemCertPool() roots, err := x509.SystemCertPool()
if err != nil { if err != nil {
return err return err
} }
pem, err := ioutil.ReadFile(*p.cert) pem, err := ioutil.ReadFile(p.cert)
if err != nil { if err != nil {
return err return err
} }
@ -168,12 +168,12 @@ func (p *Proxy) handleLocalRequest(w http.ResponseWriter, r *http.Request) error
</html>`, read, written, float64(written)/float64(read)*100)) </html>`, read, written, float64(written)/float64(read)*100))
return nil return nil
} else if r.Method == "GET" && r.URL.Path == "/cacert" { } else if r.Method == "GET" && r.URL.Path == "/cacert" {
if p.cert == nil { if p.cert == "" {
http.NotFound(w, r) http.NotFound(w, r)
return nil return nil
} }
w.Header().Set("Content-Type", "application/x-x509-ca-cert") w.Header().Set("Content-Type", "application/x-x509-ca-cert")
http.ServeFile(w, r, *p.cert) http.ServeFile(w, r, p.cert)
return nil return nil
} else { } else {
w.WriteHeader(http.StatusNotImplemented) w.WriteHeader(http.StatusNotImplemented)