GetBytes returns b unchanged when Immutable is off or b is read-only (rodata). Otherwise, it returns a detached copy.
(b []byte)
| 811 | // GetBytes returns b unchanged when Immutable is off or b is read-only (rodata). |
| 812 | // Otherwise, it returns a detached copy. |
| 813 | func (app *App) GetBytes(b []byte) []byte { |
| 814 | if !app.config.Immutable || len(b) == 0 { |
| 815 | return b |
| 816 | } |
| 817 | if isReadOnly(unsafe.Pointer(unsafe.SliceData(b))) { //nolint:gosec // pointer check avoids unnecessary copy |
| 818 | return b // rodata → safe to return as-is |
| 819 | } |
| 820 | return utils.CopyBytes(b) // detach when backed by request/response memory |
| 821 | } |
| 822 | |
| 823 | // Adds an ip address to TrustProxyConfig.ranges or TrustProxyConfig.ips based on whether it is an IP range or not |
| 824 | func (app *App) handleTrustedProxy(ipAddress string) { |