...

Source file src/github.com/stretchr/testify/http/test_response_writer.go

Documentation: github.com/stretchr/testify/http

     1  package http
     2  
     3  import (
     4  	"net/http"
     5  )
     6  
     7  // Deprecated: Use [net/http/httptest] instead.
     8  type TestResponseWriter struct {
     9  
    10  	// StatusCode is the last int written by the call to WriteHeader(int)
    11  	StatusCode int
    12  
    13  	// Output is a string containing the written bytes using the Write([]byte) func.
    14  	Output string
    15  
    16  	// header is the internal storage of the http.Header object
    17  	header http.Header
    18  }
    19  
    20  // Deprecated: Use [net/http/httptest] instead.
    21  func (rw *TestResponseWriter) Header() http.Header {
    22  
    23  	if rw.header == nil {
    24  		rw.header = make(http.Header)
    25  	}
    26  
    27  	return rw.header
    28  }
    29  
    30  // Deprecated: Use [net/http/httptest] instead.
    31  func (rw *TestResponseWriter) Write(bytes []byte) (int, error) {
    32  
    33  	// assume 200 success if no header has been set
    34  	if rw.StatusCode == 0 {
    35  		rw.WriteHeader(200)
    36  	}
    37  
    38  	// add these bytes to the output string
    39  	rw.Output += string(bytes)
    40  
    41  	// return normal values
    42  	return 0, nil
    43  
    44  }
    45  
    46  // Deprecated: Use [net/http/httptest] instead.
    47  func (rw *TestResponseWriter) WriteHeader(i int) {
    48  	rw.StatusCode = i
    49  }
    50  

View as plain text