defaults dont work for conf

This commit is contained in:
Bel LaPointe
2019-02-23 18:54:33 -07:00
parent 73de851e81
commit 2099ae50c6
5 changed files with 66 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
package server
import (
"context"
"encoding/base64"
"errors"
"local/rproxy3/config"
@@ -10,6 +11,9 @@ import (
"net/http"
"net/url"
"strings"
"time"
"golang.org/x/time/rate"
)
const nsRouting = "routing"
@@ -36,6 +40,7 @@ type Server struct {
addr string
username string
password string
limiter *rate.Limiter
}
func (s *Server) Route(src, dst string) error {
@@ -80,7 +85,16 @@ func (s *Server) doAuth(foo http.HandlerFunc) http.HandlerFunc {
}
func (s *Server) Pre(foo http.HandlerFunc) http.HandlerFunc {
return s.doAuth(foo)
return func(w http.ResponseWriter, r *http.Request) {
ctx, can := context.WithTimeout(r.Context(), time.Second*time.Duration(config.GetTimeout()))
log.Printf("context iwth tiemout: %v", time.Second*time.Duration(config.GetTimeout()))
defer can()
if err := s.limiter.Wait(ctx); err != nil {
w.WriteHeader(http.StatusTooManyRequests)
return
}
s.doAuth(foo)(w, r)
}
}
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {