blob: abc28d9f2c46a35c2438914bf6faa375ac6a37a0 (
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
|
package main
import "fmt"
type Response struct {
status Status
headers map[string]string
body []byte
}
func (r *Response) StatusLine() []byte {
return []byte(fmt.Sprintf("HTTP/1.1 %d %s\r\n", r.status.Code(), r.status.Text()))
}
func (r *Response) Headers() []byte {
buf := make([]byte, 0)
for key, value := range r.headers {
buf = append(buf, fmt.Sprintf("%s: %s\r\n", key, value)...)
}
return append(buf, "\r\n"...)
}
func (r *Response) Body() []byte {
return r.body
}
func NewResponse(code Status, headers map[string]string, body []byte) *Response {
return &Response{code, headers, body}
}
|