diff --git a/server/middleware.go b/server/middleware.go index 2cfbf06..c9f7918 100644 --- a/server/middleware.go +++ b/server/middleware.go @@ -8,14 +8,13 @@ import ( "errors" "io" "io/ioutil" + "net/http" "time" peeringCrypto "forge.cadoles.com/Cadoles/go-http-peering/crypto" peering "forge.cadoles.com/Cadoles/go-http-peering" jwt "github.com/dgrijalva/jwt-go" - - "net/http" ) const ( @@ -38,7 +37,6 @@ func Authenticate(store peering.Store, key *rsa.PublicKey, funcs ...OptionFunc) middleware := func(next http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { - serverToken := r.Header.Get(ServerTokenHeader) if serverToken == "" { sendError(w, http.StatusUnauthorized) @@ -77,6 +75,7 @@ func Authenticate(store peering.Store, key *rsa.PublicKey, funcs ...OptionFunc) return } sendError(w, http.StatusUnauthorized) + return case ErrPeerRejected: if err := store.UpdateLastContact(serverClaims.PeerID, r.RemoteAddr, time.Now()); err != nil { logger.Printf("[ERROR] %s", err) @@ -115,7 +114,6 @@ func Authenticate(store peering.Store, key *rsa.PublicKey, funcs ...OptionFunc) r.Body = ioutil.NopCloser(bytes.NewBuffer(body)) next.ServeHTTP(w, r) - } return http.HandlerFunc(fn) }