internal/server: clean up NewServer
This commit is contained in:
parent
e1e255b138
commit
0a5ff8dfaf
|
@ -13,6 +13,7 @@ import (
|
|||
proto "git.xeserv.us/xena/route/proto"
|
||||
"github.com/Xe/ln"
|
||||
"github.com/mtneug/pkg/ulid"
|
||||
"github.com/oxtoacart/bpool"
|
||||
kcp "github.com/xtaci/kcp-go"
|
||||
"golang.org/x/crypto/acme/autocert"
|
||||
"golang.org/x/net/context"
|
||||
|
@ -136,18 +137,15 @@ func New(cfg Config) (*Server, error) {
|
|||
Manager: m,
|
||||
}
|
||||
|
||||
go s.listenKCP(context.Background(), cfg.BackendKCPAddr, &tls.Config{
|
||||
tc := &tls.Config{
|
||||
GetCertificate: m.GetCertificate,
|
||||
})
|
||||
}
|
||||
|
||||
go s.listenTCP(context.Background(), cfg.BackendTCPAddr, &tls.Config{
|
||||
GetCertificate: m.GetCertificate,
|
||||
})
|
||||
go s.listenKCP(context.Background(), cfg.BackendKCPAddr, tc)
|
||||
go s.listenTCP(context.Background(), cfg.BackendTCPAddr, tc)
|
||||
|
||||
gs := grpc.NewServer(grpc.Creds(credentials.NewTLS(&tls.Config{
|
||||
GetCertificate: m.GetCertificate,
|
||||
InsecureSkipVerify: true,
|
||||
})))
|
||||
// gRPC setup
|
||||
gs := grpc.NewServer(grpc.Creds(credentials.NewTLS(tc)))
|
||||
|
||||
proto.RegisterBackendsServer(gs, &Backend{Server: s})
|
||||
proto.RegisterRoutesServer(gs, &Route{Server: s})
|
||||
|
@ -194,7 +192,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
Director: s.Director,
|
||||
Transport: s.ts,
|
||||
FlushInterval: 1 * time.Second,
|
||||
//BufferPool: bpool.NewBytePool(256, 4096),
|
||||
BufferPool: bpool.NewBytePool(256, 4096),
|
||||
}
|
||||
|
||||
rp.ServeHTTP(w, r)
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDirector(t *testing.T) {
|
||||
s := &Server{}
|
||||
|
||||
req, err := http.NewRequest("GET", "https://cetacean.club/", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
req.Header.Add("X-Forwarded-For", "Rick-James")
|
||||
req.Header.Add("X-Client-Ip", "56.32.51.84")
|
||||
|
||||
s.Director(req)
|
||||
|
||||
for _, header := range []string{"X-Forwarded-For", "X-Client-Ip"} {
|
||||
t.Run(header, func(t *testing.T) {
|
||||
val := req.Header.Get(header)
|
||||
if val != "" {
|
||||
t.Fatalf("expected header %q to have no value, got: %v", header, val)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue