Contains functionality shared between the httpclient and asynchttpserver modules.
Types
HttpHeaders = ref object table*: TableRef[string, seq[string]]
- Source
HttpHeaderValues = distinct seq[string]
- Source
HttpCode = enum Http100 = "100 Continue", Http101 = "101 Switching Protocols", Http200 = "200 OK", Http201 = "201 Created", Http202 = "202 Accepted", Http204 = "204 No Content", Http205 = "205 Reset Content", Http206 = "206 Partial Content", Http300 = "300 Multiple Choices", Http301 = "301 Moved Permanently", Http302 = "302 Found", Http303 = "303 See Other", Http304 = "304 Not Modified", Http305 = "305 Use Proxy", Http307 = "307 Temporary Redirect", Http400 = "400 Bad Request", Http401 = "401 Unauthorized", Http403 = "403 Forbidden", Http404 = "404 Not Found", Http405 = "405 Method Not Allowed", Http406 = "406 Not Acceptable", Http407 = "407 Proxy Authentication Required", Http408 = "408 Request Timeout", Http409 = "409 Conflict", Http410 = "410 Gone", Http411 = "411 Length Required", Http412 = "412 Precondition Failed", Http413 = "413 Request Entity Too Large", Http414 = "414 Request-URI Too Long", Http415 = "415 Unsupported Media Type", Http416 = "416 Requested Range Not Satisfiable", Http417 = "417 Expectation Failed", Http418 = "418 I\'m a teapot", Http500 = "500 Internal Server Error", Http501 = "501 Not Implemented", Http502 = "502 Bad Gateway", Http503 = "503 Service Unavailable", Http504 = "504 Gateway Timeout", Http505 = "505 HTTP Version Not Supported"
- Source
HttpVersion = enum HttpVer11, HttpVer10
- Source
Procs
proc newHttpHeaders(): HttpHeaders {.raises: [], tags: [].}
- Source
proc newHttpHeaders(keyValuePairs: openArray[tuple[key: string, val: string]]): HttpHeaders {. raises: [], tags: [].}
- Source
proc clear(headers: HttpHeaders) {.raises: [], tags: [].}
- Source
proc `[]`(headers: HttpHeaders; key: string): HttpHeaderValues {.raises: [KeyError], tags: [].}
-
Returns the values associated with the given key. If the returned values are passed to a procedure expecting a string, the first value is automatically picked. If there are no values associated with the key, an exception is raised.
To access multiple values of a key, use the overloaded [] below or to get all of them access the table field directly.
Source proc `[]`(headers: HttpHeaders; key: string; i: int): string {.raises: [KeyError], tags: [].}
- Returns the i'th value associated with the given key. If there are no values associated with the key or the i'th value doesn't exist, an exception is raised. Source
proc `[]=`(headers: HttpHeaders; key, value: string) {.raises: [], tags: [].}
- Sets the header entries associated with key to the specified value. Replaces any existing values. Source
proc `[]=`(headers: HttpHeaders; key: string; value: seq[string]) {.raises: [], tags: [].}
- Sets the header entries associated with key to the specified list of values. Replaces any existing values. Source
proc add(headers: HttpHeaders; key, value: string) {.raises: [KeyError], tags: [].}
- Adds the specified value to the specified key. Appends to any existing values associated with the key. Source
proc contains(values: HttpHeaderValues; value: string): bool {.raises: [], tags: [].}
- Determines if value is one of the values inside values. Comparison is performed without case sensitivity. Source
proc hasKey(headers: HttpHeaders; key: string): bool {.raises: [], tags: [].}
- Source
proc getOrDefault(headers: HttpHeaders; key: string; default = @ [""].HttpHeaderValues): HttpHeaderValues {. raises: [KeyError], tags: [].}
- Returns the values associated with the given key. If there are no values associated with the key, then default is returned. Source
proc len(headers: HttpHeaders): int {.raises: [], tags: [].}
- Source
proc parseHeader(line: string): tuple[key: string, value: seq[string]] {.raises: [], tags: [].}
-
Parses a single raw header HTTP line into key value pairs.
Used by asynchttpserver and httpclient internally and should not be used by you.
Source proc `==`(protocol: tuple[orig: string, major, minor: int]; ver: HttpVersion): bool {. raises: [], tags: [].}
- Source
Iterators
iterator pairs(headers: HttpHeaders): tuple[key, value: string] {.raises: [], tags: [].}
- Yields each key, value pair. Source
Converters
converter toString(values: HttpHeaderValues): string {.raises: [], tags: [].}
- Source