From 22a1b1203829acabe618102e7295a116315e1bf0 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 10 Jun 2019 04:31:57 -0300 Subject: [PATCH] [documentation] fix #11281, httpclient examples (#11455) --- lib/pure/httpclient.nim | 49 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) 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