mirror of
https://github.com/axllent/mailpit.git
synced 2026-06-28 06:56:06 +00:00
Chore: Refactor error handling and resource management across multiple files (golangci-lint)
- Updated error handling to use the error return value for resource closures in tests and functions, ensuring proper error reporting. - Replaced direct calls to `Close()` with deferred functions that handle errors gracefully. - Improved readability by using `strings.ReplaceAll` instead of `strings.Replace` for string manipulation. - Enhanced network connection handling by adding default cases for unsupported network types. - Updated HTTP response handling to use the appropriate status codes and error messages. - Removed unused variables and commented-out code to clean up the codebase.
This commit is contained in:
@@ -290,8 +290,9 @@ func middleWareFunc(fn http.HandlerFunc) http.HandlerFunc {
|
||||
}
|
||||
|
||||
// Check basic authentication headers if configured.
|
||||
// OPTIONS requests are skipped if CORS is enabled, since browsers omit credentials for preflight.
|
||||
if !(AccessControlAllowOrigin != "" && r.Method == http.MethodOptions) && auth.UICredentials != nil {
|
||||
// OPTIONS requests are skipped if CORS is enabled, since browsers omit credentials for preflight checks.
|
||||
isCORSOptionsRequest := AccessControlAllowOrigin != "" && r.Method == http.MethodOptions
|
||||
if !isCORSOptionsRequest && auth.UICredentials != nil {
|
||||
user, pass, ok := r.BasicAuth()
|
||||
|
||||
if !ok {
|
||||
@@ -312,7 +313,7 @@ func middleWareFunc(fn http.HandlerFunc) http.HandlerFunc {
|
||||
|
||||
w.Header().Set("Content-Encoding", "gzip")
|
||||
gz := gzip.NewWriter(w)
|
||||
defer gz.Close()
|
||||
defer func() { _ = gz.Close() }()
|
||||
gzr := gzipResponseWriter{Writer: gz, ResponseWriter: w}
|
||||
fn(gzr, r)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user