Contains functionality shared between the httpclient and asynchttpserver modules.
Unstable API.
Types
HttpHeaderValues = distinct seq[string]
- Source Edit
HttpMethod = enum HttpHead = "HEAD", ## Asks for the response identical to the one that ## would correspond to a GET request, but without ## the response body. HttpGet = "GET", ## Retrieves the specified resource. HttpPost = "POST", ## Submits data to be processed to the identified ## resource. The data is included in the body of ## the request. HttpPut = "PUT", ## Uploads a representation of the specified ## resource. HttpDelete = "DELETE", ## Deletes the specified resource. HttpTrace = "TRACE", ## Echoes back the received request, so that a ## client ## can see what intermediate servers are adding or ## changing in the request. HttpOptions = "OPTIONS", ## Returns the HTTP methods that the server ## supports for specified address. HttpConnect = "CONNECT", ## Converts the request connection to a transparent ## TCP/IP tunnel, usually used for proxies. HttpPatch = "PATCH" ## Applies partial modifications to a resource.
- the requested HttpMethod Source Edit
HttpVersion = enum HttpVer11, HttpVer10
- Source Edit
Consts
headerLimit = 10000
- Source Edit
Http102 = 102
- https://tools.ietf.org/html/rfc2518.html WebDAV Source Edit
Http103 = 103
- https://tools.ietf.org/html/rfc8297.html Early hints Source Edit
Http207 = 207
- https://tools.ietf.org/html/rfc4918.html WebDAV Source Edit
Http208 = 208
- https://tools.ietf.org/html/rfc5842.html WebDAV, Section 7.1 Source Edit
Http226 = 226
- https://tools.ietf.org/html/rfc3229.html Delta encoding, Section 10.4.1 Source Edit
Http402 = 402
- https://tools.ietf.org/html/rfc7231.html Payment required, Section 6.5.2 Source Edit
Http423 = 423
- https://tools.ietf.org/html/rfc4918.html WebDAV, Section 11.3 Source Edit
Http424 = 424
- https://tools.ietf.org/html/rfc4918.html WebDAV, Section 11.3 Source Edit
Http425 = 425
- https://tools.ietf.org/html/rfc8470.html Early data Source Edit
Http506 = 506
- https://tools.ietf.org/html/rfc2295.html Content negotiation, Section 8.1 Source Edit
Http507 = 507
- https://tools.ietf.org/html/rfc4918.html WebDAV, Section 11.5 Source Edit
Http508 = 508
- https://tools.ietf.org/html/rfc5842.html WebDAV, Section 7.2 Source Edit
Http510 = 510
- https://tools.ietf.org/html/rfc2774.html Extension framework, Section 7 Source Edit
Http511 = 511
- https://tools.ietf.org/html/rfc6585.html Additional status code, Section 6 Source Edit
httpNewLine = "\r\n"
- Source Edit
Procs
func `$`(code: HttpCode): string {....raises: [], tags: [].}
-
Converts the specified HttpCode into a HTTP status.
Example:
doAssert($Http404 == "404 Not Found")
Source Edit func `$`(headers: HttpHeaders): string {.inline, ...raises: [], tags: [].}
- Source Edit
func `==`(protocol: tuple[orig: string, major, minor: int]; ver: HttpVersion): bool {. ...raises: [], tags: [].}
- Source Edit
proc `[]=`(headers: HttpHeaders; key, value: string) {....raises: [], tags: [].}
- Sets the header entries associated with key to the specified value. Replaces any existing values. Source Edit
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. If value is empty, deletes the header entries associated with key. Source Edit
func `[]`(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 Edit func `[]`(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 Edit
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 Edit
proc clear(headers: HttpHeaders) {.inline, ...raises: [], tags: [].}
- Source Edit
func contains(methods: set[HttpMethod]; x: string): bool {....raises: [ValueError], tags: [].}
- Source Edit
func 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 Edit
proc del(headers: HttpHeaders; key: string) {....raises: [], tags: [].}
- Deletes the header entries associated with key Source Edit
func 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 Edit
func is1xx(code: HttpCode): bool {.inline, ...raises: [], tags: [].}
-
Determines whether code is a 1xx HTTP status code.
Example:
doAssert is1xx(HttpCode(103))
Source Edit func is2xx(code: HttpCode): bool {.inline, ...raises: [], tags: [].}
- Determines whether code is a 2xx HTTP status code. Source Edit
func is3xx(code: HttpCode): bool {.inline, ...raises: [], tags: [].}
- Determines whether code is a 3xx HTTP status code. Source Edit
func is4xx(code: HttpCode): bool {.inline, ...raises: [], tags: [].}
- Determines whether code is a 4xx HTTP status code. Source Edit
func is5xx(code: HttpCode): bool {.inline, ...raises: [], tags: [].}
- Determines whether code is a 5xx HTTP status code. Source Edit
func len(headers: HttpHeaders): int {.inline, ...raises: [], tags: [].}
- Source Edit
func newHttpHeaders(keyValuePairs: openArray[tuple[key: string, val: string]]; titleCase = false): HttpHeaders {....raises: [KeyError], tags: [].}
- Returns a new HttpHeaders object from an array. if titleCase is set to true, headers are passed to the server in title case (e.g. "Content-Length") Source Edit
func newHttpHeaders(titleCase = false): HttpHeaders {....raises: [], tags: [].}
- Returns a new HttpHeaders object. if titleCase is set to true, headers are passed to the server in title case (e.g. "Content-Length") Source Edit
Iterators
iterator pairs(headers: HttpHeaders): tuple[key, value: string] {....raises: [], tags: [].}
- Yields each key, value pair. Source Edit
Converters
converter toString(values: HttpHeaderValues): string {....raises: [], tags: [].}
- Source Edit