guts.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2018 The Go Authors. 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. // Package httpguts provides functions implementing various details
  5. // of the HTTP specification.
  6. //
  7. // This package is shared by the standard library (which vendors it)
  8. // and x/net/http2. It comes with no API stability promise.
  9. package httpguts
  10. import (
  11. "net/textproto"
  12. "strings"
  13. )
  14. // ValidTrailerHeader reports whether name is a valid header field name to appear
  15. // in trailers.
  16. // See RFC 7230, Section 4.1.2
  17. func ValidTrailerHeader(name string) bool {
  18. name = textproto.CanonicalMIMEHeaderKey(name)
  19. if strings.HasPrefix(name, "If-") || badTrailer[name] {
  20. return false
  21. }
  22. return true
  23. }
  24. var badTrailer = map[string]bool{
  25. "Authorization": true,
  26. "Cache-Control": true,
  27. "Connection": true,
  28. "Content-Encoding": true,
  29. "Content-Length": true,
  30. "Content-Range": true,
  31. "Content-Type": true,
  32. "Expect": true,
  33. "Host": true,
  34. "Keep-Alive": true,
  35. "Max-Forwards": true,
  36. "Pragma": true,
  37. "Proxy-Authenticate": true,
  38. "Proxy-Authorization": true,
  39. "Proxy-Connection": true,
  40. "Range": true,
  41. "Realm": true,
  42. "Te": true,
  43. "Trailer": true,
  44. "Transfer-Encoding": true,
  45. "Www-Authenticate": true,
  46. }