2024-01-15 13:06:27 +01:00
|
|
|
package clean
|
|
|
|
|
|
|
|
// Header sanitizes a string for use in request or response headers.
|
|
|
|
func Header(s string) string {
|
|
|
|
if s == "" || len(s) > MaxLength {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
result := make([]rune, 0, len(s))
|
|
|
|
|
|
|
|
for _, r := range s {
|
2024-01-16 12:14:06 +01:00
|
|
|
if r > 31 && r < 127 {
|
2024-01-15 13:06:27 +01:00
|
|
|
result = append(result, r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return string(result)
|
|
|
|
}
|