src/prologue/core/response

Search:
Group by:
Source   Edit  

Types

Response = object
  httpVersion*: HttpVersion
  code*: HttpCode
  headers*: ResponseHeaders
  body*: string
Response object. Source   Edit  

Procs

func `$`(response: Response): string {....raises: [], tags: [], forbids: [].}
Gets the string form of Response. Source   Edit  
func abort(code = Http401; body = ""; headers = initResponseHeaders();
           version = HttpVer11): Response {.inline, ...raises: [], tags: [],
    forbids: [].}
Returns the response with Http401 code(do not raise exception). Source   Edit  
func error404(code = Http404; body = "<h1>404 Not Found!</h1>";
              headers = initResponseHeaders(); version = HttpVer11): Response {.
    inline, ...raises: [], tags: [], forbids: [].}
Creates an error 404 response. Source   Edit  
func htmlResponse(text: string; code = Http200; headers = initResponseHeaders();
                  version = HttpVer11): Response {.inline, ...raises: [], tags: [],
    forbids: [].}
Content-Type: text/html; charset=UTF-8. Source   Edit  
func initResponse(httpVersion: HttpVersion; code: HttpCode;
                  headers: openArray[(string, string)]; body = ""): Response {.
    inline, ...raises: [KeyError], tags: [], forbids: [].}
Initializes a response. Source   Edit  
func initResponse(httpVersion: HttpVersion; code: HttpCode; headers = [
    ("Content-Type", "text/html; charset=UTF-8")].initResponseHeaders; body = ""): Response {.
    inline, ...raises: [], tags: [], forbids: [].}
Initializes a response. Source   Edit  
func jsonResponse(text: JsonNode; code = Http200;
                  headers = initResponseHeaders(); version = HttpVer11): Response {.
    inline, ...raises: [], tags: [], forbids: [].}
Content-Type: application/json. Source   Edit  
func plainTextResponse(text: string; code = Http200;
                       headers = initResponseHeaders(); version = HttpVer11): Response {.
    inline, ...raises: [], tags: [], forbids: [].}
Content-Type: text/plain. Source   Edit  
func redirect(url: string; code = Http301; body = ""; delay = 0;
              headers = initResponseHeaders(); version = HttpVer11): Response {.
    inline, ...raises: [KeyError], tags: [], forbids: [].}
Redirects to new url. Source   Edit  

Macros

macro resp(body: string; code = Http200; version = HttpVer11)
Handy to make a response of ctx. Source   Edit  
macro resp(response: Response)
Handy to make a response of ctx. Source   Edit  
macro respDefault(code: HttpCode)
Uses default error handler registered in the error handler table if existing. Source   Edit  

Templates

template addHeader(response: var Response; key, value: string)
Adds header values to the existing HttpHeaders. Source   Edit  
template deleteCookie(response: var Response; key: string; value = "";
                      path = ""; domain = "")
Deletes the cookie of the response. Source   Edit  
template getHeader(response: Response; key: string): seq[string]
Retrieves value of response.headers[key]. Source   Edit  
template getHeaderOrDefault(response: Response; key: string; default = @[""]): seq[
    string]
Retrieves value of response.headers[key]. Otherwise default will be returned. Source   Edit  
template hasHeader(response: Response; key: string): bool
Returns true if key is in the response. Source   Edit  
template setCookie(response: var Response; cookie: Cookie)
Sets the cookie of response. Source   Edit  
template setCookie(response: var Response; key, value: string; expires = "";
                   maxAge: Option[int] = none(int); domain = ""; path = "";
                   secure = false; httpOnly = false; sameSite = Lax)
Sets the cookie of response. Source   Edit  
template setCookie(response: var Response; key, value: string;
                   expires: DateTime | Time; maxAge: Option[int] = none(int);
                   domain = ""; path = ""; secure = false; httpOnly = false;
                   sameSite = Lax)
Sets the cookie of response. Source   Edit  
template setHeader(response: var Response; key, value: string)
Sets the header values of the response. Source   Edit  
template setHeader(response: var Response; key: string; value: seq[string])
Sets the header values of the response. Source   Edit