defaults dont work for conf
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user