| 102 | var authRegexp = regexp.MustCompile(`((?i)\r\nauthorization:\s+)(\S+\s+)(\S+)`) |
| 103 | |
| 104 | func (zc *zeroResponseConn) Close() error { |
| 105 | err := zc.Conn.Close() |
| 106 | |
| 107 | zc.once.Do(func() { |
| 108 | zc.bufHolderMux.Lock() |
| 109 | defer zc.bufHolderMux.Unlock() |
| 110 | |
| 111 | // If buffer was already returned, it means there was some data written on the connection, nothing to do. |
| 112 | if zc.bufHolder == nil { |
| 113 | return |
| 114 | } |
| 115 | |
| 116 | // If we didn't write anything to this connection, and we've got timeout while reading data, it looks like |
| 117 | // slow a slow client failing to send a request to us. |
| 118 | if !zc.lastReadErrIsDeadlineExceeded.Load() { |
| 119 | return |
| 120 | } |
| 121 | |
| 122 | b := zc.bufHolder.buf |
| 123 | b = authRegexp.ReplaceAll(b, []byte("${1}${2}***")) // Replace value in Authorization header with ***. |
| 124 | |
| 125 | _ = zc.log.Log("msg", "read timeout, connection closed with no response", "read", strconv.Quote(string(b)), "remote", zc.RemoteAddr().String()) |
| 126 | |
| 127 | zc.returnPool.Put(zc.bufHolder) |
| 128 | zc.bufHolder = nil |
| 129 | }) |
| 130 | |
| 131 | return err |
| 132 | } |