Procs
proc beenModified(ctx: Context; modDate: DateTime = now()): bool {. ...raises: [KeyError, TimeParseError], tags: [TimeEffect].}
- Returns true if modDate is newer than If-Modified-Since in the request. Source Edit
proc closed(ctx: Context): bool {.inline, ...raises: [], tags: [].}
- Returns true if the client has disconnected from the server Source Edit
proc requestRange(ctx: Context): tuple[start, finish: Option[int]] {. ...raises: [KeyError, ValueError], tags: [].}
- Returns start and end positions for a range request. Range requests are still valid if either start or finish don't exist. But if both don't exist then the request is invalid. This currently only supports single range requests Source Edit
proc send(ctx: Context; body: sink string; code: HttpCode; extraHeaders: HttpHeaders = nil) {....raises: [ValueError], tags: [].}
- Responds to a context and overwrites the status code. If responding to a HEAD or OPTIONS request then the body isn't send (But the Content-Length is set) Source Edit
proc send(ctx: Context; body: sink string; extraHeaders: HttpHeaders = nil) {. ...raises: [ValueError], tags: [].}
- Responds to a context with body and does not overwrite the current status code Source Edit
proc send(ctx: Context; code: HttpCode; extraHeaders: HttpHeaders = nil) {. ...raises: [ValueError], tags: [].}
- Responds with just a status code. Ignores the current response body Source Edit
proc send(ctx: Context; prob: ProblemResponse; extraHeaders: HttpHeaders = nil) {. ...raises: [ValueError], tags: [].}
- Sends a problem response back. Automatically sets the response code to the one specifed in prob Source Edit
proc send[T: object | ref object | array | seq | set](ctx: Context; obj: sink T; code = Http200; extraHeaders: HttpHeaders = nil)
- Responds to a context in json format with obj T automatically sets the Content-Type header to "application/json" Source Edit
proc sendCompressed(ctx: Context; body: sink string; compression: CompressedDataFormat; code = Http200; extraHeaders: HttpHeaders = nil) {. ...raises: [ValueError, ZippyError], tags: [].}
- Sends body but compresses it with compression. Currently only dfGzip and dfDeflate are supported. Compresses even if the client doesn't say they support the compression Source Edit
proc sendCompressed(ctx: Context; body: sink string; code = Http200; extraHeaders: HttpHeaders = nil) {. ...raises: [KeyError, ValueError, ZippyError], tags: [].}
- Sends body and trys to compress it. Checks Accept-Encoding header to see what it can compress with. Doesn't compress if nothing in Accept-Encoding is implemented or the header is missing Source Edit
proc sendFile(ctx: Context; filename: string; dir = "."; headers: HttpHeaders = nil; downloadName = ""; charset = "utf-8"; bufsize = 4096; allowRanges = false): owned(Future[void]) {. ...raises: [Exception], tags: [ReadDirEffect, RootEffect, TimeEffect, ReadIOEffect].}
-
Responds to a context with a file.
- allowRanges: Whether to support range requests. Only use
- this if there is little processing before sending the file
proc setContentType(ctx: Context; fileName: string) {....raises: [], tags: [].}
- Sets the content type to be for fileName e.g. "index.html" will set "Content-Type" header to "text/html" Source Edit
proc supportedCompression(ctx: Context): Option[CompressedDataFormat] {. ...raises: [KeyError], tags: [].}
- Returns the compression that is supported by the context. If it doesn't support any compression then none is returned Source Edit