---
title: ResponseWriter
summary: ResponseWriter is used to respond to client requests.
url: https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/fsthttp/interface.ResponseWriter/
---

**Kind:** Interface  
**Module:** [fsthttp](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/fsthttp/)  
**Package:** compute-sdk-go v1.11.0  
**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/response.go#L270

```go
type ResponseWriter interface {
	Header() Header

	WriteHeader(code int)

	Write(p []byte) (int, error)

	Close() error

	SetManualFramingMode(bool)

	Append(other io.ReadCloser) error
}
```

ResponseWriter is used to respond to client requests.

## Methods

### Append

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/response.go#L329

```go
Append(other io.ReadCloser) error
```

Append a body onto the end of this response. Will fail if passed anything other than a Response's Body field.
This operation is performed in amortized constant time, and so should always be preferred to directly copying a body with io.Copy.

**Parameters**

- `other`: `io.ReadCloser`

**Returns**

`error`

### Close

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/response.go#L313

```go
Close() error
```

Close the response to the client. The ResponseWriter is automatically
closed after the request handler finishes running, so it is not
necessary to call it explicitly, but doing so indicates that the
response can be fully written to the client immediately.

If WriteHeader has not yet been called, Close calls WriteHeader(200)
before closing the response. Once closed, a ResponseWriter is
invalidated, and may no longer be accessed or used in any way.

**Returns**

`error`

### Header

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/response.go#L284

```go
Header() Header
```

Header returns the headers that will be sent by WriteHeader.
The [Header](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/fsthttp/type.Header/) map also is the mechanism with which implementations can set HTTP trailers.
Changing the returned headers after a call to WriteHeader has no effect unless the modified headers are Trailers.

There are two ways to set Trailers. The preferred way is to
predeclare in the headers which trailers you will later
send by setting the "Trailer" header to the names of the
trailer keys which will come later. In this case, those
keys of the Header map are treated as if they were
trailers. See the example. The second way, for trailer
keys not known to the [Handler](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/fsthttp/interface.Handler/) until after the first [ResponseWriter.Write](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/fsthttp/interface.ResponseWriter/#method-Write),
is to prefix the [Header](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/fsthttp/type.Header/) map keys with the [TrailerPrefix]
constant value.

**Returns**

`Header`

### SetManualFramingMode

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/response.go#L325

```go
SetManualFramingMode(bool)
```

SetManualFramingMode controls how the framing headers
(Content-Length/Transfer-Encoding) are set for a response.

If set to true, the response uses the exact framing headers
set in the message.  If set to false, or set to true and
the framing is invalid, the framing headers are based on the
message body, and any framing headers already set in the message are
discarded.

To have an effect on the response, this must be called before any call to Write() or WriteHeader().

**Parameters**

- : `bool`

### Write

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/response.go#L303

```go
Write(p []byte) (int, error)
```

Write the data to the connection as part of an HTTP reply.

If WriteHeader has not yet been called, Write calls WriteHeader(200)
before writing the data. Unlike the ResponseWriter in net/http, Write
will not automatically add Content-Type or Content-Length headers.

**Parameters**

- `p`: `[]byte`

**Returns**

`(int, error)`

### WriteHeader

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/fsthttp/response.go#L296

```go
WriteHeader(code int)
```

WriteHeader initiates the response to the client by sending an HTTP
response preamble with the provided status code, and all of the response
headers collected by Header. If WriteHeader is not called explicitly,
the first call to Write or Close will trigger an implicit call to
WriteHeader with a code of 200. After the first call to WriteHeader,
subsequent calls will print a warning but have no effect.

1xx status codes other than 103 (Early Hints) are not permitted and will
result in an ErrInvalidStatusCode error when calling Write, Close, or
Append, and clients will receive a 500 (Internal Server Error) response.

**Parameters**

- `code`: `int`
