resp_header.go 856 B

123456789101112131415161718192021222324252627282930313233343536
  1. package binder
  2. import (
  3. "github.com/gofiber/utils/v2"
  4. "github.com/valyala/fasthttp"
  5. )
  6. // RespHeaderBinding is the respHeader binder for response header.
  7. type RespHeaderBinding struct {
  8. EnableSplitting bool
  9. }
  10. // Name returns the binding name.
  11. func (*RespHeaderBinding) Name() string {
  12. return "respHeader"
  13. }
  14. // Bind parses the response header and returns the result.
  15. func (b *RespHeaderBinding) Bind(resp *fasthttp.Response, out any) error {
  16. data := make(map[string][]string)
  17. for key, val := range resp.Header.All() {
  18. k := utils.UnsafeString(key)
  19. v := utils.UnsafeString(val)
  20. if err := formatBindData(b.Name(), out, data, k, v, b.EnableSplitting, false); err != nil {
  21. return err
  22. }
  23. }
  24. return parse(b.Name(), out, data)
  25. }
  26. // Reset resets the RespHeaderBinding binder.
  27. func (b *RespHeaderBinding) Reset() {
  28. b.EnableSplitting = false
  29. }