mirror of
https://github.com/logos-storage/nim-chronos.git
synced 2026-01-25 00:33:10 +00:00
enable --styleCheck:usages
This commit is contained in:
parent
7dc58d42b6
commit
0fc82049ac
@ -13,7 +13,7 @@ requires "nim > 1.2.0",
|
||||
"httputils",
|
||||
"https://github.com/status-im/nim-unittest2.git#head"
|
||||
|
||||
var commandStart = "nim c -r --hints:off --verbosity:0 --skipParentCfg:on --warning[ObservableStores]:off"
|
||||
var commandStart = "nim c -r --hints:off --verbosity:0 --skipParentCfg:on --warning[ObservableStores]:off --styleCheck:usages --styleCheck:error"
|
||||
|
||||
task test, "Run all tests":
|
||||
var commands = @[
|
||||
|
||||
@ -710,7 +710,7 @@ proc closeWait*(response: HttpClientResponseRef) {.async.} =
|
||||
response.state = HttpReqRespState.Closed
|
||||
untrackHttpClientResponse(response)
|
||||
|
||||
proc prepareResponse(request: HttpClientRequestRef, data: openarray[byte]
|
||||
proc prepareResponse(request: HttpClientRequestRef, data: openArray[byte]
|
||||
): HttpResult[HttpClientResponseRef] {.raises: [Defect] .} =
|
||||
## Process response headers.
|
||||
let resp = parseResponse(data, false)
|
||||
@ -813,8 +813,8 @@ proc new*(t: typedesc[HttpClientRequestRef], session: HttpSessionRef,
|
||||
ha: HttpAddress, meth: HttpMethod = MethodGet,
|
||||
version: HttpVersion = HttpVersion11,
|
||||
flags: set[HttpClientRequestFlag] = {},
|
||||
headers: openarray[HttpHeaderTuple] = [],
|
||||
body: openarray[byte] = []): HttpClientRequestRef {.
|
||||
headers: openArray[HttpHeaderTuple] = [],
|
||||
body: openArray[byte] = []): HttpClientRequestRef {.
|
||||
raises: [Defect].} =
|
||||
let res = HttpClientRequestRef(
|
||||
state: HttpReqRespState.Ready, session: session, meth: meth,
|
||||
@ -828,8 +828,8 @@ proc new*(t: typedesc[HttpClientRequestRef], session: HttpSessionRef,
|
||||
url: string, meth: HttpMethod = MethodGet,
|
||||
version: HttpVersion = HttpVersion11,
|
||||
flags: set[HttpClientRequestFlag] = {},
|
||||
headers: openarray[HttpHeaderTuple] = [],
|
||||
body: openarray[byte] = []): HttpResult[HttpClientRequestRef] {.
|
||||
headers: openArray[HttpHeaderTuple] = [],
|
||||
body: openArray[byte] = []): HttpResult[HttpClientRequestRef] {.
|
||||
raises: [Defect].} =
|
||||
let address = ? session.getAddress(parseUri(url))
|
||||
let res = HttpClientRequestRef(
|
||||
@ -843,22 +843,22 @@ proc new*(t: typedesc[HttpClientRequestRef], session: HttpSessionRef,
|
||||
proc get*(t: typedesc[HttpClientRequestRef], session: HttpSessionRef,
|
||||
url: string, version: HttpVersion = HttpVersion11,
|
||||
flags: set[HttpClientRequestFlag] = {},
|
||||
headers: openarray[HttpHeaderTuple] = []
|
||||
headers: openArray[HttpHeaderTuple] = []
|
||||
): HttpResult[HttpClientRequestRef] {.raises: [Defect].} =
|
||||
HttpClientRequestRef.new(session, url, MethodGet, version, flags, headers)
|
||||
|
||||
proc get*(t: typedesc[HttpClientRequestRef], session: HttpSessionRef,
|
||||
ha: HttpAddress, version: HttpVersion = HttpVersion11,
|
||||
flags: set[HttpClientRequestFlag] = {},
|
||||
headers: openarray[HttpHeaderTuple] = []
|
||||
headers: openArray[HttpHeaderTuple] = []
|
||||
): HttpClientRequestRef {.raises: [Defect].} =
|
||||
HttpClientRequestRef.new(session, ha, MethodGet, version, flags, headers)
|
||||
|
||||
proc post*(t: typedesc[HttpClientRequestRef], session: HttpSessionRef,
|
||||
url: string, version: HttpVersion = HttpVersion11,
|
||||
flags: set[HttpClientRequestFlag] = {},
|
||||
headers: openarray[HttpHeaderTuple] = [],
|
||||
body: openarray[byte] = []
|
||||
headers: openArray[HttpHeaderTuple] = [],
|
||||
body: openArray[byte] = []
|
||||
): HttpResult[HttpClientRequestRef] {.raises: [Defect].} =
|
||||
HttpClientRequestRef.new(session, url, MethodPost, version, flags, headers,
|
||||
body)
|
||||
@ -866,8 +866,8 @@ proc post*(t: typedesc[HttpClientRequestRef], session: HttpSessionRef,
|
||||
proc post*(t: typedesc[HttpClientRequestRef], session: HttpSessionRef,
|
||||
url: string, version: HttpVersion = HttpVersion11,
|
||||
flags: set[HttpClientRequestFlag] = {},
|
||||
headers: openarray[HttpHeaderTuple] = [],
|
||||
body: openarray[char] = []): HttpResult[HttpClientRequestRef] {.
|
||||
headers: openArray[HttpHeaderTuple] = [],
|
||||
body: openArray[char] = []): HttpResult[HttpClientRequestRef] {.
|
||||
raises: [Defect].} =
|
||||
HttpClientRequestRef.new(session, url, MethodPost, version, flags, headers,
|
||||
body.toOpenArrayByte(0, len(body) - 1))
|
||||
@ -875,8 +875,8 @@ proc post*(t: typedesc[HttpClientRequestRef], session: HttpSessionRef,
|
||||
proc post*(t: typedesc[HttpClientRequestRef], session: HttpSessionRef,
|
||||
ha: HttpAddress, version: HttpVersion = HttpVersion11,
|
||||
flags: set[HttpClientRequestFlag] = {},
|
||||
headers: openarray[HttpHeaderTuple] = [],
|
||||
body: openarray[byte] = []): HttpClientRequestRef {.
|
||||
headers: openArray[HttpHeaderTuple] = [],
|
||||
body: openArray[byte] = []): HttpClientRequestRef {.
|
||||
raises: [Defect].} =
|
||||
HttpClientRequestRef.new(session, ha, MethodPost, version, flags, headers,
|
||||
body)
|
||||
@ -884,8 +884,8 @@ proc post*(t: typedesc[HttpClientRequestRef], session: HttpSessionRef,
|
||||
proc post*(t: typedesc[HttpClientRequestRef], session: HttpSessionRef,
|
||||
ha: HttpAddress, version: HttpVersion = HttpVersion11,
|
||||
flags: set[HttpClientRequestFlag] = {},
|
||||
headers: openarray[HttpHeaderTuple] = [],
|
||||
body: openarray[char] = []): HttpClientRequestRef {.
|
||||
headers: openArray[HttpHeaderTuple] = [],
|
||||
body: openArray[char] = []): HttpClientRequestRef {.
|
||||
raises: [Defect].} =
|
||||
HttpClientRequestRef.new(session, ha, MethodPost, version, flags, headers,
|
||||
body.toOpenArrayByte(0, len(body) - 1))
|
||||
|
||||
@ -127,7 +127,7 @@ iterator queryParams*(query: string,
|
||||
else:
|
||||
yield (decodeUrl(k), decodeUrl(v))
|
||||
|
||||
func getTransferEncoding*(ch: openarray[string]): HttpResult[
|
||||
func getTransferEncoding*(ch: openArray[string]): HttpResult[
|
||||
set[TransferEncodingFlags]] {.
|
||||
raises: [Defect].} =
|
||||
## Parse value of multiple HTTP headers ``Transfer-Encoding`` and return
|
||||
@ -158,7 +158,7 @@ func getTransferEncoding*(ch: openarray[string]): HttpResult[
|
||||
return err("Incorrect Transfer-Encoding value")
|
||||
ok(res)
|
||||
|
||||
func getContentEncoding*(ch: openarray[string]): HttpResult[
|
||||
func getContentEncoding*(ch: openArray[string]): HttpResult[
|
||||
set[ContentEncodingFlags]] {.
|
||||
raises: [Defect].} =
|
||||
## Parse value of multiple HTTP headers ``Content-Encoding`` and return
|
||||
@ -189,7 +189,7 @@ func getContentEncoding*(ch: openarray[string]): HttpResult[
|
||||
return err("Incorrect Content-Encoding value")
|
||||
ok(res)
|
||||
|
||||
func getContentType*(ch: openarray[string]): HttpResult[string] {.
|
||||
func getContentType*(ch: openArray[string]): HttpResult[string] {.
|
||||
raises: [Defect].} =
|
||||
## Check and prepare value of ``Content-Type`` header.
|
||||
if len(ch) == 0:
|
||||
@ -200,7 +200,7 @@ func getContentType*(ch: openarray[string]): HttpResult[string] {.
|
||||
let mparts = ch[0].split(";")
|
||||
ok(strip(mparts[0]).toLowerAscii())
|
||||
|
||||
proc bytesToString*(src: openarray[byte], dst: var openarray[char]) =
|
||||
proc bytesToString*(src: openArray[byte], dst: var openArray[char]) =
|
||||
## Convert array of bytes to array of characters.
|
||||
##
|
||||
## Note, that this procedure assume that `sizeof(byte) == sizeof(char) == 1`.
|
||||
@ -209,7 +209,7 @@ proc bytesToString*(src: openarray[byte], dst: var openarray[char]) =
|
||||
if len(src) > 0:
|
||||
copyMem(addr dst[0], unsafeAddr src[0], len(src))
|
||||
|
||||
proc stringToBytes*(src: openarray[char], dst: var openarray[byte]) =
|
||||
proc stringToBytes*(src: openArray[char], dst: var openArray[byte]) =
|
||||
## Convert array of characters to array of bytes.
|
||||
##
|
||||
## Note, that this procedure assume that `sizeof(byte) == sizeof(char) == 1`.
|
||||
@ -218,7 +218,7 @@ proc stringToBytes*(src: openarray[char], dst: var openarray[byte]) =
|
||||
if len(src) > 0:
|
||||
copyMem(addr dst[0], unsafeAddr src[0], len(src))
|
||||
|
||||
func bytesToString*(src: openarray[byte]): string =
|
||||
func bytesToString*(src: openArray[byte]): string =
|
||||
## Convert array of bytes to a string.
|
||||
##
|
||||
## Note, that this procedure assume that `sizeof(byte) == sizeof(char) == 1`.
|
||||
@ -231,7 +231,7 @@ func bytesToString*(src: openarray[byte]): string =
|
||||
else:
|
||||
default
|
||||
|
||||
func stringToBytes*(src: openarray[char]): seq[byte] =
|
||||
func stringToBytes*(src: openArray[char]): seq[byte] =
|
||||
## Convert string to sequence of bytes.
|
||||
##
|
||||
## Note, that this procedure assume that `sizeof(byte) == sizeof(char) == 1`.
|
||||
@ -244,7 +244,7 @@ func stringToBytes*(src: openarray[char]): seq[byte] =
|
||||
else:
|
||||
default
|
||||
|
||||
proc dumpHex*(pbytes: openarray[byte], groupBy = 1, ascii = true): string =
|
||||
proc dumpHex*(pbytes: openArray[byte], groupBy = 1, ascii = true): string =
|
||||
## Get hexadecimal dump of memory for array ``pbytes``.
|
||||
var res = ""
|
||||
var offset = 0
|
||||
|
||||
@ -34,7 +34,7 @@ type
|
||||
ServerRunning, ServerStopped, ServerClosed
|
||||
|
||||
HttpProcessError* = object
|
||||
error*: HTTPServerError
|
||||
error*: HttpServerError
|
||||
code*: HttpCode
|
||||
exc*: ref CatchableError
|
||||
remote*: TransportAddress
|
||||
@ -130,7 +130,7 @@ type
|
||||
|
||||
ByteChar* = string | seq[byte]
|
||||
|
||||
proc init(htype: typedesc[HttpProcessError], error: HTTPServerError,
|
||||
proc init(htype: typedesc[HttpProcessError], error: HttpServerError,
|
||||
exc: ref CatchableError, remote: TransportAddress,
|
||||
code: HttpCode): HttpProcessError {.raises: [Defect].} =
|
||||
HttpProcessError(error: error, exc: exc, remote: remote, code: code)
|
||||
@ -214,7 +214,7 @@ proc new*(htype: typedesc[HttpServerRef],
|
||||
var res = HttpServerRef()
|
||||
res[].init(address, serverInstance, processCallback, createConnection,
|
||||
serverUri, serverFlags, socketFlags, serverIdent, maxConnections,
|
||||
bufferSize, backLogSize, httpHeadersTimeout, maxHeadersSize,
|
||||
bufferSize, backlogSize, httpHeadersTimeout, maxHeadersSize,
|
||||
maxRequestBodySize)
|
||||
ok(res)
|
||||
|
||||
@ -683,7 +683,7 @@ proc processLoop(server: HttpServerRef, transp: StreamTransport,
|
||||
await transp.closeWait()
|
||||
return
|
||||
except HttpCriticalError as exc:
|
||||
let error = HttpProcessError.init(HTTPServerError.CriticalError, exc,
|
||||
let error = HttpProcessError.init(HttpServerError.CriticalError, exc,
|
||||
transp.remoteAddress(), exc.code)
|
||||
connArg = RequestFence.err(error)
|
||||
runLoop = false
|
||||
@ -715,15 +715,15 @@ proc processLoop(server: HttpServerRef, transp: StreamTransport,
|
||||
except CancelledError:
|
||||
breakLoop = true
|
||||
except AsyncTimeoutError as exc:
|
||||
let error = HttpProcessError.init(HTTPServerError.TimeoutError, exc,
|
||||
let error = HttpProcessError.init(HttpServerError.TimeoutError, exc,
|
||||
transp.remoteAddress(), Http408)
|
||||
arg = RequestFence.err(error)
|
||||
except HttpRecoverableError as exc:
|
||||
let error = HttpProcessError.init(HTTPServerError.RecoverableError, exc,
|
||||
let error = HttpProcessError.init(HttpServerError.RecoverableError, exc,
|
||||
transp.remoteAddress(), exc.code)
|
||||
arg = RequestFence.err(error)
|
||||
except HttpCriticalError as exc:
|
||||
let error = HttpProcessError.init(HTTPServerError.CriticalError, exc,
|
||||
let error = HttpProcessError.init(HttpServerError.CriticalError, exc,
|
||||
transp.remoteAddress(), exc.code)
|
||||
arg = RequestFence.err(error)
|
||||
except HttpDisconnectError as exc:
|
||||
@ -734,7 +734,7 @@ proc processLoop(server: HttpServerRef, transp: StreamTransport,
|
||||
else:
|
||||
breakLoop = true
|
||||
except CatchableError as exc:
|
||||
let error = HttpProcessError.init(HTTPServerError.CatchableError, exc,
|
||||
let error = HttpProcessError.init(HttpServerError.CatchableError, exc,
|
||||
transp.remoteAddress(), Http500)
|
||||
arg = RequestFence.err(error)
|
||||
|
||||
@ -762,13 +762,13 @@ proc processLoop(server: HttpServerRef, transp: StreamTransport,
|
||||
let code = arg.error().code
|
||||
try:
|
||||
case arg.error().error
|
||||
of HTTPServerError.TimeoutError:
|
||||
of HttpServerError.TimeoutError:
|
||||
discard await conn.sendErrorResponse(HttpVersion11, code, false)
|
||||
of HTTPServerError.RecoverableError:
|
||||
of HttpServerError.RecoverableError:
|
||||
discard await conn.sendErrorResponse(HttpVersion11, code, false)
|
||||
of HTTPServerError.CriticalError:
|
||||
of HttpServerError.CriticalError:
|
||||
discard await conn.sendErrorResponse(HttpVersion11, code, false)
|
||||
of HTTPServerError.CatchableError:
|
||||
of HttpServerError.CatchableError:
|
||||
discard await conn.sendErrorResponse(HttpVersion11, code, false)
|
||||
of HttpServerError.DisconnectError:
|
||||
discard
|
||||
@ -1463,7 +1463,7 @@ proc requestInfo*(req: HttpRequestRef, contentType = "text/text"): string {.
|
||||
res.add(kv("server.maxHeadersSize", $req.connection.server.maxHeadersSize))
|
||||
res.add(kv("server.maxRequestBodySize",
|
||||
$req.connection.server.maxRequestBodySize))
|
||||
res.add(kv("server.backlog", $req.connection.server.backLogSize))
|
||||
res.add(kv("server.backlog", $req.connection.server.backlogSize))
|
||||
res.add(kv("server.headersTimeout", $req.connection.server.headersTimeout))
|
||||
res.add(kv("server.baseUri", $req.connection.server.baseUri))
|
||||
res.add(kv("server.flags", $req.connection.server.flags))
|
||||
|
||||
@ -44,7 +44,7 @@ proc contains*(ht: HttpTables, key: string): bool =
|
||||
ht.table.contains(key.toLowerAscii())
|
||||
|
||||
proc getList*(ht: HttpTables, key: string,
|
||||
default: openarray[string] = []): seq[string] =
|
||||
default: openArray[string] = []): seq[string] =
|
||||
## Returns sequence of headers with key ``key``.
|
||||
var defseq = @default
|
||||
ht.table.getOrDefault(key.toLowerAscii(), defseq)
|
||||
|
||||
@ -71,7 +71,7 @@ type
|
||||
|
||||
BChar* = byte | char
|
||||
|
||||
proc startsWith(s, prefix: openarray[byte]): bool {.
|
||||
proc startsWith(s, prefix: openArray[byte]): bool {.
|
||||
raises: [Defect].} =
|
||||
# This procedure is copy of strutils.startsWith() procedure, however,
|
||||
# it is intended to work with arrays of bytes, but not with strings.
|
||||
@ -81,7 +81,7 @@ proc startsWith(s, prefix: openarray[byte]): bool {.
|
||||
if i >= len(s) or s[i] != prefix[i]: return false
|
||||
inc(i)
|
||||
|
||||
proc parseUntil(s, until: openarray[byte]): int {.
|
||||
proc parseUntil(s, until: openArray[byte]): int {.
|
||||
raises: [Defect].} =
|
||||
# This procedure is copy of parseutils.parseUntil() procedure, however,
|
||||
# it is intended to work with arrays of bytes, but not with strings.
|
||||
@ -119,8 +119,8 @@ func setPartNames(part: var MultiPart): HttpResult[void] {.
|
||||
ok()
|
||||
|
||||
proc init*[A: BChar, B: BChar](mpt: typedesc[MultiPartReader],
|
||||
buffer: openarray[A],
|
||||
boundary: openarray[B]): MultiPartReader {.
|
||||
buffer: openArray[A],
|
||||
boundary: openArray[B]): MultiPartReader {.
|
||||
raises: [Defect].} =
|
||||
## Create new MultiPartReader instance with `buffer` interface.
|
||||
##
|
||||
@ -144,7 +144,7 @@ proc init*[A: BChar, B: BChar](mpt: typedesc[MultiPartReader],
|
||||
|
||||
proc new*[B: BChar](mpt: typedesc[MultiPartReaderRef],
|
||||
stream: HttpBodyReader,
|
||||
boundary: openarray[B],
|
||||
boundary: openArray[B],
|
||||
partHeadersMaxSize = 4096): MultiPartReaderRef {.
|
||||
raises: [Defect].} =
|
||||
## Create new MultiPartReader instance with `stream` interface.
|
||||
@ -427,7 +427,7 @@ func isEmpty*(mp: MultiPart): bool {.
|
||||
## Returns ``true`` is multipart ``mp`` is not initialized/filled yet.
|
||||
mp.counter == 0
|
||||
|
||||
func validateBoundary[B: BChar](boundary: openarray[B]): HttpResult[void] =
|
||||
func validateBoundary[B: BChar](boundary: openArray[B]): HttpResult[void] =
|
||||
if len(boundary) == 0:
|
||||
err("Content-Type boundary must be at least 1 character size")
|
||||
elif len(boundary) > 70:
|
||||
@ -439,7 +439,7 @@ func validateBoundary[B: BChar](boundary: openarray[B]): HttpResult[void] =
|
||||
return err("Content-Type boundary alphabet incorrect")
|
||||
ok()
|
||||
|
||||
func getMultipartBoundary*(ch: openarray[string]): HttpResult[string] {.
|
||||
func getMultipartBoundary*(ch: openArray[string]): HttpResult[string] {.
|
||||
raises: [Defect].} =
|
||||
## Returns ``multipart/form-data`` boundary value from ``Content-Type``
|
||||
## header.
|
||||
@ -510,7 +510,7 @@ proc quoteCheck(name: string): HttpResult[string] =
|
||||
ok(name)
|
||||
|
||||
proc init*[B: BChar](mpt: typedesc[MultiPartWriter],
|
||||
boundary: openarray[B]): MultiPartWriter {.
|
||||
boundary: openArray[B]): MultiPartWriter {.
|
||||
raises: [Defect].} =
|
||||
## Create new MultiPartWriter instance with `buffer` interface.
|
||||
##
|
||||
@ -540,7 +540,7 @@ proc init*[B: BChar](mpt: typedesc[MultiPartWriter],
|
||||
|
||||
proc new*[B: BChar](mpt: typedesc[MultiPartWriterRef],
|
||||
stream: HttpBodyWriter,
|
||||
boundary: openarray[B]): MultiPartWriterRef {.
|
||||
boundary: openArray[B]): MultiPartWriterRef {.
|
||||
raises: [Defect].} =
|
||||
doAssert(validateBoundary(boundary).isOk())
|
||||
doAssert(not(isNil(stream)))
|
||||
@ -566,7 +566,7 @@ proc new*[B: BChar](mpt: typedesc[MultiPartWriterRef],
|
||||
state: MultiPartWriterState.MessagePreparing
|
||||
)
|
||||
|
||||
proc prepareHeaders(partMark: openarray[byte], name: string, filename: string,
|
||||
proc prepareHeaders(partMark: openArray[byte], name: string, filename: string,
|
||||
headers: HttpTable): string =
|
||||
const ContentDisposition = "Content-Disposition"
|
||||
let qname =
|
||||
@ -707,13 +707,13 @@ proc write*(mpw: var MultiPartWriter, pbytes: pointer, nbytes: int) =
|
||||
mpw.buffer.setLen(index + nbytes)
|
||||
copyMem(addr mpw.buffer[0], pbytes, nbytes)
|
||||
|
||||
proc write*(mpw: var MultiPartWriter, data: openarray[byte]) =
|
||||
proc write*(mpw: var MultiPartWriter, data: openArray[byte]) =
|
||||
## Write part's data ``data`` to the output stream.
|
||||
doAssert(mpw.kind == MultiPartSource.Buffer)
|
||||
doAssert(mpw.state == MultiPartWriterState.PartStarted)
|
||||
mpw.buffer.add(data)
|
||||
|
||||
proc write*(mpw: var MultiPartWriter, data: openarray[char]) =
|
||||
proc write*(mpw: var MultiPartWriter, data: openArray[char]) =
|
||||
## Write part's data ``data`` to the output stream.
|
||||
doAssert(mpw.kind == MultiPartSource.Buffer)
|
||||
doAssert(mpw.state == MultiPartWriterState.PartStarted)
|
||||
|
||||
@ -97,7 +97,7 @@ proc new*(htype: typedesc[SecureHttpServerRef],
|
||||
HttpServer(res[]).init(address, serverInstance, processCallback,
|
||||
createSecConnection, serverUri, serverFlags,
|
||||
socketFlags, serverIdent, maxConnections,
|
||||
bufferSize, backLogSize, httpHeadersTimeout,
|
||||
bufferSize, backlogSize, httpHeadersTimeout,
|
||||
maxHeadersSize, maxRequestBodySize)
|
||||
res.tlsCertificate = tlsCertificate
|
||||
res.tlsPrivateKey = tlsPrivateKey
|
||||
|
||||
@ -209,7 +209,7 @@ proc close*(ev: SelectEvent) =
|
||||
raiseIOSelectorsError(osLastError())
|
||||
|
||||
proc selectInto*[T](s: Selector[T], timeout: int,
|
||||
results: var openarray[ReadyKey]): int =
|
||||
results: var openArray[ReadyKey]): int =
|
||||
var maxres = MAX_POLL_EVENTS
|
||||
if maxres > len(results):
|
||||
maxres = len(results)
|
||||
|
||||
@ -304,7 +304,7 @@ proc unregister*[T](s: Selector[T], ev: SelectEvent) =
|
||||
s.delKey(fd)
|
||||
|
||||
proc selectInto*[T](s: Selector[T], timeout: int,
|
||||
results: var openarray[ReadyKey]): int =
|
||||
results: var openArray[ReadyKey]): int =
|
||||
var tv = Timeval()
|
||||
var ptv = addr tv
|
||||
var rset, wset, eset: FdSet
|
||||
|
||||
@ -163,7 +163,7 @@ when defined(nimdoc):
|
||||
## Unregisters file/socket descriptor ``fd`` from selector ``s``.
|
||||
|
||||
proc selectInto*[T](s: Selector[T], timeout: int,
|
||||
results: var openarray[ReadyKey]): int =
|
||||
results: var openArray[ReadyKey]): int =
|
||||
## Waits for events registered in selector ``s``.
|
||||
##
|
||||
## The ``timeout`` argument specifies the maximum number of milliseconds
|
||||
|
||||
@ -750,7 +750,7 @@ proc readMessage*(rstream: AsyncStreamReader, pred: ReadMessagePredicate) {.
|
||||
##
|
||||
## ``predicate`` callback must copy all the data from ``data`` array and
|
||||
## return number of bytes it is going to consume.
|
||||
## ``predicate`` callback will receive (zero-length) openarray, if stream
|
||||
## ``predicate`` callback will receive (zero-length) openArray, if stream
|
||||
## is at EOF.
|
||||
doAssert(not(isNil(pred)), "`predicate` callback should not be `nil`")
|
||||
checkStreamClosed(rstream)
|
||||
|
||||
@ -64,7 +64,7 @@ proc readUntilBoundary(rstream: AsyncStreamReader, pbytes: pointer,
|
||||
var state = 0
|
||||
var pbuffer = cast[ptr UncheckedArray[byte]](pbytes)
|
||||
|
||||
proc predicate(data: openarray[byte]): tuple[consumed: int, done: bool] =
|
||||
proc predicate(data: openArray[byte]): tuple[consumed: int, done: bool] =
|
||||
if len(data) == 0:
|
||||
(0, true)
|
||||
else:
|
||||
@ -88,7 +88,7 @@ proc readUntilBoundary(rstream: AsyncStreamReader, pbytes: pointer,
|
||||
await rstream.readMessage(predicate)
|
||||
return k
|
||||
|
||||
func endsWith(s, suffix: openarray[byte]): bool =
|
||||
func endsWith(s, suffix: openArray[byte]): bool =
|
||||
var i = 0
|
||||
var j = len(s) - len(suffix)
|
||||
while i + j >= 0 and i + j < len(s):
|
||||
@ -275,7 +275,7 @@ proc init*[T](child: BoundedStreamReader, rsource: AsyncStreamReader,
|
||||
udata)
|
||||
|
||||
proc init*[T](child: BoundedStreamReader, rsource: AsyncStreamReader,
|
||||
boundary: openarray[byte], comparison = BoundCmp.Equal,
|
||||
boundary: openArray[byte], comparison = BoundCmp.Equal,
|
||||
bufferSize = BoundedBufferSize, udata: ref T) =
|
||||
doAssert(len(boundary) > 0, BoundarySizeDefectMessage)
|
||||
child.boundary = @boundary
|
||||
@ -284,7 +284,7 @@ proc init*[T](child: BoundedStreamReader, rsource: AsyncStreamReader,
|
||||
udata)
|
||||
|
||||
proc init*[T](child: BoundedStreamReader, rsource: AsyncStreamReader,
|
||||
boundSize: uint64, boundary: openarray[byte],
|
||||
boundSize: uint64, boundary: openArray[byte],
|
||||
comparison = BoundCmp.Equal,
|
||||
bufferSize = BoundedBufferSize, udata: ref T) =
|
||||
doAssert(len(boundary) > 0, BoundarySizeDefectMessage)
|
||||
@ -302,7 +302,7 @@ proc init*(child: BoundedStreamReader, rsource: AsyncStreamReader,
|
||||
init(AsyncStreamReader(child), rsource, boundedReadLoop, bufferSize)
|
||||
|
||||
proc init*(child: BoundedStreamReader, rsource: AsyncStreamReader,
|
||||
boundary: openarray[byte], comparison = BoundCmp.Equal,
|
||||
boundary: openArray[byte], comparison = BoundCmp.Equal,
|
||||
bufferSize = BoundedBufferSize) =
|
||||
doAssert(len(boundary) > 0, BoundarySizeDefectMessage)
|
||||
child.boundary = @boundary
|
||||
@ -310,7 +310,7 @@ proc init*(child: BoundedStreamReader, rsource: AsyncStreamReader,
|
||||
init(AsyncStreamReader(child), rsource, boundedReadLoop, bufferSize)
|
||||
|
||||
proc init*(child: BoundedStreamReader, rsource: AsyncStreamReader,
|
||||
boundSize: uint64, boundary: openarray[byte],
|
||||
boundSize: uint64, boundary: openArray[byte],
|
||||
comparison = BoundCmp.Equal, bufferSize = BoundedBufferSize) =
|
||||
doAssert(len(boundary) > 0, BoundarySizeDefectMessage)
|
||||
child.boundSize = some(boundSize)
|
||||
@ -338,7 +338,7 @@ proc newBoundedStreamReader*[T](rsource: AsyncStreamReader,
|
||||
res
|
||||
|
||||
proc newBoundedStreamReader*[T](rsource: AsyncStreamReader,
|
||||
boundary: openarray[byte],
|
||||
boundary: openArray[byte],
|
||||
comparison = BoundCmp.Equal,
|
||||
bufferSize = BoundedBufferSize,
|
||||
udata: ref T): BoundedStreamReader =
|
||||
@ -357,7 +357,7 @@ proc newBoundedStreamReader*[T](rsource: AsyncStreamReader,
|
||||
|
||||
proc newBoundedStreamReader*[T](rsource: AsyncStreamReader,
|
||||
boundSize: uint64,
|
||||
boundary: openarray[byte],
|
||||
boundary: openArray[byte],
|
||||
comparison = BoundCmp.Equal,
|
||||
bufferSize = BoundedBufferSize,
|
||||
udata: ref T): BoundedStreamReader =
|
||||
@ -396,7 +396,7 @@ proc newBoundedStreamReader*(rsource: AsyncStreamReader,
|
||||
res
|
||||
|
||||
proc newBoundedStreamReader*(rsource: AsyncStreamReader,
|
||||
boundary: openarray[byte],
|
||||
boundary: openArray[byte],
|
||||
comparison = BoundCmp.Equal,
|
||||
bufferSize = BoundedBufferSize,
|
||||
): BoundedStreamReader =
|
||||
@ -415,7 +415,7 @@ proc newBoundedStreamReader*(rsource: AsyncStreamReader,
|
||||
|
||||
proc newBoundedStreamReader*(rsource: AsyncStreamReader,
|
||||
boundSize: uint64,
|
||||
boundary: openarray[byte],
|
||||
boundary: openArray[byte],
|
||||
comparison = BoundCmp.Equal,
|
||||
bufferSize = BoundedBufferSize,
|
||||
): BoundedStreamReader =
|
||||
|
||||
@ -226,7 +226,7 @@ template readAndReset(fut: untyped) =
|
||||
if fut.finished():
|
||||
let res = fut.read()
|
||||
case res
|
||||
of TLSREsult.Success:
|
||||
of TLSResult.Success:
|
||||
fut = nil
|
||||
continue
|
||||
of TLSResult.Error:
|
||||
@ -619,7 +619,7 @@ proc copyKey(src: EcPrivateKey): TLSPrivateKey =
|
||||
res.eckey.curve = src.curve
|
||||
res
|
||||
|
||||
proc init*(tt: typedesc[TLSPrivateKey], data: openarray[byte]): TLSPrivateKey =
|
||||
proc init*(tt: typedesc[TLSPrivateKey], data: openArray[byte]): TLSPrivateKey =
|
||||
## Initialize TLS private key from array of bytes ``data``.
|
||||
##
|
||||
## This procedure initializes private key using raw, DER-encoded format,
|
||||
@ -642,7 +642,7 @@ proc init*(tt: typedesc[TLSPrivateKey], data: openarray[byte]): TLSPrivateKey =
|
||||
raiseTLSStreamProtocolError("Unknown key type (" & $keyType & ")")
|
||||
res
|
||||
|
||||
proc pemDecode*(data: openarray[char]): seq[PEMElement] =
|
||||
proc pemDecode*(data: openArray[char]): seq[PEMElement] =
|
||||
## Decode PEM encoded string and get array of binary blobs.
|
||||
if len(data) == 0:
|
||||
raiseTLSStreamProtocolError("Empty PEM message")
|
||||
@ -685,7 +685,7 @@ proc pemDecode*(data: openarray[char]): seq[PEMElement] =
|
||||
raiseTLSStreamProtocolError("Invalid PEM encoding")
|
||||
res
|
||||
|
||||
proc init*(tt: typedesc[TLSPrivateKey], data: openarray[char]): TLSPrivateKey =
|
||||
proc init*(tt: typedesc[TLSPrivateKey], data: openArray[char]): TLSPrivateKey =
|
||||
## Initialize TLS private key from string ``data``.
|
||||
##
|
||||
## This procedure initializes private key using unencrypted PKCS#8 PEM
|
||||
@ -703,7 +703,7 @@ proc init*(tt: typedesc[TLSPrivateKey], data: openarray[char]): TLSPrivateKey =
|
||||
res
|
||||
|
||||
proc init*(tt: typedesc[TLSCertificate],
|
||||
data: openarray[char]): TLSCertificate =
|
||||
data: openArray[char]): TLSCertificate =
|
||||
## Initialize TLS certificates from string ``data``.
|
||||
##
|
||||
## This procedure initializes array of certificates from PEM encoded string.
|
||||
|
||||
@ -1118,7 +1118,7 @@ elif defined(macosx) or defined(bsd):
|
||||
freeIfAddrs(ifap)
|
||||
res
|
||||
|
||||
proc sasize(data: openarray[byte]): int =
|
||||
proc sasize(data: openArray[byte]): int =
|
||||
# SA_SIZE() template. Taken from FreeBSD net/route.h:1.63
|
||||
if len(data) > 0:
|
||||
if data[0] == 0x00'u8:
|
||||
|
||||
@ -105,7 +105,7 @@ suite "HTTP server testing suite":
|
||||
let request = r.get()
|
||||
return await request.respond(Http200, "TEST_OK", HttpTable.init())
|
||||
else:
|
||||
if r.error().error == HTTPServerError.TimeoutError:
|
||||
if r.error().error == HttpServerError.TimeoutError:
|
||||
serverRes = true
|
||||
return dumbResponse()
|
||||
|
||||
@ -134,7 +134,7 @@ suite "HTTP server testing suite":
|
||||
let request = r.get()
|
||||
return await request.respond(Http200, "TEST_OK", HttpTable.init())
|
||||
else:
|
||||
if r.error().error == HTTPServerError.CriticalError:
|
||||
if r.error().error == HttpServerError.CriticalError:
|
||||
serverRes = true
|
||||
return dumbResponse()
|
||||
|
||||
@ -162,7 +162,7 @@ suite "HTTP server testing suite":
|
||||
let request = r.get()
|
||||
return await request.respond(Http200, "TEST_OK", HttpTable.init())
|
||||
else:
|
||||
if r.error().error == HTTPServerError.CriticalError:
|
||||
if r.error().error == HttpServerError.CriticalError:
|
||||
serverRes = true
|
||||
return dumbResponse()
|
||||
|
||||
@ -191,7 +191,7 @@ suite "HTTP server testing suite":
|
||||
if r.isOk():
|
||||
discard
|
||||
else:
|
||||
if r.error().error == HTTPServerError.CriticalError:
|
||||
if r.error().error == HttpServerError.CriticalError:
|
||||
serverRes = true
|
||||
return dumbResponse()
|
||||
|
||||
|
||||
@ -80,7 +80,7 @@ suite "Secure HTTP server testing suite":
|
||||
): Future[string] {.async.} =
|
||||
var
|
||||
transp: StreamTransport
|
||||
tlsstream: TlsAsyncStream
|
||||
tlsstream: TLSAsyncStream
|
||||
reader: AsyncStreamReader
|
||||
writer: AsyncStreamWriter
|
||||
|
||||
|
||||
@ -50,10 +50,10 @@ suite "callSoon() tests suite":
|
||||
callbackproc = proc (udata: pointer) {.gcsafe, raises: [Defect].} =
|
||||
timeoutsTest2 += 1
|
||||
{.gcsafe.}:
|
||||
callSoon(callbackProc)
|
||||
callSoon(callbackproc)
|
||||
|
||||
proc test2(timers, callbacks: var int) =
|
||||
callSoon(callbackProc)
|
||||
callSoon(callbackproc)
|
||||
waitFor(testProc())
|
||||
timers = timeoutsTest1
|
||||
callbacks = timeoutsTest2
|
||||
|
||||
@ -848,7 +848,7 @@ suite "Stream Transport test suite":
|
||||
res: seq[byte]
|
||||
error: ref CatchableError
|
||||
|
||||
proc predicate(data: openarray[byte]): tuple[consumed: int, done: bool] =
|
||||
proc predicate(data: openArray[byte]): tuple[consumed: int, done: bool] =
|
||||
if len(data) == 0:
|
||||
# There will be no more data, length-value incomplete
|
||||
error = newException(TransportIncompleteError, "LV incomplete")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user