chore: remove unnecessary code (#3161)

master
Kevin Wan 2 years ago committed by GitHub
parent ce4eb6ed61
commit 3da740b7fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -65,13 +65,6 @@ func (s *Server) build() error {
source <- up source <- up
} }
}, func(up Upstream, writer mr.Writer[rest.Route], cancel func(error)) { }, func(up Upstream, writer mr.Writer[rest.Route], cancel func(error)) {
target, err := up.Grpc.BuildTarget()
if err != nil {
cancel(err)
return
}
up.Name = target
var cli zrpc.Client var cli zrpc.Client
if s.dialer != nil { if s.dialer != nil {
cli = s.dialer(up.Grpc) cli = s.dialer(up.Grpc)

@ -290,13 +290,15 @@ func (ng *engine) signatureVerifier(signature signatureSetting) (func(chain.Chai
decrypters[fingerprint] = decrypter decrypters[fingerprint] = decrypter
} }
return func(chn chain.Chain) chain.Chain { return func(chn chain.Chain) chain.Chain {
var unsignedCallbacks []handler.UnsignedCallback if ng.unsignedCallback == nil {
if ng.unsignedCallback != nil { return chn.Append(handler.LimitContentSecurityHandler(ng.conf.MaxBytes,
unsignedCallbacks = append(unsignedCallbacks, ng.unsignedCallback) decrypters, signature.Expiry, signature.Strict))
} }
return chn.Append(handler.LimitContentSecurityHandler(ng.conf.MaxBytes, decrypters, signature.Expiry, signature.Strict, unsignedCallbacks)) return chn.Append(handler.LimitContentSecurityHandler(ng.conf.MaxBytes,
decrypters, signature.Expiry, signature.Strict, ng.unsignedCallback))
}, nil }, nil
} }

@ -18,12 +18,12 @@ type UnsignedCallback func(w http.ResponseWriter, r *http.Request, next http.Han
// ContentSecurityHandler returns a middleware to verify content security. // ContentSecurityHandler returns a middleware to verify content security.
func ContentSecurityHandler(decrypters map[string]codec.RsaDecrypter, tolerance time.Duration, func ContentSecurityHandler(decrypters map[string]codec.RsaDecrypter, tolerance time.Duration,
strict bool, callbacks ...UnsignedCallback) func(http.Handler) http.Handler { strict bool, callbacks ...UnsignedCallback) func(http.Handler) http.Handler {
return LimitContentSecurityHandler(maxBytes, decrypters, tolerance, strict, callbacks) return LimitContentSecurityHandler(maxBytes, decrypters, tolerance, strict, callbacks...)
} }
// LimitContentSecurityHandler returns a middleware to verify content security. // LimitContentSecurityHandler returns a middleware to verify content security.
func LimitContentSecurityHandler(maxBytesSize int64, decrypters map[string]codec.RsaDecrypter, tolerance time.Duration, func LimitContentSecurityHandler(limitBytes int64, decrypters map[string]codec.RsaDecrypter,
strict bool, callbacks []UnsignedCallback) func(http.Handler) http.Handler { tolerance time.Duration, strict bool, callbacks ...UnsignedCallback) func(http.Handler) http.Handler {
if len(callbacks) == 0 { if len(callbacks) == 0 {
callbacks = append(callbacks, handleVerificationFailure) callbacks = append(callbacks, handleVerificationFailure)
} }
@ -42,7 +42,7 @@ func LimitContentSecurityHandler(maxBytesSize int64, decrypters map[string]codec
r.Header.Get(contentSecurity)) r.Header.Get(contentSecurity))
executeCallbacks(w, r, next, strict, code, callbacks) executeCallbacks(w, r, next, strict, code, callbacks)
} else if r.ContentLength > 0 && header.Encrypted() { } else if r.ContentLength > 0 && header.Encrypted() {
LimitCryptionHandler(maxBytesSize, header.Key)(next).ServeHTTP(w, r) LimitCryptionHandler(limitBytes, header.Key)(next).ServeHTTP(w, r)
} else { } else {
next.ServeHTTP(w, r) next.ServeHTTP(w, r)
} }

@ -23,7 +23,7 @@ func CryptionHandler(key []byte) func(http.Handler) http.Handler {
} }
// LimitCryptionHandler returns a middleware to handle cryption. // LimitCryptionHandler returns a middleware to handle cryption.
func LimitCryptionHandler(maxBytesSize int64, key []byte) func(http.Handler) http.Handler { func LimitCryptionHandler(limitBytes int64, key []byte) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
cw := newCryptionResponseWriter(w) cw := newCryptionResponseWriter(w)
@ -34,7 +34,7 @@ func LimitCryptionHandler(maxBytesSize int64, key []byte) func(http.Handler) htt
return return
} }
if err := decryptBody(maxBytesSize, key, r); err != nil { if err := decryptBody(limitBytes, key, r); err != nil {
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
return return
} }
@ -44,8 +44,8 @@ func LimitCryptionHandler(maxBytesSize int64, key []byte) func(http.Handler) htt
} }
} }
func decryptBody(maxBytesSize int64, key []byte, r *http.Request) error { func decryptBody(limitBytes int64, key []byte, r *http.Request) error {
if maxBytesSize > 0 && r.ContentLength > maxBytesSize { if limitBytes > 0 && r.ContentLength > limitBytes {
return errContentLengthExceeded return errContentLengthExceeded
} }

Loading…
Cancel
Save