1
// Copyright 2011 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.
5
// Package httptest provides utilities for HTTP testing.
10
"launchpad.net/ubuntu-push/http13client"
13
// ResponseRecorder is an implementation of http.ResponseWriter that
14
// records its mutations for later inspection in tests.
15
type ResponseRecorder struct {
16
Code int // the HTTP response code from WriteHeader
17
HeaderMap http.Header // the HTTP response headers
18
Body *bytes.Buffer // if non-nil, the bytes.Buffer to append written data to
24
// NewRecorder returns an initialized ResponseRecorder.
25
func NewRecorder() *ResponseRecorder {
26
return &ResponseRecorder{
27
HeaderMap: make(http.Header),
28
Body: new(bytes.Buffer),
33
// DefaultRemoteAddr is the default remote address to return in RemoteAddr if
34
// an explicit DefaultRemoteAddr isn't set on ResponseRecorder.
35
const DefaultRemoteAddr = "1.2.3.4"
37
// Header returns the response headers.
38
func (rw *ResponseRecorder) Header() http.Header {
47
// Write always succeeds and writes to rw.Body, if not nil.
48
func (rw *ResponseRecorder) Write(buf []byte) (int, error) {
58
// WriteHeader sets rw.Code.
59
func (rw *ResponseRecorder) WriteHeader(code int) {
66
// Flush sets rw.Flushed to true.
67
func (rw *ResponseRecorder) Flush() {