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() {
flag.Parse()
p := proxy.New(*host, cert)
p := proxy.New(*host, *cert)
if (*ca == "") != (*caKey == "") {
log.Fatalln("must specify both CA certificate and key")

View file

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