github.com/searKing/golang/go@v1.2.117/net/http/interceptors.recover.go (about) 1 // Copyright 2020 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package http 6 7 import ( 8 "io" 9 "net/http" 10 "net/http/httputil" 11 "strings" 12 13 "github.com/searKing/golang/go/error/builtin" 14 ) 15 16 // Recover and dump HTTP request if broken pipe 17 func Recover(writer io.Writer, req *http.Request, recoverHandler func(err any) any) any { 18 return builtin.Recover(writer, recoverHandler, func() string { 19 httpRequest, _ := httputil.DumpRequest(req, false) 20 headers := strings.Split(string(httpRequest), "\r\n") 21 for idx, header := range headers { 22 current := strings.Split(header, ":") 23 if current[0] == "Authorization" { 24 headers[idx] = current[0] + ": *" 25 } 26 } 27 return string(httpRequest) 28 }) 29 }