[backport] run nimpretty on web stuff

This commit is contained in:
narimiran 2019-09-27 11:08:54 +02:00
commit 0ca9cc7419
8 changed files with 103 additions and 92 deletions

View file

@ -827,7 +827,8 @@ proc newConnection(client: HttpClient | AsyncHttpClient,
connectUrl.hostname = url.hostname connectUrl.hostname = url.hostname
connectUrl.port = if url.port != "": url.port else: "443" connectUrl.port = if url.port != "": url.port else: "443"
let proxyHeaderString = generateHeaders(connectUrl, $HttpConnect, newHttpHeaders(), "", client.proxy) let proxyHeaderString = generateHeaders(connectUrl, $HttpConnect,
newHttpHeaders(), "", client.proxy)
await client.socket.send(proxyHeaderString) await client.socket.send(proxyHeaderString)
let proxyResp = await parseResponse(client, false) let proxyResp = await parseResponse(client, false)

View file

@ -497,7 +497,8 @@ when defineSsl:
# http://simplestcodings.blogspot.co.uk/2010/08/secure-server-client-using-openssl-in-c.html # http://simplestcodings.blogspot.co.uk/2010/08/secure-server-client-using-openssl-in-c.html
proc loadCertificates(ctx: SSL_CTX, certFile, keyFile: string) = proc loadCertificates(ctx: SSL_CTX, certFile, keyFile: string) =
if certFile != "" and not existsFile(certFile): if certFile != "" and not existsFile(certFile):
raise newException(system.IOError, "Certificate file could not be found: " & certFile) raise newException(system.IOError,
"Certificate file could not be found: " & certFile)
if keyFile != "" and not existsFile(keyFile): if keyFile != "" and not existsFile(keyFile):
raise newException(system.IOError, "Key file could not be found: " & keyFile) raise newException(system.IOError, "Key file could not be found: " & keyFile)
@ -586,7 +587,8 @@ when defineSsl:
proc clientGetPskFunc*(ctx: SSLContext): SslClientGetPskFunc = proc clientGetPskFunc*(ctx: SSLContext): SslClientGetPskFunc =
return ctx.getExtraInternal().clientGetPskFunc return ctx.getExtraInternal().clientGetPskFunc
proc pskClientCallback(ssl: SslPtr; hint: cstring; identity: cstring; max_identity_len: cuint; psk: ptr cuchar; proc pskClientCallback(ssl: SslPtr; hint: cstring; identity: cstring;
max_identity_len: cuint; psk: ptr cuchar;
max_psk_len: cuint): cuint {.cdecl.} = max_psk_len: cuint): cuint {.cdecl.} =
let ctx = SSLContext(context: ssl.SSL_get_SSL_CTX) let ctx = SSLContext(context: ssl.SSL_get_SSL_CTX)
let hintString = if hint == nil: "" else: $hint let hintString = if hint == nil: "" else: $hint
@ -613,7 +615,8 @@ when defineSsl:
proc serverGetPskFunc*(ctx: SSLContext): SslServerGetPskFunc = proc serverGetPskFunc*(ctx: SSLContext): SslServerGetPskFunc =
return ctx.getExtraInternal().serverGetPskFunc return ctx.getExtraInternal().serverGetPskFunc
proc pskServerCallback(ssl: SslCtx; identity: cstring; psk: ptr cuchar; max_psk_len: cint): cuint {.cdecl.} = proc pskServerCallback(ssl: SslCtx; identity: cstring; psk: ptr cuchar;
max_psk_len: cint): cuint {.cdecl.} =
let ctx = SSLContext(context: ssl.SSL_get_SSL_CTX) let ctx = SSLContext(context: ssl.SSL_get_SSL_CTX)
let pskString = (ctx.serverGetPskFunc)($identity) let pskString = (ctx.serverGetPskFunc)($identity)
if psk.len.cint > max_psk_len: if psk.len.cint > max_psk_len:
@ -940,8 +943,8 @@ proc getPeerAddr*(socket: Socket): (string, Port) =
## This is high-level interface for `getpeername`:idx:. ## This is high-level interface for `getpeername`:idx:.
getPeerAddr(socket.fd, socket.domain) getPeerAddr(socket.fd, socket.domain)
proc setSockOpt*(socket: Socket, opt: SOBool, value: bool, level = SOL_SOCKET) {. proc setSockOpt*(socket: Socket, opt: SOBool, value: bool,
tags: [WriteIOEffect].} = level = SOL_SOCKET) {.tags: [WriteIOEffect].} =
## Sets option ``opt`` to a boolean value specified by ``value``. ## Sets option ``opt`` to a boolean value specified by ``value``.
## ##
## .. code-block:: Nim ## .. code-block:: Nim
@ -1038,7 +1041,8 @@ template retRead(flags, readBytes: int) {.dirty.} =
else: else:
return res return res
proc recv*(socket: Socket, data: pointer, size: int): int {.tags: [ReadIOEffect].} = proc recv*(socket: Socket, data: pointer, size: int): int {.tags: [
ReadIOEffect].} =
## Receives data from a socket. ## Receives data from a socket.
## ##
## **Note**: This is a low-level function, you may be interested in the higher ## **Note**: This is a low-level function, you may be interested in the higher
@ -1093,7 +1097,8 @@ proc waitFor(socket: Socket, waited: var Duration, timeout, size: int,
result = 1 result = 1
if size <= 0: assert false if size <= 0: assert false
if timeout == -1: return size if timeout == -1: return size
if socket.isBuffered and socket.bufLen != 0 and socket.bufLen != socket.currPos: if socket.isBuffered and socket.bufLen != 0 and
socket.bufLen != socket.currPos:
result = socket.bufLen - socket.currPos result = socket.bufLen - socket.currPos
result = min(result, size) result = min(result, size)
else: else:

View file

@ -90,7 +90,8 @@ proc decodeUrl*(s: string, decodePlus=true): string =
runnableExamples: runnableExamples:
assert decodeUrl("https%3A%2F%2Fnim-lang.org") == "https://nim-lang.org" assert decodeUrl("https%3A%2F%2Fnim-lang.org") == "https://nim-lang.org"
assert decodeUrl("https%3A%2F%2Fnim-lang.org%2Fthis+is+a+test") == "https://nim-lang.org/this is a test" assert decodeUrl("https%3A%2F%2Fnim-lang.org%2Fthis+is+a+test") == "https://nim-lang.org/this is a test"
assert decodeUrl("https%3A%2F%2Fnim-lang.org%2Fthis%20is%20a%20test", false) == "https://nim-lang.org/this is a test" assert decodeUrl("https%3A%2F%2Fnim-lang.org%2Fthis%20is%20a%20test",
false) == "https://nim-lang.org/this is a test"
proc handleHexChar(c: char, x: var int) {.inline.} = proc handleHexChar(c: char, x: var int) {.inline.} =
case c case c
of '0'..'9': x = (x shl 4) or (ord(c) - ord('0')) of '0'..'9': x = (x shl 4) or (ord(c) - ord('0'))
@ -119,7 +120,8 @@ proc decodeUrl*(s: string, decodePlus=true): string =
inc(j) inc(j)
setLen(result, j) setLen(result, j)
proc encodeQuery*(query: openArray[(string, string)], usePlus=true, omitEq=true): string = proc encodeQuery*(query: openArray[(string, string)], usePlus = true,
omitEq = true): string =
## Encodes a set of (key, value) parameters into a URL query string. ## Encodes a set of (key, value) parameters into a URL query string.
## ##
## Every (key, value) pair is URL-encoded and written as ``key=value``. If the ## Every (key, value) pair is URL-encoded and written as ``key=value``. If the
@ -369,7 +371,8 @@ proc combine*(uris: varargs[Uri]): Uri =
## **See also:** ## **See also:**
## * `/ proc <#/,Uri,string>`_ for building URIs ## * `/ proc <#/,Uri,string>`_ for building URIs
runnableExamples: runnableExamples:
let foo = combine(parseUri("https://nim-lang.org/"), parseUri("docs/"), parseUri("manual.html")) let foo = combine(parseUri("https://nim-lang.org/"), parseUri("docs/"),
parseUri("manual.html"))
assert foo.hostname == "nim-lang.org" assert foo.hostname == "nim-lang.org"
assert foo.path == "/docs/manual.html" assert foo.path == "/docs/manual.html"
result = uris[0] result = uris[0]

View file

@ -421,7 +421,8 @@ iterator mitems*(n: var XmlNode): var XmlNode {.inline.} =
assert n.k == xnElement assert n.k == xnElement
for i in 0 .. n.len-1: yield n[i] for i in 0 .. n.len-1: yield n[i]
proc toXmlAttributes*(keyValuePairs: varargs[tuple[key, val: string]]): XmlAttributes = proc toXmlAttributes*(keyValuePairs: varargs[tuple[key,
val: string]]): XmlAttributes =
## Converts `{key: value}` pairs into `XmlAttributes`. ## Converts `{key: value}` pairs into `XmlAttributes`.
## ##
## .. code-block:: ## .. code-block::
@ -654,7 +655,8 @@ proc child*(n: XmlNode, name: string): XmlNode =
if i.tag == name: if i.tag == name:
return i return i
proc findAll*(n: XmlNode, tag: string, result: var seq[XmlNode], caseInsensitive = false) = proc findAll*(n: XmlNode, tag: string, result: var seq[XmlNode],
caseInsensitive = false) =
## Iterates over all the children of `n` returning those matching `tag`. ## Iterates over all the children of `n` returning those matching `tag`.
## ##
## Found nodes satisfying the condition will be appended to the `result` ## Found nodes satisfying the condition will be appended to the `result`