1
0

test_response_writer.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package http
  2. import (
  3. "net/http"
  4. )
  5. // TestResponseWriter DEPRECATED: We recommend you use http://golang.org/pkg/net/http/httptest instead.
  6. type TestResponseWriter struct {
  7. // StatusCode is the last int written by the call to WriteHeader(int)
  8. StatusCode int
  9. // Output is a string containing the written bytes using the Write([]byte) func.
  10. Output string
  11. // header is the internal storage of the http.Header object
  12. header http.Header
  13. }
  14. // Header DEPRECATED: We recommend you use http://golang.org/pkg/net/http/httptest instead.
  15. func (rw *TestResponseWriter) Header() http.Header {
  16. if rw.header == nil {
  17. rw.header = make(http.Header)
  18. }
  19. return rw.header
  20. }
  21. // Write DEPRECATED: We recommend you use http://golang.org/pkg/net/http/httptest instead.
  22. func (rw *TestResponseWriter) Write(bytes []byte) (int, error) {
  23. // assume 200 success if no header has been set
  24. if rw.StatusCode == 0 {
  25. rw.WriteHeader(200)
  26. }
  27. // add these bytes to the output string
  28. rw.Output = rw.Output + string(bytes)
  29. // return normal values
  30. return 0, nil
  31. }
  32. // WriteHeader DEPRECATED: We recommend you use http://golang.org/pkg/net/http/httptest instead.
  33. func (rw *TestResponseWriter) WriteHeader(i int) {
  34. rw.StatusCode = i
  35. }