TypeCore

Response

The Response type represents an HTTP response with methods for setting headers, status, and body content.

Type Definition

type Response struct {
    conn        net.Conn
    headers     map[string]string
    contentType string
    body        io.ReadCloser
    statusCode  int
    cookies     []*cookies.Cookie
}

Methods

SetHeader()

Sets an HTTP header for the response.

func (r *Response) SetHeader(key, value string)

SetStatus()

Sets the HTTP status code for the response.

func (r *Response) SetStatus(status int)

Write()

Writes a string to the response body.

func (r *Response) Write(body string)

WriteBytes()

Writes bytes to the response body.

func (r *Response) WriteBytes(b []byte)

JSON()

Writes JSON data to the response and sets appropriate content type.

func (r *Response) JSON(data interface)

SetCookie()

Sets a cookie in the response headers.

func (r *Response) SetCookie(cookie *cookies.Cookie)

Send()

Sends the response to the client. Must be called to complete the response.

func (r *Response) Send()