Преглед на файлове

fixed the host header issue

Mohamed Al Ashaal преди 6 години
родител
ревизия
c4916bf3a4
променени са 2 файла, в които са добавени 8 реда и са изтрити 5 реда
  1. 1 0
      flags.go
  2. 7 5
      server.go

+ 1 - 0
flags.go

@@ -9,6 +9,7 @@ import (
 import "github.com/mitchellh/go-homedir"
 
 var (
+	VERSION 	= "httpsify/v3.0.0"
 	HOME_DIR, _ = homedir.Dir()
 	HTTPS_ADDR  = flag.String("https", ":443", "the https address to listen on")
 	STORAGE     = flag.String("storage", path.Join(HOME_DIR, ".httpsify/certs"), "the ssl certs storage directory")

+ 7 - 5
server.go

@@ -2,7 +2,7 @@ package main
 
 import (
 	"context"
-	"crypto/tls"
+	// "crypto/tls"
 	"errors"
 	"io/ioutil"
 	"net/http"
@@ -30,20 +30,21 @@ func InitServer() error {
 			return errors.New("Unkown host(" + host + ")")
 		},
 	}
+	_ = m
 	s := &http.Server{
 		Addr:      *HTTPS_ADDR,
-		TLSConfig: &tls.Config{GetCertificate: m.GetCertificate},
+		// TLSConfig: &tls.Config{GetCertificate: m.GetCertificate},
 		Handler:   ServeHTTP(),
 	}
 	log.SetOutput(ioutil.Discard)
-	return s.ListenAndServeTLS("", "")
+	return s.ListenAndServe()
 }
 
 // The main server handler
 func ServeHTTP() http.Handler {
 	return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
 		if upstreams, ok := HOSTS[req.Host]; ok {
-			forwarder, _ := forward.New()
+			forwarder, _ := forward.New(forward.PassHostHeader(true))
 			loadbalancer, _ := roundrobin.New(forwarder)
 			for _, upstream := range upstreams {
 				if url, err := url.Parse(upstream); err == nil {
@@ -52,9 +53,10 @@ func ServeHTTP() http.Handler {
 					colorize(color.FgRed, "⇛", err.Error())
 				}
 			}
+			res.Header().Set("X-HTTPSIFY-Version", VERSION)
 			loadbalancer.ServeHTTP(res, req)
 			return
 		}
-		http.Error(res, "The request domain couldn't be found here", http.StatusNotImplemented)
+		http.Error(res, "The request service couldn't be found here", http.StatusNotImplemented)
 	})
 }