github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/gnovm/tests/files/extern/net/http/httptest/httptest.gno (about)

     1  package httptest
     2  
     3  import (
     4  	"bytes"
     5  
     6  	"github.com/gnolang/gno/_test/net/http"
     7  )
     8  
     9  type ResponseRecorder struct {
    10  	// Code is the HTTP response code set by WriteHeader.
    11  	//
    12  	// Note that if a Handler never calls WriteHeader or Write,
    13  	// this might end up being 0, rather than the implicit
    14  	// http.StatusOK. To get the implicit value, use the Result
    15  	// method.
    16  	Code int
    17  
    18  	// HeaderMap contains the headers explicitly set by the Handler.
    19  	// It is an internal detail.
    20  	//
    21  	// Deprecated: HeaderMap exists for historical compatibility
    22  	// and should not be used. To access the headers returned by a handler,
    23  	// use the Response.Header map as returned by the Result method.
    24  	HeaderMap http.Header
    25  
    26  	// Body is the buffer to which the Handler's Write calls are sent.
    27  	// If nil, the Writes are silently discarded.
    28  	Body *bytes.Buffer
    29  
    30  	// Flushed is whether the Handler called Flush.
    31  	Flushed bool
    32  	// contains filtered or unexported fields
    33  }
    34  
    35  func NewRecorder() *ResponseRecorder {
    36  	return &ResponseRecorder{
    37  		HeaderMap: make(http.Header),
    38  		Body:      new(bytes.Buffer),
    39  		Code:      200,
    40  	}
    41  }
    42  
    43  // XXX dummy
    44  func (rw *ResponseRecorder) Header() http.Header {
    45  	return rw.HeaderMap
    46  }
    47  
    48  // XXX dummy
    49  func (rw *ResponseRecorder) Write(buf []byte) (int, error) {
    50  	return 0, nil
    51  }
    52  
    53  // XXX dummy
    54  func (rw *ResponseRecorder) WriteHeader(code int) {
    55  }