diff options
author | Juan Carlos <juancarlospaco@gmail.com> | 2019-06-10 04:31:57 -0300 |
---|---|---|
committer | Miran <narimiran@disroot.org> | 2019-06-10 09:31:57 +0200 |
commit | 22a1b1203829acabe618102e7295a116315e1bf0 (patch) | |
tree | 0de2791c742c03adc18b142187620e6668e06c9d /lib | |
parent | cb47e49d3bceb616b26bb3dc7bc0ec1a34927013 (diff) | |
download | Nim-22a1b1203829acabe618102e7295a116315e1bf0.tar.gz |
[documentation] fix #11281, httpclient examples (#11455)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/httpclient.nim | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim index 83cf77a1b..4139d83fd 100644 --- a/lib/pure/httpclient.nim +++ b/lib/pure/httpclient.nim @@ -121,12 +121,59 @@ ## if however data does not reach the client within the specified timeout a ## ``TimeoutError`` exception will be raised. ## +## Here is how to set a timeout when creating an ``HttpClient`` instance: +## +## .. code-block:: Nim +## import httpclient +## +## let client = newHttpClient(timeout = 42) +## ## Proxy ## ===== ## ## A proxy can be specified as a param to any of the procedures defined in ## this module. To do this, use the ``newProxy`` constructor. Unfortunately, ## only basic authentication is supported at the moment. +## +## Some examples on how to configure a Proxy for ``HttpClient``: +## +## .. code-block:: Nim +## import httpclient +## +## let myProxy = newProxy("http://myproxy.network") +## let client = newHttpClient(proxy = myProxy) +## +## Get Proxy URL from environment variables: +## +## .. code-block:: Nim +## import httpclient +## +## var url = "" +## try: +## if existsEnv("http_proxy"): +## url = getEnv("http_proxy") +## elif existsEnv("https_proxy"): +## url = getEnv("https_proxy") +## except ValueError: +## echo "Unable to parse proxy from environment variables." +## +## let myProxy = newProxy(url = url) +## let client = newHttpClient(proxy = myProxy) +## +## Redirects +## ========= +## +## The maximum redirects can be set with the ``maxRedirects`` of ``int`` type, +## it specifies the maximum amount of redirects to follow, +## it defaults to ``5``, you can set it to ``0`` to disable redirects. +## +## Here you can see an example about how to set the ``maxRedirects`` of ``HttpClient``: +## +## .. code-block:: Nim +## import httpclient +## +## let client = newHttpClient(maxRedirects = 0) +## import net, strutils, uri, parseutils, strtabs, base64, os, mimetypes, math, random, httpcore, times, tables, streams @@ -647,7 +694,7 @@ proc getSocket*(client: HttpClient): Socket = ## ## .. code-block:: Nim ## if client.connected: - ## echo client.getSocket.getLocalAddr + ## echo client.getSocket.getLocalAddr ## echo client.getSocket.getPeerAddr ## return client.socket |