summaryrefslogtreecommitdiff
path: root/internal/types/response.go
blob: ccd23b67da6125d0cee0292aa1161a79d6fc6a9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package types

import "io"

// Status is the integer status code of a response.
type Status int

// Response contains the data in a response over the small web.
//
// Because protocols have so many differences, this type represents a
// greatest common denominator of request/response-oriented protocols.
type Response struct {
	// Status is the status code of the response.
	Status Status

	// Meta contains status-specific additional information.
	Meta any

	// Body is the response body, if any.
	Body io.Reader

	// Request is the request which generated this response.
	//
	// Available in clients.
	// Not set in servers, and there is no need to set it in server handlers.
	Request *Request
}

func (response *Response) Close() error {
	if cl, ok := response.Body.(io.Closer); ok {
		return cl.Close()
	}
	return nil
}

// ResponseReader is an object which can serialize a response to a protocol.
type ResponseReader interface {
	io.Reader
	io.WriterTo
	io.Closer
}