httpclient.html 152 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <!-- This file is generated by Nim. -->
  4. <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <title>std/httpclient</title>
  9. <!-- Google fonts -->
  10. <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
  11. <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
  12. <!-- Favicon -->
  13. <link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
  14. <link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
  15. <!-- CSS -->
  16. <link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
  17. <!-- JS -->
  18. <script type="text/javascript" src="dochack.js?v=2.3.1"></script>
  19. </head>
  20. <body>
  21. <div class="document" id="documentId">
  22. <div class="container">
  23. <h1 class="title">std/httpclient</h1>
  24. <div class="row">
  25. <div class="three columns">
  26. <div class="theme-select-wrapper">
  27. <label for="theme-select">Theme:&nbsp;</label>
  28. <select id="theme-select" onchange="setTheme(this.value)">
  29. <option value="auto">🌗 Match OS</option>
  30. <option value="dark">🌑 Dark</option>
  31. <option value="light">🌕 Light</option>
  32. </select>
  33. </div>
  34. <div id="global-links">
  35. <ul class="simple-boot">
  36. <li><a href="manual.html">Manual</a></li>
  37. <li><a href="lib.html">Standard library</a></li>
  38. <li> <a id="indexLink" href="theindex.html">Index</a></li>
  39. <li><a href="compiler/theindex.html">Compiler docs</a></li>
  40. <li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
  41. <li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
  42. </ul>
  43. </div>
  44. <div id="searchInputDiv">
  45. Search: <input type="search" id="searchInput"
  46. oninput="search()" />
  47. </div>
  48. <ul class="simple simple-toc" id="toc-list">
  49. <li><a class="reference" id="retrieving-a-website_toc" href="#retrieving-a-website">Retrieving a website</a></li>
  50. <li><a class="reference" id="using-http-post_toc" href="#using-http-post">Using HTTP POST</a></li>
  51. <li><a class="reference" id="progress-reporting_toc" href="#progress-reporting">Progress reporting</a></li>
  52. <li><a class="reference" id="sslslashtls-support_toc" href="#sslslashtls-support">SSL/TLS support</a></li>
  53. <li><a class="reference" id="timeouts_toc" href="#timeouts">Timeouts</a></li>
  54. <li><a class="reference" id="proxy_toc" href="#proxy">Proxy</a></li>
  55. <li><a class="reference" id="redirects_toc" href="#redirects">Redirects</a></li>
  56. <li>
  57. <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
  58. </li>
  59. <li>
  60. <details open>
  61. <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
  62. <ul class="simple simple-toc-section">
  63. <li><a class="reference" href="#AsyncHttpClient" title="AsyncHttpClient = HttpClientBase[AsyncSocket]">AsyncHttpClient</a></li>
  64. <li><a class="reference" href="#AsyncResponse" title="AsyncResponse = ref object
  65. version*: string
  66. status*: string
  67. headers*: HttpHeaders
  68. bodyStream*: FutureStream[string]">AsyncResponse</a></li>
  69. <li><a class="reference" href="#HttpClient" title="HttpClient = HttpClientBase[Socket]">HttpClient</a></li>
  70. <li><a class="reference" href="#HttpClientBase" title="HttpClientBase[SocketType] = ref object
  71. ## Where we are currently connected.
  72. headers*: HttpHeaders ## Headers to send in requests.
  73. ## Maximum redirects, set to `0` to disable.
  74. timeout*: int ## Only used for blocking HttpClient for now.
  75. ## `nil` or the callback to call when request progress changes.
  76. when SocketType is Socket:
  77. onProgressChanged*: ProgressChangedProc[void]
  78. else:
  79. onProgressChanged*: ProgressChangedProc[Future[void]]
  80. when defined(ssl):
  81. when SocketType is AsyncSocket:
  82. else:
  83. ## When `false`, the body is never read in requestAux.">HttpClientBase</a></li>
  84. <li><a class="reference" href="#HttpRequestError" title="HttpRequestError = object of IOError">HttpRequestError</a></li>
  85. <li><a class="reference" href="#MultipartData" title="MultipartData = ref object">MultipartData</a></li>
  86. <li><a class="reference" href="#MultipartEntries" title="MultipartEntries = openArray[tuple[name, content: string]]">MultipartEntries</a></li>
  87. <li><a class="reference" href="#ProgressChangedProc" title="ProgressChangedProc[ReturnType] = proc (total, progress, speed: BiggestInt): ReturnType {.
  88. closure, gcsafe.}">ProgressChangedProc</a></li>
  89. <li><a class="reference" href="#ProtocolError" title="ProtocolError = object of IOError">ProtocolError</a></li>
  90. <li><a class="reference" href="#Proxy" title="Proxy = ref object
  91. url*: Uri
  92. auth*: string">Proxy</a></li>
  93. <li><a class="reference" href="#Response" title="Response = ref object
  94. version*: string
  95. status*: string
  96. headers*: HttpHeaders
  97. bodyStream*: Stream">Response</a></li>
  98. </ul>
  99. </details>
  100. </li>
  101. <li>
  102. <details open>
  103. <summary><a class="reference reference-toplevel" href="#10" id="60">Consts</a></summary>
  104. <ul class="simple simple-toc-section">
  105. <li><a class="reference" href="#defUserAgent" title="defUserAgent = &quot;Nim-httpclient/2.3.1&quot;">defUserAgent</a></li>
  106. </ul>
  107. </details>
  108. </li>
  109. <li>
  110. <details open>
  111. <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
  112. <ul class="simple simple-toc-section">
  113. <ul class="simple nested-toc-section">$
  114. <li><a class="reference" href="#%24%2CMultipartData" title="`$`(data: MultipartData): string">`$`(data: MultipartData): string</a></li>
  115. </ul>
  116. <ul class="simple nested-toc-section">[]=
  117. <li><a class="reference" href="#%5B%5D%3D%2CMultipartData%2Cstring%2Cstring" title="`[]=`(p: MultipartData; name, content: string)">`[]=`(p: MultipartData; name, content: string)</a></li>
  118. <li><a class="reference" href="#%5B%5D%3D%2CMultipartData%2Cstring%2Ctuple%5Bstring%2Cstring%2Cstring%5D" title="`[]=`(p: MultipartData; name: string;
  119. file: tuple[name, contentType, content: string])">`[]=`(p: MultipartData; name: string;
  120. file: tuple[name, contentType, content: string])</a></li>
  121. </ul>
  122. <ul class="simple nested-toc-section">add
  123. <li><a class="reference" href="#add%2CMultipartData%2Cstring%2Cstring%2Cstring%2Cstring" title="add(p: MultipartData; name, content: string; filename: string = &quot;&quot;;
  124. contentType: string = &quot;&quot;; useStream = true)">add(p: MultipartData; name, content: string; filename: string = &quot;&quot;;
  125. contentType: string = &quot;&quot;; useStream = true)</a></li>
  126. <li><a class="reference" href="#add%2CMultipartData%2CMultipartEntries" title="add(p: MultipartData; xs: MultipartEntries): MultipartData">add(p: MultipartData; xs: MultipartEntries): MultipartData</a></li>
  127. </ul>
  128. <ul class="simple nested-toc-section">addFiles
  129. <li><a class="reference" href="#addFiles%2CMultipartData%2CopenArray%5Btuple%5Bstring%2Cstring%5D%5D" title="addFiles(p: MultipartData; xs: openArray[tuple[name, file: string]];
  130. mimeDb = newMimetypes(); useStream = true): MultipartData">addFiles(p: MultipartData; xs: openArray[tuple[name, file: string]];
  131. mimeDb = newMimetypes(); useStream = true): MultipartData</a></li>
  132. </ul>
  133. <ul class="simple nested-toc-section">body
  134. <li><a class="reference" href="#body%2CAsyncResponse" title="body(response: AsyncResponse): Future[string]">body(response: AsyncResponse): Future[string]</a></li>
  135. <li><a class="reference" href="#body%2CResponse" title="body(response: Response): string">body(response: Response): string</a></li>
  136. </ul>
  137. <ul class="simple nested-toc-section">close
  138. <li><a class="reference" href="#close" title="close(client: HttpClient | AsyncHttpClient)">close(client: HttpClient | AsyncHttpClient)</a></li>
  139. </ul>
  140. <ul class="simple nested-toc-section">code
  141. <li><a class="reference" href="#code" title="code(response: Response | AsyncResponse): HttpCode">code(response: Response | AsyncResponse): HttpCode</a></li>
  142. </ul>
  143. <ul class="simple nested-toc-section">contentLength
  144. <li><a class="reference" href="#contentLength" title="contentLength(response: Response | AsyncResponse): int">contentLength(response: Response | AsyncResponse): int</a></li>
  145. </ul>
  146. <ul class="simple nested-toc-section">contentType
  147. <li><a class="reference" href="#contentType" title="contentType(response: Response | AsyncResponse): string">contentType(response: Response | AsyncResponse): string</a></li>
  148. </ul>
  149. <ul class="simple nested-toc-section">delete
  150. <li><a class="reference" href="#delete%2CAsyncHttpClient%2C" title="delete(client: AsyncHttpClient; url: Uri | string): Future[AsyncResponse]">delete(client: AsyncHttpClient; url: Uri | string): Future[AsyncResponse]</a></li>
  151. <li><a class="reference" href="#delete%2CHttpClient%2C" title="delete(client: HttpClient; url: Uri | string): Response">delete(client: HttpClient; url: Uri | string): Response</a></li>
  152. </ul>
  153. <ul class="simple nested-toc-section">deleteContent
  154. <li><a class="reference" href="#deleteContent%2CAsyncHttpClient%2C" title="deleteContent(client: AsyncHttpClient; url: Uri | string): Future[string]">deleteContent(client: AsyncHttpClient; url: Uri | string): Future[string]</a></li>
  155. <li><a class="reference" href="#deleteContent%2CHttpClient%2C" title="deleteContent(client: HttpClient; url: Uri | string): string">deleteContent(client: HttpClient; url: Uri | string): string</a></li>
  156. </ul>
  157. <ul class="simple nested-toc-section">downloadFile
  158. <li><a class="reference" href="#downloadFile%2CAsyncHttpClient%2C%2Cstring" title="downloadFile(client: AsyncHttpClient; url: Uri | string; filename: string): Future[
  159. void]">downloadFile(client: AsyncHttpClient; url: Uri | string; filename: string): Future[
  160. void]</a></li>
  161. <li><a class="reference" href="#downloadFile%2CHttpClient%2C%2Cstring" title="downloadFile(client: HttpClient; url: Uri | string; filename: string)">downloadFile(client: HttpClient; url: Uri | string; filename: string)</a></li>
  162. </ul>
  163. <ul class="simple nested-toc-section">get
  164. <li><a class="reference" href="#get%2CAsyncHttpClient%2C" title="get(client: AsyncHttpClient; url: Uri | string): Future[AsyncResponse]">get(client: AsyncHttpClient; url: Uri | string): Future[AsyncResponse]</a></li>
  165. <li><a class="reference" href="#get%2CHttpClient%2C" title="get(client: HttpClient; url: Uri | string): Response">get(client: HttpClient; url: Uri | string): Response</a></li>
  166. </ul>
  167. <ul class="simple nested-toc-section">getContent
  168. <li><a class="reference" href="#getContent%2CAsyncHttpClient%2C" title="getContent(client: AsyncHttpClient; url: Uri | string): Future[string]">getContent(client: AsyncHttpClient; url: Uri | string): Future[string]</a></li>
  169. <li><a class="reference" href="#getContent%2CHttpClient%2C" title="getContent(client: HttpClient; url: Uri | string): string">getContent(client: HttpClient; url: Uri | string): string</a></li>
  170. </ul>
  171. <ul class="simple nested-toc-section">getSocket
  172. <li><a class="reference" href="#getSocket%2CAsyncHttpClient" title="getSocket(client: AsyncHttpClient): AsyncSocket">getSocket(client: AsyncHttpClient): AsyncSocket</a></li>
  173. <li><a class="reference" href="#getSocket%2CHttpClient" title="getSocket(client: HttpClient): Socket">getSocket(client: HttpClient): Socket</a></li>
  174. </ul>
  175. <ul class="simple nested-toc-section">head
  176. <li><a class="reference" href="#head%2CAsyncHttpClient%2C" title="head(client: AsyncHttpClient; url: Uri | string): Future[AsyncResponse]">head(client: AsyncHttpClient; url: Uri | string): Future[AsyncResponse]</a></li>
  177. <li><a class="reference" href="#head%2CHttpClient%2C" title="head(client: HttpClient; url: Uri | string): Response">head(client: HttpClient; url: Uri | string): Response</a></li>
  178. </ul>
  179. <ul class="simple nested-toc-section">lastModified
  180. <li><a class="reference" href="#lastModified" title="lastModified(response: Response | AsyncResponse): DateTime">lastModified(response: Response | AsyncResponse): DateTime</a></li>
  181. </ul>
  182. <ul class="simple nested-toc-section">newAsyncHttpClient
  183. <li><a class="reference" href="#newAsyncHttpClient%2Cint%2CProxy" title="newAsyncHttpClient(userAgent = defUserAgent; maxRedirects = 5;
  184. sslContext = getDefaultSSL(); proxy: Proxy = nil;
  185. headers = newHttpHeaders()): AsyncHttpClient">newAsyncHttpClient(userAgent = defUserAgent; maxRedirects = 5;
  186. sslContext = getDefaultSSL(); proxy: Proxy = nil;
  187. headers = newHttpHeaders()): AsyncHttpClient</a></li>
  188. </ul>
  189. <ul class="simple nested-toc-section">newHttpClient
  190. <li><a class="reference" href="#newHttpClient%2Cint%2CProxy%2Cint" title="newHttpClient(userAgent = defUserAgent; maxRedirects = 5;
  191. sslContext = getDefaultSSL(); proxy: Proxy = nil; timeout = -1;
  192. headers = newHttpHeaders()): HttpClient">newHttpClient(userAgent = defUserAgent; maxRedirects = 5;
  193. sslContext = getDefaultSSL(); proxy: Proxy = nil; timeout = -1;
  194. headers = newHttpHeaders()): HttpClient</a></li>
  195. </ul>
  196. <ul class="simple nested-toc-section">newMultipartData
  197. <li><a class="reference" href="#newMultipartData" title="newMultipartData(): MultipartData">newMultipartData(): MultipartData</a></li>
  198. <li><a class="reference" href="#newMultipartData%2CMultipartEntries" title="newMultipartData(xs: MultipartEntries): MultipartData">newMultipartData(xs: MultipartEntries): MultipartData</a></li>
  199. </ul>
  200. <ul class="simple nested-toc-section">newProxy
  201. <li><a class="reference" href="#newProxy%2Cstring%2Cstring" title="newProxy(url: string; auth = &quot;&quot;): Proxy">newProxy(url: string; auth = &quot;&quot;): Proxy</a></li>
  202. <li><a class="reference" href="#newProxy%2CUri%2Cstring" title="newProxy(url: Uri; auth = &quot;&quot;): Proxy">newProxy(url: Uri; auth = &quot;&quot;): Proxy</a></li>
  203. </ul>
  204. <ul class="simple nested-toc-section">patch
  205. <li><a class="reference" href="#patch%2CAsyncHttpClient%2C%2Cstring%2CMultipartData" title="patch(client: AsyncHttpClient; url: Uri | string; body = &quot;&quot;;
  206. multipart: MultipartData = nil): Future[AsyncResponse]">patch(client: AsyncHttpClient; url: Uri | string; body = &quot;&quot;;
  207. multipart: MultipartData = nil): Future[AsyncResponse]</a></li>
  208. <li><a class="reference" href="#patch%2CHttpClient%2C%2Cstring%2CMultipartData" title="patch(client: HttpClient; url: Uri | string; body = &quot;&quot;;
  209. multipart: MultipartData = nil): Response">patch(client: HttpClient; url: Uri | string; body = &quot;&quot;;
  210. multipart: MultipartData = nil): Response</a></li>
  211. </ul>
  212. <ul class="simple nested-toc-section">patchContent
  213. <li><a class="reference" href="#patchContent%2CAsyncHttpClient%2C%2Cstring%2CMultipartData" title="patchContent(client: AsyncHttpClient; url: Uri | string; body = &quot;&quot;;
  214. multipart: MultipartData = nil): Future[string]">patchContent(client: AsyncHttpClient; url: Uri | string; body = &quot;&quot;;
  215. multipart: MultipartData = nil): Future[string]</a></li>
  216. <li><a class="reference" href="#patchContent%2CHttpClient%2C%2Cstring%2CMultipartData" title="patchContent(client: HttpClient; url: Uri | string; body = &quot;&quot;;
  217. multipart: MultipartData = nil): string">patchContent(client: HttpClient; url: Uri | string; body = &quot;&quot;;
  218. multipart: MultipartData = nil): string</a></li>
  219. </ul>
  220. <ul class="simple nested-toc-section">post
  221. <li><a class="reference" href="#post%2CAsyncHttpClient%2C%2Cstring%2CMultipartData" title="post(client: AsyncHttpClient; url: Uri | string; body = &quot;&quot;;
  222. multipart: MultipartData = nil): Future[AsyncResponse]">post(client: AsyncHttpClient; url: Uri | string; body = &quot;&quot;;
  223. multipart: MultipartData = nil): Future[AsyncResponse]</a></li>
  224. <li><a class="reference" href="#post%2CHttpClient%2C%2Cstring%2CMultipartData" title="post(client: HttpClient; url: Uri | string; body = &quot;&quot;;
  225. multipart: MultipartData = nil): Response">post(client: HttpClient; url: Uri | string; body = &quot;&quot;;
  226. multipart: MultipartData = nil): Response</a></li>
  227. </ul>
  228. <ul class="simple nested-toc-section">postContent
  229. <li><a class="reference" href="#postContent%2CAsyncHttpClient%2C%2Cstring%2CMultipartData" title="postContent(client: AsyncHttpClient; url: Uri | string; body = &quot;&quot;;
  230. multipart: MultipartData = nil): Future[string]">postContent(client: AsyncHttpClient; url: Uri | string; body = &quot;&quot;;
  231. multipart: MultipartData = nil): Future[string]</a></li>
  232. <li><a class="reference" href="#postContent%2CHttpClient%2C%2Cstring%2CMultipartData" title="postContent(client: HttpClient; url: Uri | string; body = &quot;&quot;;
  233. multipart: MultipartData = nil): string">postContent(client: HttpClient; url: Uri | string; body = &quot;&quot;;
  234. multipart: MultipartData = nil): string</a></li>
  235. </ul>
  236. <ul class="simple nested-toc-section">put
  237. <li><a class="reference" href="#put%2CAsyncHttpClient%2C%2Cstring%2CMultipartData" title="put(client: AsyncHttpClient; url: Uri | string; body = &quot;&quot;;
  238. multipart: MultipartData = nil): Future[AsyncResponse]">put(client: AsyncHttpClient; url: Uri | string; body = &quot;&quot;;
  239. multipart: MultipartData = nil): Future[AsyncResponse]</a></li>
  240. <li><a class="reference" href="#put%2CHttpClient%2C%2Cstring%2CMultipartData" title="put(client: HttpClient; url: Uri | string; body = &quot;&quot;;
  241. multipart: MultipartData = nil): Response">put(client: HttpClient; url: Uri | string; body = &quot;&quot;;
  242. multipart: MultipartData = nil): Response</a></li>
  243. </ul>
  244. <ul class="simple nested-toc-section">putContent
  245. <li><a class="reference" href="#putContent%2CAsyncHttpClient%2C%2Cstring%2CMultipartData" title="putContent(client: AsyncHttpClient; url: Uri | string; body = &quot;&quot;;
  246. multipart: MultipartData = nil): Future[string]">putContent(client: AsyncHttpClient; url: Uri | string; body = &quot;&quot;;
  247. multipart: MultipartData = nil): Future[string]</a></li>
  248. <li><a class="reference" href="#putContent%2CHttpClient%2C%2Cstring%2CMultipartData" title="putContent(client: HttpClient; url: Uri | string; body = &quot;&quot;;
  249. multipart: MultipartData = nil): string">putContent(client: HttpClient; url: Uri | string; body = &quot;&quot;;
  250. multipart: MultipartData = nil): string</a></li>
  251. </ul>
  252. <ul class="simple nested-toc-section">request
  253. <li><a class="reference" href="#request%2CAsyncHttpClient%2C%2Cstring%2CHttpHeaders%2CMultipartData" title="request(client: AsyncHttpClient; url: Uri | string;
  254. httpMethod: HttpMethod | string = HttpGet; body = &quot;&quot;;
  255. headers: HttpHeaders = nil; multipart: MultipartData = nil): Future[
  256. AsyncResponse]">request(client: AsyncHttpClient; url: Uri | string;
  257. httpMethod: HttpMethod | string = HttpGet; body = &quot;&quot;;
  258. headers: HttpHeaders = nil; multipart: MultipartData = nil): Future[
  259. AsyncResponse]</a></li>
  260. <li><a class="reference" href="#request%2CHttpClient%2C%2Cstring%2CHttpHeaders%2CMultipartData" title="request(client: HttpClient; url: Uri | string;
  261. httpMethod: HttpMethod | string = HttpGet; body = &quot;&quot;;
  262. headers: HttpHeaders = nil; multipart: MultipartData = nil): Response">request(client: HttpClient; url: Uri | string;
  263. httpMethod: HttpMethod | string = HttpGet; body = &quot;&quot;;
  264. headers: HttpHeaders = nil; multipart: MultipartData = nil): Response</a></li>
  265. </ul>
  266. </ul>
  267. </details>
  268. </li>
  269. </ul>
  270. </div>
  271. <div class="nine columns" id="content">
  272. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  273. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  274. <div id="tocRoot"></div>
  275. <p class="module-desc">This module implements a simple HTTP client that can be used to retrieve webpages and other data.<div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
  276. Validate untrusted inputs: URI parsers and getters are not detecting malicious URIs.</div>
  277. <h1><a class="toc-backref" id="retrieving-a-website" href="#retrieving-a-website">Retrieving a website</a></h1><p>This example uses HTTP GET to retrieve <tt class="docutils literal"><span class="pre"><span class="Identifier">http</span><span class="Punctuation">:</span><span class="Operator">//</span><span class="Identifier">google</span><span class="Operator">.</span><span class="Identifier">com</span></span></tt>:</p>
  278. <p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">httpclient</span>
  279. <span class="Keyword">var</span> <span class="Identifier">client</span> <span class="Operator">=</span> <span class="Identifier">newHttpClient</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  280. <span class="Keyword">try</span><span class="Punctuation">:</span>
  281. <span class="Identifier">echo</span> <span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">getContent</span><span class="Punctuation">(</span><span class="StringLit">&quot;http://google.com&quot;</span><span class="Punctuation">)</span>
  282. <span class="Keyword">finally</span><span class="Punctuation">:</span>
  283. <span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre></p>
  284. <p>The same action can also be performed asynchronously, simply use the <tt class="docutils literal"><span class="pre"><span class="Identifier">AsyncHttpClient</span></span></tt>:</p>
  285. <p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Punctuation">[</span><span class="Identifier">asyncdispatch</span><span class="Punctuation">,</span> <span class="Identifier">httpclient</span><span class="Punctuation">]</span>
  286. <span class="Keyword">proc</span> <span class="Identifier">asyncProc</span><span class="Punctuation">(</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Identifier">Future</span><span class="Punctuation">[</span><span class="Identifier">string</span><span class="Punctuation">]</span> <span class="Punctuation">{</span><span class="Operator">.</span><span class="Identifier">async</span><span class="Operator">.</span><span class="Punctuation">}</span> <span class="Operator">=</span>
  287. <span class="Keyword">var</span> <span class="Identifier">client</span> <span class="Operator">=</span> <span class="Identifier">newAsyncHttpClient</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  288. <span class="Keyword">try</span><span class="Punctuation">:</span>
  289. <span class="Keyword">return</span> <span class="Identifier">await</span> <span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">getContent</span><span class="Punctuation">(</span><span class="StringLit">&quot;http://google.com&quot;</span><span class="Punctuation">)</span>
  290. <span class="Keyword">finally</span><span class="Punctuation">:</span>
  291. <span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  292. <span class="Identifier">echo</span> <span class="Identifier">waitFor</span> <span class="Identifier">asyncProc</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre></p>
  293. <p>The functionality implemented by <tt class="docutils literal"><span class="pre"><span class="Identifier">HttpClient</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">AsyncHttpClient</span></span></tt> is the same, so you can use whichever one suits you best in the examples shown here.</p>
  294. <p><strong>Note:</strong> You need to run asynchronous examples in an async proc otherwise you will get an <tt class="docutils literal"><span class="pre"><span class="Identifier">Undeclared</span> <span class="Identifier">identifier</span><span class="Punctuation">:</span> <span class="CharLit">'await'</span></span></tt> error.</p>
  295. <p><strong>Note:</strong> An asynchronous client instance can only deal with one request at a time. To send multiple requests in parallel, use multiple client instances.</p>
  296. <h1><a class="toc-backref" id="using-http-post" href="#using-http-post">Using HTTP POST</a></h1><p>This example demonstrates the usage of the W3 HTML Validator, it uses <tt class="docutils literal"><span class="pre"><span class="Identifier">multipart</span><span class="Operator">/</span><span class="Identifier">form</span><span class="Operator">-</span><span class="Identifier">data</span></span></tt> as the <tt class="docutils literal"><span class="pre"><span class="Identifier">Content</span><span class="Operator">-</span><span class="Keyword">Type</span></span></tt> to send the HTML to be validated to the server.</p>
  297. <p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Punctuation">[</span><span class="Identifier">httpclient</span><span class="Punctuation">]</span>
  298. <span class="Keyword">var</span> <span class="Identifier">client</span> <span class="Operator">=</span> <span class="Identifier">newHttpClient</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  299. <span class="Keyword">var</span> <span class="Identifier">data</span> <span class="Operator">=</span> <span class="Identifier">newMultipartData</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  300. <span class="Identifier">data</span><span class="Punctuation">[</span><span class="StringLit">&quot;output&quot;</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="StringLit">&quot;soap12&quot;</span>
  301. <span class="Identifier">data</span><span class="Punctuation">[</span><span class="StringLit">&quot;uploaded_file&quot;</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="Punctuation">(</span><span class="StringLit">&quot;test.html&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;text/html&quot;</span><span class="Punctuation">,</span>
  302. <span class="StringLit">&quot;&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;test&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;&quot;</span><span class="Punctuation">)</span>
  303. <span class="Keyword">try</span><span class="Punctuation">:</span>
  304. <span class="Identifier">echo</span> <span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">postContent</span><span class="Punctuation">(</span><span class="StringLit">&quot;http://validator.w3.org/check&quot;</span><span class="Punctuation">,</span> <span class="Identifier">multipart</span><span class="Operator">=</span><span class="Identifier">data</span><span class="Punctuation">)</span>
  305. <span class="Keyword">finally</span><span class="Punctuation">:</span>
  306. <span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre></p>
  307. <p>To stream files from disk when performing the request, use <tt class="docutils literal"><span class="pre"><span class="Identifier">addFiles</span></span></tt>.</p>
  308. <p><strong>Note:</strong> This will allocate a new <tt class="docutils literal"><span class="pre"><span class="Identifier">Mimetypes</span></span></tt> database every time you call it, you can pass your own via the <tt class="docutils literal"><span class="pre"><span class="Identifier">mimeDb</span></span></tt> parameter to avoid this.</p>
  309. <p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Punctuation">[</span><span class="Identifier">httpclient</span><span class="Punctuation">,</span> <span class="Identifier">mimetypes</span><span class="Punctuation">]</span>
  310. <span class="Keyword">let</span> <span class="Identifier">mimes</span> <span class="Operator">=</span> <span class="Identifier">newMimetypes</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  311. <span class="Keyword">var</span> <span class="Identifier">client</span> <span class="Operator">=</span> <span class="Identifier">newHttpClient</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  312. <span class="Keyword">var</span> <span class="Identifier">data</span> <span class="Operator">=</span> <span class="Identifier">newMultipartData</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  313. <span class="Identifier">data</span><span class="Operator">.</span><span class="Identifier">addFiles</span><span class="Punctuation">(</span><span class="Punctuation">{</span><span class="StringLit">&quot;uploaded_file&quot;</span><span class="Punctuation">:</span> <span class="StringLit">&quot;test.html&quot;</span><span class="Punctuation">}</span><span class="Punctuation">,</span> <span class="Identifier">mimeDb</span> <span class="Operator">=</span> <span class="Identifier">mimes</span><span class="Punctuation">)</span>
  314. <span class="Keyword">try</span><span class="Punctuation">:</span>
  315. <span class="Identifier">echo</span> <span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">postContent</span><span class="Punctuation">(</span><span class="StringLit">&quot;http://validator.w3.org/check&quot;</span><span class="Punctuation">,</span> <span class="Identifier">multipart</span><span class="Operator">=</span><span class="Identifier">data</span><span class="Punctuation">)</span>
  316. <span class="Keyword">finally</span><span class="Punctuation">:</span>
  317. <span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre></p>
  318. <p>You can also make post requests with custom headers. This example sets <tt class="docutils literal"><span class="pre"><span class="Identifier">Content</span><span class="Operator">-</span><span class="Keyword">Type</span></span></tt> to <tt class="docutils literal"><span class="pre"><span class="Identifier">application</span><span class="Operator">/</span><span class="Identifier">json</span></span></tt> and uses a json object for the body</p>
  319. <p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Punctuation">[</span><span class="Identifier">httpclient</span><span class="Punctuation">,</span> <span class="Identifier">json</span><span class="Punctuation">]</span>
  320. <span class="Keyword">let</span> <span class="Identifier">client</span> <span class="Operator">=</span> <span class="Identifier">newHttpClient</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  321. <span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">headers</span> <span class="Operator">=</span> <span class="Identifier">newHttpHeaders</span><span class="Punctuation">(</span><span class="Punctuation">{</span> <span class="StringLit">&quot;Content-Type&quot;</span><span class="Punctuation">:</span> <span class="StringLit">&quot;application/json&quot;</span> <span class="Punctuation">}</span><span class="Punctuation">)</span>
  322. <span class="Keyword">let</span> <span class="Identifier">body</span> <span class="Operator">=</span> <span class="Operator">%*</span><span class="Punctuation">{</span>
  323. <span class="StringLit">&quot;data&quot;</span><span class="Punctuation">:</span> <span class="StringLit">&quot;some text&quot;</span>
  324. <span class="Punctuation">}</span>
  325. <span class="Keyword">try</span><span class="Punctuation">:</span>
  326. <span class="Keyword">let</span> <span class="Identifier">response</span> <span class="Operator">=</span> <span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">request</span><span class="Punctuation">(</span><span class="StringLit">&quot;http://some.api&quot;</span><span class="Punctuation">,</span> <span class="Identifier">httpMethod</span> <span class="Operator">=</span> <span class="Identifier">HttpPost</span><span class="Punctuation">,</span> <span class="Identifier">body</span> <span class="Operator">=</span> <span class="Operator">$</span><span class="Identifier">body</span><span class="Punctuation">)</span>
  327. <span class="Identifier">echo</span> <span class="Identifier">response</span><span class="Operator">.</span><span class="Identifier">status</span>
  328. <span class="Keyword">finally</span><span class="Punctuation">:</span>
  329. <span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre></p>
  330. <h1><a class="toc-backref" id="progress-reporting" href="#progress-reporting">Progress reporting</a></h1><p>You may specify a callback procedure to be called during an HTTP request. This callback will be executed every second with information about the progress of the HTTP request.</p>
  331. <p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Punctuation">[</span><span class="Identifier">asyncdispatch</span><span class="Punctuation">,</span> <span class="Identifier">httpclient</span><span class="Punctuation">]</span>
  332. <span class="Keyword">proc</span> <span class="Identifier">onProgressChanged</span><span class="Punctuation">(</span><span class="Identifier">total</span><span class="Punctuation">,</span> <span class="Identifier">progress</span><span class="Punctuation">,</span> <span class="Identifier">speed</span><span class="Punctuation">:</span> <span class="Identifier">BiggestInt</span><span class="Punctuation">)</span> <span class="Punctuation">{</span><span class="Operator">.</span><span class="Identifier">async</span><span class="Operator">.</span><span class="Punctuation">}</span> <span class="Operator">=</span>
  333. <span class="Identifier">echo</span><span class="Punctuation">(</span><span class="StringLit">&quot;Downloaded &quot;</span><span class="Punctuation">,</span> <span class="Identifier">progress</span><span class="Punctuation">,</span> <span class="StringLit">&quot; of &quot;</span><span class="Punctuation">,</span> <span class="Identifier">total</span><span class="Punctuation">)</span>
  334. <span class="Identifier">echo</span><span class="Punctuation">(</span><span class="StringLit">&quot;Current rate: &quot;</span><span class="Punctuation">,</span> <span class="Identifier">speed</span> <span class="Keyword">div</span> <span class="DecNumber">1000</span><span class="Punctuation">,</span> <span class="StringLit">&quot;kb/s&quot;</span><span class="Punctuation">)</span>
  335. <span class="Keyword">proc</span> <span class="Identifier">asyncProc</span><span class="Punctuation">(</span><span class="Punctuation">)</span> <span class="Punctuation">{</span><span class="Operator">.</span><span class="Identifier">async</span><span class="Operator">.</span><span class="Punctuation">}</span> <span class="Operator">=</span>
  336. <span class="Keyword">var</span> <span class="Identifier">client</span> <span class="Operator">=</span> <span class="Identifier">newAsyncHttpClient</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  337. <span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">onProgressChanged</span> <span class="Operator">=</span> <span class="Identifier">onProgressChanged</span>
  338. <span class="Keyword">try</span><span class="Punctuation">:</span>
  339. <span class="Keyword">discard</span> <span class="Identifier">await</span> <span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">getContent</span><span class="Punctuation">(</span><span class="StringLit">&quot;http://speedtest-ams2.digitalocean.com/100mb.test&quot;</span><span class="Punctuation">)</span>
  340. <span class="Keyword">finally</span><span class="Punctuation">:</span>
  341. <span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  342. <span class="Identifier">waitFor</span> <span class="Identifier">asyncProc</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre></p>
  343. <p>If you would like to remove the callback simply set it to <tt class="docutils literal"><span class="pre"><span class="Keyword">nil</span></span></tt>.</p>
  344. <p><pre class="listing"><span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">onProgressChanged</span> <span class="Operator">=</span> <span class="Keyword">nil</span></pre></p>
  345. <div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
  346. The <tt class="docutils literal"><span class="pre"><span class="Identifier">total</span></span></tt> reported by httpclient may be 0 in some cases.</div>
  347. <h1><a class="toc-backref" id="sslslashtls-support" href="#sslslashtls-support">SSL/TLS support</a></h1><p>This requires the OpenSSL library. Fortunately it's widely used and installed on many operating systems. httpclient will use SSL automatically if you give any of the functions a url with the <tt class="docutils literal"><span class="pre"><span class="Identifier">https</span></span></tt> schema, for example: <tt class="docutils literal"><span class="pre"><span class="Identifier">https</span><span class="Punctuation">:</span><span class="Operator">//</span><span class="Identifier">github</span><span class="Operator">.</span><span class="Identifier">com</span><span class="Operator">/</span></span></tt>.</p>
  348. <p>You will also have to compile with <tt class="docutils literal"><span class="pre"><span class="Identifier">ssl</span></span></tt> defined like so: <tt class="docutils literal"><span class="pre"><span class="Identifier">nim</span> <span class="Identifier">c</span> <span class="Operator">-</span><span class="Identifier">d</span><span class="Punctuation">:</span><span class="Identifier">ssl</span> <span class="Operator">...</span></span></tt>.</p>
  349. <p>Certificate validation is performed by default.</p>
  350. <p>A set of directories and files from the <a class="reference external" href="ssl_certs.html">ssl_certs</a> module are scanned to locate CA certificates.</p>
  351. <p>Example of setting SSL verification parameters in a new client:</p>
  352. <p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Punctuation">[</span><span class="Identifier">net</span><span class="Punctuation">,</span> <span class="Identifier">httpclient</span><span class="Punctuation">]</span>
  353. <span class="Keyword">var</span> <span class="Identifier">client</span> <span class="Operator">=</span> <span class="Identifier">newHttpClient</span><span class="Punctuation">(</span><span class="Identifier">sslContext</span><span class="Operator">=</span><span class="Identifier">newContext</span><span class="Punctuation">(</span><span class="Identifier">verifyMode</span><span class="Operator">=</span><span class="Identifier">CVerifyPeer</span><span class="Punctuation">)</span><span class="Punctuation">)</span></pre></p>
  354. <p>There are three options for verify mode:</p>
  355. <ul class="simple"><li><tt class="docutils literal"><span class="pre">CVerifyNone</span></tt>: certificates are not verified;</li>
  356. <li><tt class="docutils literal"><span class="pre">CVerifyPeer</span></tt>: certificates are verified;</li>
  357. <li><tt class="docutils literal"><span class="pre">CVerifyPeerUseEnvVars</span></tt>: certificates are verified and the optional environment variables SSL_CERT_FILE and SSL_CERT_DIR are also used to locate certificates</li>
  358. </ul>
  359. <p>See <a class="reference external" href="net.html#newContext.string,string,string,string">newContext</a> to tweak or disable certificate validation.</p>
  360. <h1><a class="toc-backref" id="timeouts" href="#timeouts">Timeouts</a></h1><p>Currently only the synchronous functions support a timeout. The timeout is measured in milliseconds, once it is set any call on a socket which may block will be susceptible to this timeout.</p>
  361. <p>It may be surprising but the function as a whole can take longer than the specified timeout, only individual internal calls on the socket are affected. In practice this means that as long as the server is sending data an exception will not be raised, if however data does not reach the client within the specified timeout a <tt class="docutils literal"><span class="pre"><span class="Identifier">TimeoutError</span></span></tt> exception will be raised.</p>
  362. <p>Here is how to set a timeout when creating an <tt class="docutils literal"><span class="pre"><span class="Identifier">HttpClient</span></span></tt> instance:</p>
  363. <p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">httpclient</span>
  364. <span class="Keyword">let</span> <span class="Identifier">client</span> <span class="Operator">=</span> <span class="Identifier">newHttpClient</span><span class="Punctuation">(</span><span class="Identifier">timeout</span> <span class="Operator">=</span> <span class="DecNumber">42</span><span class="Punctuation">)</span></pre></p>
  365. <h1><a class="toc-backref" id="proxy" href="#proxy">Proxy</a></h1><p>A proxy can be specified as a param to any of the procedures defined in this module. To do this, use the <tt class="docutils literal"><span class="pre"><span class="Identifier">newProxy</span></span></tt> constructor. Unfortunately, only basic authentication is supported at the moment.</p>
  366. <p>Some examples on how to configure a Proxy for <tt class="docutils literal"><span class="pre"><span class="Identifier">HttpClient</span></span></tt>:</p>
  367. <p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">httpclient</span>
  368. <span class="Keyword">let</span> <span class="Identifier">myProxy</span> <span class="Operator">=</span> <span class="Identifier">newProxy</span><span class="Punctuation">(</span><span class="StringLit">&quot;http://myproxy.network&quot;</span><span class="Punctuation">)</span>
  369. <span class="Keyword">let</span> <span class="Identifier">client</span> <span class="Operator">=</span> <span class="Identifier">newHttpClient</span><span class="Punctuation">(</span><span class="Identifier">proxy</span> <span class="Operator">=</span> <span class="Identifier">myProxy</span><span class="Punctuation">)</span></pre></p>
  370. <p>Use proxies with basic authentication:</p>
  371. <p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">httpclient</span>
  372. <span class="Keyword">let</span> <span class="Identifier">myProxy</span> <span class="Operator">=</span> <span class="Identifier">newProxy</span><span class="Punctuation">(</span><span class="StringLit">&quot;http://myproxy.network&quot;</span><span class="Punctuation">,</span> <span class="Identifier">auth</span><span class="Operator">=</span><span class="StringLit">&quot;user:password&quot;</span><span class="Punctuation">)</span>
  373. <span class="Keyword">let</span> <span class="Identifier">client</span> <span class="Operator">=</span> <span class="Identifier">newHttpClient</span><span class="Punctuation">(</span><span class="Identifier">proxy</span> <span class="Operator">=</span> <span class="Identifier">myProxy</span><span class="Punctuation">)</span></pre></p>
  374. <p>Get Proxy URL from environment variables:</p>
  375. <p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">httpclient</span>
  376. <span class="Keyword">var</span> <span class="Identifier">url</span> <span class="Operator">=</span> <span class="StringLit">&quot;&quot;</span>
  377. <span class="Keyword">try</span><span class="Punctuation">:</span>
  378. <span class="Keyword">if</span> <span class="Identifier">existsEnv</span><span class="Punctuation">(</span><span class="StringLit">&quot;http_proxy&quot;</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
  379. <span class="Identifier">url</span> <span class="Operator">=</span> <span class="Identifier">getEnv</span><span class="Punctuation">(</span><span class="StringLit">&quot;http_proxy&quot;</span><span class="Punctuation">)</span>
  380. <span class="Keyword">elif</span> <span class="Identifier">existsEnv</span><span class="Punctuation">(</span><span class="StringLit">&quot;https_proxy&quot;</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
  381. <span class="Identifier">url</span> <span class="Operator">=</span> <span class="Identifier">getEnv</span><span class="Punctuation">(</span><span class="StringLit">&quot;https_proxy&quot;</span><span class="Punctuation">)</span>
  382. <span class="Keyword">except</span> <span class="Identifier">ValueError</span><span class="Punctuation">:</span>
  383. <span class="Identifier">echo</span> <span class="StringLit">&quot;Unable to parse proxy from environment variables.&quot;</span>
  384. <span class="Keyword">let</span> <span class="Identifier">myProxy</span> <span class="Operator">=</span> <span class="Identifier">newProxy</span><span class="Punctuation">(</span><span class="Identifier">url</span> <span class="Operator">=</span> <span class="Identifier">url</span><span class="Punctuation">)</span>
  385. <span class="Keyword">let</span> <span class="Identifier">client</span> <span class="Operator">=</span> <span class="Identifier">newHttpClient</span><span class="Punctuation">(</span><span class="Identifier">proxy</span> <span class="Operator">=</span> <span class="Identifier">myProxy</span><span class="Punctuation">)</span></pre></p>
  386. <h1><a class="toc-backref" id="redirects" href="#redirects">Redirects</a></h1><p>The maximum redirects can be set with the <tt class="docutils literal"><span class="pre"><span class="Identifier">maxRedirects</span></span></tt> of <tt class="docutils literal"><span class="pre"><span class="Identifier">int</span></span></tt> type, it specifies the maximum amount of redirects to follow, it defaults to <tt class="docutils literal"><span class="pre"><span class="DecNumber">5</span></span></tt>, you can set it to <tt class="docutils literal"><span class="pre"><span class="DecNumber">0</span></span></tt> to disable redirects.</p>
  387. <p>Here you can see an example about how to set the <tt class="docutils literal"><span class="pre"><span class="Identifier">maxRedirects</span></span></tt> of <tt class="docutils literal"><span class="pre"><span class="Identifier">HttpClient</span></span></tt>:</p>
  388. <p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">httpclient</span>
  389. <span class="Keyword">let</span> <span class="Identifier">client</span> <span class="Operator">=</span> <span class="Identifier">newHttpClient</span><span class="Punctuation">(</span><span class="Identifier">maxRedirects</span> <span class="Operator">=</span> <span class="DecNumber">0</span><span class="Punctuation">)</span></pre></p>
  390. </p>
  391. <div class="section" id="6">
  392. <h1><a class="toc-backref" href="#6">Imports</a></h1>
  393. <dl class="item">
  394. <a class="reference external" href="since.html">since</a>, <a class="reference external" href="net.html">net</a>, <a class="reference external" href="strutils.html">strutils</a>, <a class="reference external" href="uri.html">uri</a>, <a class="reference external" href="parseutils.html">parseutils</a>, <a class="reference external" href="base64.html">base64</a>, <a class="reference external" href="os.html">os</a>, <a class="reference external" href="mimetypes.html">mimetypes</a>, <a class="reference external" href="math.html">math</a>, <a class="reference external" href="random.html">random</a>, <a class="reference external" href="httpcore.html">httpcore</a>, <a class="reference external" href="times.html">times</a>, <a class="reference external" href="tables.html">tables</a>, <a class="reference external" href="streams.html">streams</a>, <a class="reference external" href="monotimes.html">monotimes</a>, <a class="reference external" href="asyncnet.html">asyncnet</a>, <a class="reference external" href="asyncdispatch.html">asyncdispatch</a>, <a class="reference external" href="asyncfile.html">asyncfile</a>, <a class="reference external" href="nativesockets.html">nativesockets</a>, <a class="reference external" href="assertions.html">assertions</a>, <a class="reference external" href="syncio.html">syncio</a>
  395. </dl>
  396. </div>
  397. <div class="section" id="7">
  398. <h1><a class="toc-backref" href="#7">Types</a></h1>
  399. <dl class="item">
  400. <div id="AsyncHttpClient">
  401. <dt><pre><a href="httpclient.html#AsyncHttpClient"><span class="Identifier">AsyncHttpClient</span></a> <span class="Other">=</span> <a href="httpclient.html#HttpClientBase"><span class="Identifier">HttpClientBase</span></a><span class="Other">[</span><a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a><span class="Other">]</span></pre></dt>
  402. <dd>
  403. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L663" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  404. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L663" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  405. </dd>
  406. </div>
  407. <div id="AsyncResponse">
  408. <dt><pre><a href="httpclient.html#AsyncResponse"><span class="Identifier">AsyncResponse</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <span class="Keyword">object</span>
  409. <span class="Identifier">version</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a>
  410. <span class="Identifier">status</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a>
  411. <span class="Identifier">headers</span><span class="Operator">*</span><span class="Other">:</span> <a href="httpcore.html#HttpHeaders"><span class="Identifier">HttpHeaders</span></a>
  412. <span class="Identifier">bodyStream</span><span class="Operator">*</span><span class="Other">:</span> <a href="asyncstreams.html#FutureStream"><span class="Identifier">FutureStream</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span></pre></dt>
  413. <dd>
  414. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L282" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  415. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L282" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  416. </dd>
  417. </div>
  418. <div id="HttpClient">
  419. <dt><pre><a href="httpclient.html#HttpClient"><span class="Identifier">HttpClient</span></a> <span class="Other">=</span> <a href="httpclient.html#HttpClientBase"><span class="Identifier">HttpClientBase</span></a><span class="Other">[</span><a href="net.html#Socket"><span class="Identifier">Socket</span></a><span class="Other">]</span></pre></dt>
  420. <dd>
  421. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L620" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  422. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L620" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  423. </dd>
  424. </div>
  425. <div id="HttpClientBase">
  426. <dt><pre><a href="httpclient.html#HttpClientBase"><span class="Identifier">HttpClientBase</span></a><span class="Other">[</span><span class="Identifier">SocketType</span><span class="Other">]</span> <span class="Other">=</span> <span class="Keyword">ref</span> <span class="Keyword">object</span>
  427. <span class="Comment">## Where we are currently connected.</span>
  428. <span class="Identifier">headers</span><span class="Operator">*</span><span class="Other">:</span> <a href="httpcore.html#HttpHeaders"><span class="Identifier">HttpHeaders</span></a> <span class="Comment">## Headers to send in requests.</span>
  429. <span class="Comment">## Maximum redirects, set to `0` to disable.</span>
  430. <span class="Identifier">timeout</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> <span class="Comment">## Only used for blocking HttpClient for now.</span>
  431. <span class="Comment">## `nil` or the callback to call when request progress changes.</span>
  432. <span class="Keyword">when</span> <span class="Identifier">SocketType</span> <span class="Keyword">is</span> <span class="Identifier">Socket</span><span class="Other">:</span>
  433. <span class="Identifier">onProgressChanged</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">ProgressChangedProc</span><span class="Other">[</span><span class="Identifier">void</span><span class="Other">]</span>
  434. <span class="Keyword">else</span><span class="Other">:</span>
  435. <span class="Identifier">onProgressChanged</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">ProgressChangedProc</span><span class="Other">[</span><span class="Identifier">Future</span><span class="Other">[</span><span class="Identifier">void</span><span class="Other">]</span><span class="Other">]</span>
  436. <span class="Keyword">when</span> <span class="Identifier">defined</span><span class="Other">(</span><span class="Identifier">ssl</span><span class="Other">)</span><span class="Other">:</span>
  437. <span class="Keyword">when</span> <span class="Identifier">SocketType</span> <span class="Keyword">is</span> <span class="Identifier">AsyncSocket</span><span class="Other">:</span>
  438. <span class="Keyword">else</span><span class="Other">:</span>
  439. <span class="Comment">## When `false`, the body is never read in requestAux.</span></pre></dt>
  440. <dd>
  441. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L592" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  442. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L592" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  443. </dd>
  444. </div>
  445. <div id="HttpRequestError">
  446. <dt><pre><a href="httpclient.html#HttpRequestError"><span class="Identifier">HttpRequestError</span></a> <span class="Other">=</span> <span class="Keyword">object</span> <span class="Keyword">of</span> <a href="exceptions.html#IOError"><span class="Identifier">IOError</span></a></pre></dt>
  447. <dd>
  448. Thrown in the <tt class="docutils literal"><span class="pre"><span class="Identifier">getContent</span></span></tt> proc and <tt class="docutils literal"><span class="pre"><span class="Identifier">postContent</span></span></tt> proc, when the server returns an error
  449. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L360" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  450. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L360" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  451. </dd>
  452. </div>
  453. <div id="MultipartData">
  454. <dt><pre><a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <span class="Keyword">object</span></pre></dt>
  455. <dd>
  456. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L353" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  457. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L353" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  458. </dd>
  459. </div>
  460. <div id="MultipartEntries">
  461. <dt><pre><a href="httpclient.html#MultipartEntries"><span class="Identifier">MultipartEntries</span></a> <span class="Other">=</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">name</span><span class="Other">,</span> <span class="Identifier">content</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span><span class="Other">]</span></pre></dt>
  462. <dd>
  463. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L352" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  464. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L352" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  465. </dd>
  466. </div>
  467. <div id="ProgressChangedProc">
  468. <dt><pre><a href="httpclient.html#ProgressChangedProc"><span class="Identifier">ProgressChangedProc</span></a><span class="Other">[</span><span class="Identifier">ReturnType</span><span class="Other">]</span> <span class="Other">=</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">total</span><span class="Other">,</span> <span class="Identifier">progress</span><span class="Other">,</span> <span class="Identifier">speed</span><span class="Other">:</span> <a href="ctypes.html#BiggestInt"><span class="Identifier">BiggestInt</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">ReturnType</span> {.
  469. <span class="Identifier">closure</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span></span>.}</pre></dt>
  470. <dd>
  471. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L588" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  472. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L588" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  473. </dd>
  474. </div>
  475. <div id="ProtocolError">
  476. <dt><pre><a href="httpclient.html#ProtocolError"><span class="Identifier">ProtocolError</span></a> <span class="Other">=</span> <span class="Keyword">object</span> <span class="Keyword">of</span> <a href="exceptions.html#IOError"><span class="Identifier">IOError</span></a></pre></dt>
  477. <dd>
  478. exception that is raised when server does not conform to the implemented protocol
  479. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L356" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  480. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L356" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  481. </dd>
  482. </div>
  483. <div id="Proxy">
  484. <dt><pre><a href="httpclient.html#Proxy"><span class="Identifier">Proxy</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <span class="Keyword">object</span>
  485. <span class="Identifier">url</span><span class="Operator">*</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a>
  486. <span class="Identifier">auth</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
  487. <dd>
  488. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L339" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  489. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L339" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  490. </dd>
  491. </div>
  492. <div id="Response">
  493. <dt><pre><a href="httpclient.html#Response"><span class="Identifier">Response</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <span class="Keyword">object</span>
  494. <span class="Identifier">version</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a>
  495. <span class="Identifier">status</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a>
  496. <span class="Identifier">headers</span><span class="Operator">*</span><span class="Other">:</span> <a href="httpcore.html#HttpHeaders"><span class="Identifier">HttpHeaders</span></a>
  497. <span class="Identifier">bodyStream</span><span class="Operator">*</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a></pre></dt>
  498. <dd>
  499. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L275" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  500. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L275" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  501. </dd>
  502. </div>
  503. </dl>
  504. </div>
  505. <div class="section" id="10">
  506. <h1><a class="toc-backref" href="#10">Consts</a></h1>
  507. <dl class="item">
  508. <div id="defUserAgent">
  509. <dt><pre><a href="httpclient.html#defUserAgent"><span class="Identifier">defUserAgent</span></a> <span class="Other">=</span> <span class="StringLit">&quot;Nim-httpclient/2.3.1&quot;</span></pre></dt>
  510. <dd>
  511. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L364" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  512. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L364" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  513. </dd>
  514. </div>
  515. </dl>
  516. </div>
  517. <div class="section" id="12">
  518. <h1><a class="toc-backref" href="#12">Procs</a></h1>
  519. <dl class="item">
  520. <div id="$-procs-all">
  521. <div id="$,MultipartData">
  522. <dt><pre><span class="Keyword">proc</span> <a href="#%24%2CMultipartData"><span class="Identifier">`$`</span></a><span class="Other">(</span><span class="Identifier">data</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  523. <dd>
  524. convert MultipartData to string so it's human readable when echo see <a class="reference external" href="https://github.com/nim-lang/Nim/issues/11863">https://github.com/nim-lang/Nim/issues/11863</a>
  525. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L402" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  526. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L402" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  527. </dd>
  528. </div>
  529. </div>
  530. <div id="[]=-procs-all">
  531. <div id="[]=,MultipartData,string,string">
  532. <dt><pre><span class="Keyword">proc</span> <a href="#%5B%5D%3D%2CMultipartData%2Cstring%2Cstring"><span class="Identifier">`[]=`</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a><span class="Other">;</span> <span class="Identifier">name</span><span class="Other">,</span> <span class="Identifier">content</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span> {.<span class="Identifier">inline</span><span class="Other">,</span>
  533. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  534. <dd>
  535. <p>Add a multipart entry to the multipart data <tt class="docutils literal"><span class="pre"><span class="Identifier">p</span></span></tt>. The value is added without a filename and without a content type.</p>
  536. <p><pre class="listing"><span class="Identifier">data</span><span class="Punctuation">[</span><span class="StringLit">&quot;username&quot;</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="StringLit">&quot;NimUser&quot;</span></pre></p>
  537. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L488" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  538. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L488" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  539. </dd>
  540. </div>
  541. <div id="[]=,MultipartData,string,tuple[string,string,string]">
  542. <dt><pre><span class="Keyword">proc</span> <a href="#%5B%5D%3D%2CMultipartData%2Cstring%2Ctuple%5Bstring%2Cstring%2Cstring%5D"><span class="Identifier">`[]=`</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a><span class="Other">;</span> <span class="Identifier">name</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span>
  543. <span class="Identifier">file</span><span class="Other">:</span> <span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">name</span><span class="Other">,</span> <span class="Identifier">contentType</span><span class="Other">,</span> <span class="Identifier">content</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span><span class="Other">)</span> {.<span class="Identifier">inline</span><span class="Other">,</span>
  544. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  545. <dd>
  546. <p>Add a file to the multipart data <tt class="docutils literal"><span class="pre"><span class="Identifier">p</span></span></tt>, specifying filename, contentType and content manually.</p>
  547. <p><pre class="listing"><span class="Identifier">data</span><span class="Punctuation">[</span><span class="StringLit">&quot;uploaded_file&quot;</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="Punctuation">(</span><span class="StringLit">&quot;test.html&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;text/html&quot;</span><span class="Punctuation">,</span>
  548. <span class="StringLit">&quot;&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;test&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;&quot;</span><span class="Punctuation">)</span></pre></p>
  549. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L497" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  550. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L497" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  551. </dd>
  552. </div>
  553. </div>
  554. <div id="add-procs-all">
  555. <div id="add,MultipartData,string,string,string,string">
  556. <dt><pre><span class="Keyword">proc</span> <a href="#add%2CMultipartData%2Cstring%2Cstring%2Cstring%2Cstring"><span class="Identifier">add</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a><span class="Other">;</span> <span class="Identifier">name</span><span class="Other">,</span> <span class="Identifier">content</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">filename</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
  557. <span class="Identifier">contentType</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span> <span class="Identifier">useStream</span> <span class="Other">=</span> <span class="Identifier">true</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span>
  558. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  559. <dd>
  560. <p>Add a value to the multipart data.</p>
  561. <p>When <tt class="docutils literal"><span class="pre"><span class="Identifier">useStream</span></span></tt> is <tt class="docutils literal"><span class="pre"><span class="Identifier">false</span></span></tt>, the file will be read into memory.</p>
  562. <p>Raises a <tt class="docutils literal"><span class="pre"><span class="Identifier">ValueError</span></span></tt> exception if <tt class="docutils literal"><span class="pre"><span class="Identifier">name</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">filename</span></span></tt> or <tt class="docutils literal"><span class="pre"><span class="Identifier">contentType</span></span></tt> contain newline characters.</p>
  563. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L415" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  564. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L415" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  565. </dd>
  566. </div>
  567. <div id="add,MultipartData,MultipartEntries">
  568. <dt><pre><span class="Keyword">proc</span> <a href="#add%2CMultipartData%2CMultipartEntries"><span class="Identifier">add</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a><span class="Other">;</span> <span class="Identifier">xs</span><span class="Other">:</span> <a href="httpclient.html#MultipartEntries"><span class="Identifier">MultipartEntries</span></a><span class="Other">)</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a> {.<span class="Identifier">discardable</span><span class="Other">,</span>
  569. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  570. <dd>
  571. <p>Add a list of multipart entries to the multipart data <tt class="docutils literal"><span class="pre"><span class="Identifier">p</span></span></tt>. All values are added without a filename and without a content type.</p>
  572. <p><pre class="listing"><span class="Identifier">data</span><span class="Operator">.</span><span class="Identifier">add</span><span class="Punctuation">(</span><span class="Punctuation">{</span><span class="StringLit">&quot;action&quot;</span><span class="Punctuation">:</span> <span class="StringLit">&quot;login&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;format&quot;</span><span class="Punctuation">:</span> <span class="StringLit">&quot;json&quot;</span><span class="Punctuation">}</span><span class="Punctuation">)</span></pre></p>
  573. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L443" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  574. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L443" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  575. </dd>
  576. </div>
  577. </div>
  578. <div id="addFiles-procs-all">
  579. <div id="addFiles,MultipartData,openArray[tuple[string,string]]">
  580. <dt><pre><span class="Keyword">proc</span> <a href="#addFiles%2CMultipartData%2CopenArray%5Btuple%5Bstring%2Cstring%5D%5D"><span class="Identifier">addFiles</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a><span class="Other">;</span> <span class="Identifier">xs</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</span></a><span class="Other">[</span><span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">name</span><span class="Other">,</span> <span class="Identifier">file</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span><span class="Other">]</span><span class="Other">;</span>
  581. <span class="Identifier">mimeDb</span> <span class="Other">=</span> <span class="Identifier">newMimetypes</span><span class="Other">(</span><span class="Other">)</span><span class="Other">;</span> <span class="Identifier">useStream</span> <span class="Other">=</span> <span class="Identifier">true</span><span class="Other">)</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a> {.
  582. <span class="Identifier">discardable</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ReadIOEffect</span><span class="Other">]</span><span class="Other">,</span>
  583. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  584. <dd>
  585. <p>Add files to a multipart data object. The files will be streamed from disk when the request is being made. When <tt class="docutils literal"><span class="pre"><span class="Identifier">stream</span></span></tt> is <tt class="docutils literal"><span class="pre"><span class="Identifier">false</span></span></tt>, the files are instead read into memory, but beware this is very memory ineffecient even for small files. The MIME types will automatically be determined. Raises an <tt class="docutils literal"><span class="pre"><span class="Identifier">IOError</span></span></tt> if the file cannot be opened or reading fails. To manually specify file content, filename and MIME type, use <tt class="docutils literal"><span class="pre"><span class="Punctuation">[</span><span class="Punctuation">]</span><span class="Operator">=</span></span></tt> instead.</p>
  586. <p><pre class="listing"><span class="Identifier">data</span><span class="Operator">.</span><span class="Identifier">addFiles</span><span class="Punctuation">(</span><span class="Punctuation">{</span><span class="StringLit">&quot;uploaded_file&quot;</span><span class="Punctuation">:</span> <span class="StringLit">&quot;public/test.html&quot;</span><span class="Punctuation">}</span><span class="Punctuation">)</span></pre></p>
  587. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L466" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  588. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L466" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  589. </dd>
  590. </div>
  591. </div>
  592. <div id="body-procs-all">
  593. <div id="body,AsyncResponse">
  594. <dt><pre><span class="Keyword">proc</span> <a href="#body%2CAsyncResponse"><span class="Identifier">body</span></a><span class="Other">(</span><span class="Identifier">response</span><span class="Other">:</span> <a href="httpclient.html#AsyncResponse"><span class="Identifier">AsyncResponse</span></a><span class="Other">)</span><span class="Other">:</span> <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span><span class="Other">,</span>
  595. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  596. <dd>
  597. Reads the response's body and caches it. The read is performed only once.
  598. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L331" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  599. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L331" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  600. </dd>
  601. </div>
  602. <div id="body,Response">
  603. <dt><pre><span class="Keyword">proc</span> <a href="#body%2CResponse"><span class="Identifier">body</span></a><span class="Other">(</span><span class="Identifier">response</span><span class="Other">:</span> <a href="httpclient.html#Response"><span class="Identifier">Response</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  604. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ReadIOEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  605. <dd>
  606. <p>Retrieves the specified response's body.</p>
  607. <p>The response's body stream is read synchronously.</p>
  608. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L323" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  609. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L323" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  610. </dd>
  611. </div>
  612. </div>
  613. <div id="close-procs-all">
  614. <div id="close">
  615. <dt><pre><span class="Keyword">proc</span> <a href="#close"><span class="Identifier">close</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#HttpClient"><span class="Identifier">HttpClient</span></a> <span class="Operator">|</span> <a href="httpclient.html#AsyncHttpClient"><span class="Identifier">AsyncHttpClient</span></a><span class="Other">)</span></pre></dt>
  616. <dd>
  617. Closes any connections held by the HTTP client.
  618. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L705" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  619. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L705" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  620. </dd>
  621. </div>
  622. </div>
  623. <div id="code-procs-all">
  624. <div id="code">
  625. <dt><pre><span class="Keyword">proc</span> <a href="#code"><span class="Identifier">code</span></a><span class="Other">(</span><span class="Identifier">response</span><span class="Other">:</span> <a href="httpclient.html#Response"><span class="Identifier">Response</span></a> <span class="Operator">|</span> <a href="httpclient.html#AsyncResponse"><span class="Identifier">AsyncResponse</span></a><span class="Other">)</span><span class="Other">:</span> <a href="httpcore.html#HttpCode"><span class="Identifier">HttpCode</span></a> {.
  626. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><a href="exceptions.html#ValueError"><span class="Identifier">ValueError</span></a><span class="Other">,</span> <a href="exceptions.html#OverflowDefect"><span class="Identifier">OverflowDefect</span></a><span class="Other">]</span></span>.}</pre></dt>
  627. <dd>
  628. <p>Retrieves the specified response's <tt class="docutils literal"><span class="pre"><span class="Identifier">HttpCode</span></span></tt>.</p>
  629. <p>Raises a <tt class="docutils literal"><span class="pre"><span class="Identifier">ValueError</span></span></tt> if the response's <tt class="docutils literal"><span class="pre"><span class="Identifier">status</span></span></tt> does not have a corresponding <tt class="docutils literal"><span class="pre"><span class="Identifier">HttpCode</span></span></tt>.</p>
  630. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L289" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  631. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L289" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  632. </dd>
  633. </div>
  634. </div>
  635. <div id="contentLength-procs-all">
  636. <div id="contentLength">
  637. <dt><pre><span class="Keyword">proc</span> <a href="#contentLength"><span class="Identifier">contentLength</span></a><span class="Other">(</span><span class="Identifier">response</span><span class="Other">:</span> <a href="httpclient.html#Response"><span class="Identifier">Response</span></a> <span class="Operator">|</span> <a href="httpclient.html#AsyncResponse"><span class="Identifier">AsyncResponse</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a></pre></dt>
  638. <dd>
  639. <p>Retrieves the specified response's content length.</p>
  640. <p>This is effectively the value of the &quot;Content-Length&quot; header.</p>
  641. <p>A <tt class="docutils literal"><span class="pre"><span class="Identifier">ValueError</span></span></tt> exception will be raised if the value is not an integer. If the Content-Length header is not set in the response, ContentLength is set to the value -1.</p>
  642. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L303" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  643. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L303" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  644. </dd>
  645. </div>
  646. </div>
  647. <div id="contentType-procs-all">
  648. <div id="contentType">
  649. <dt><pre><span class="Keyword">proc</span> <a href="#contentType"><span class="Identifier">contentType</span></a><span class="Other">(</span><span class="Identifier">response</span><span class="Other">:</span> <a href="httpclient.html#Response"><span class="Identifier">Response</span></a> <span class="Operator">|</span> <a href="httpclient.html#AsyncResponse"><span class="Identifier">AsyncResponse</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span class="Identifier">inline</span>.}</pre></dt>
  650. <dd>
  651. <p>Retrieves the specified response's content type.</p>
  652. <p>This is effectively the value of the &quot;Content-Type&quot; header.</p>
  653. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L297" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  654. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L297" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  655. </dd>
  656. </div>
  657. </div>
  658. <div id="delete-procs-all">
  659. <div id="delete,AsyncHttpClient,">
  660. <dt><pre><span class="Keyword">proc</span> <a href="#delete%2CAsyncHttpClient%2C"><span class="Identifier">delete</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#AsyncHttpClient"><span class="Identifier">AsyncHttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="httpclient.html#AsyncResponse"><span class="Identifier">AsyncResponse</span></a><span class="Other">]</span> {.
  661. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span></span>.}</pre></dt>
  662. <dd>
  663. Connects to the hostname specified by the URL and performs a DELETE request. This procedure uses httpClient values such as <tt class="docutils literal"><span class="pre"><span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">maxRedirects</span></span></tt>.
  664. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1263" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  665. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1263" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  666. </dd>
  667. </div>
  668. <div id="delete,HttpClient,">
  669. <dt><pre><span class="Keyword">proc</span> <a href="#delete%2CHttpClient%2C"><span class="Identifier">delete</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#HttpClient"><span class="Identifier">HttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="httpclient.html#Response"><span class="Identifier">Response</span></a></pre></dt>
  670. <dd>
  671. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1264" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  672. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1264" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  673. </dd>
  674. </div>
  675. </div>
  676. <div id="deleteContent-procs-all">
  677. <div id="deleteContent,AsyncHttpClient,">
  678. <dt><pre><span class="Keyword">proc</span> <a href="#deleteContent%2CAsyncHttpClient%2C"><span class="Identifier">deleteContent</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#AsyncHttpClient"><span class="Identifier">AsyncHttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span> {.
  679. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span></span>.}</pre></dt>
  680. <dd>
  681. Connects to the hostname specified by the URL and returns the content of a DELETE request.
  682. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1269" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  683. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1269" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  684. </dd>
  685. </div>
  686. <div id="deleteContent,HttpClient,">
  687. <dt><pre><span class="Keyword">proc</span> <a href="#deleteContent%2CHttpClient%2C"><span class="Identifier">deleteContent</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#HttpClient"><span class="Identifier">HttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
  688. <dd>
  689. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1270" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  690. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1270" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  691. </dd>
  692. </div>
  693. </div>
  694. <div id="downloadFile-procs-all">
  695. <div id="downloadFile,AsyncHttpClient,,string">
  696. <dt><pre><span class="Keyword">proc</span> <a href="#downloadFile%2CAsyncHttpClient%2C%2Cstring"><span class="Identifier">downloadFile</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#AsyncHttpClient"><span class="Identifier">AsyncHttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">filename</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span>
  697. <a href="system.html#void"><span class="Identifier">void</span></a><span class="Other">]</span></pre></dt>
  698. <dd>
  699. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1354" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  700. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1354" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  701. </dd>
  702. </div>
  703. <div id="downloadFile,HttpClient,,string">
  704. <dt><pre><span class="Keyword">proc</span> <a href="#downloadFile%2CHttpClient%2C%2Cstring"><span class="Identifier">downloadFile</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#HttpClient"><span class="Identifier">HttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">filename</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span></pre></dt>
  705. <dd>
  706. Downloads <tt class="docutils literal"><span class="pre"><span class="Identifier">url</span></span></tt> and saves it to <tt class="docutils literal"><span class="pre"><span class="Identifier">filename</span></span></tt>.
  707. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1316" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  708. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1316" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  709. </dd>
  710. </div>
  711. </div>
  712. <div id="get-procs-all">
  713. <div id="get,AsyncHttpClient,">
  714. <dt><pre><span class="Keyword">proc</span> <a href="#get%2CAsyncHttpClient%2C"><span class="Identifier">get</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#AsyncHttpClient"><span class="Identifier">AsyncHttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="httpclient.html#AsyncResponse"><span class="Identifier">AsyncResponse</span></a><span class="Other">]</span> {.
  715. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span></span>.}</pre></dt>
  716. <dd>
  717. <p>Connects to the hostname specified by the URL and performs a GET request.</p>
  718. <p>This procedure uses httpClient values such as <tt class="docutils literal"><span class="pre"><span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">maxRedirects</span></span></tt>.</p>
  719. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1250" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  720. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1250" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  721. </dd>
  722. </div>
  723. <div id="get,HttpClient,">
  724. <dt><pre><span class="Keyword">proc</span> <a href="#get%2CHttpClient%2C"><span class="Identifier">get</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#HttpClient"><span class="Identifier">HttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="httpclient.html#Response"><span class="Identifier">Response</span></a></pre></dt>
  725. <dd>
  726. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1251" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  727. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1251" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  728. </dd>
  729. </div>
  730. </div>
  731. <div id="getContent-procs-all">
  732. <div id="getContent,AsyncHttpClient,">
  733. <dt><pre><span class="Keyword">proc</span> <a href="#getContent%2CAsyncHttpClient%2C"><span class="Identifier">getContent</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#AsyncHttpClient"><span class="Identifier">AsyncHttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span> {.
  734. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span></span>.}</pre></dt>
  735. <dd>
  736. Connects to the hostname specified by the URL and returns the content of a GET request.
  737. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1257" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  738. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1257" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  739. </dd>
  740. </div>
  741. <div id="getContent,HttpClient,">
  742. <dt><pre><span class="Keyword">proc</span> <a href="#getContent%2CHttpClient%2C"><span class="Identifier">getContent</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#HttpClient"><span class="Identifier">HttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
  743. <dd>
  744. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1258" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  745. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1258" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  746. </dd>
  747. </div>
  748. </div>
  749. <div id="getSocket-procs-all">
  750. <div id="getSocket,AsyncHttpClient">
  751. <dt><pre><span class="Keyword">proc</span> <a href="#getSocket%2CAsyncHttpClient"><span class="Identifier">getSocket</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#AsyncHttpClient"><span class="Identifier">AsyncHttpClient</span></a><span class="Other">)</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  752. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  753. <dd>
  754. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L723" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  755. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L723" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  756. </dd>
  757. </div>
  758. <div id="getSocket,HttpClient">
  759. <dt><pre><span class="Keyword">proc</span> <a href="#getSocket%2CHttpClient"><span class="Identifier">getSocket</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#HttpClient"><span class="Identifier">HttpClient</span></a><span class="Other">)</span><span class="Other">:</span> <a href="net.html#Socket"><span class="Identifier">Socket</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  760. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  761. <dd>
  762. <p>Get network socket, useful if you want to find out more details about the connection.</p>
  763. <p>This example shows info about local and remote endpoints:</p>
  764. <p><pre class="listing"><span class="Keyword">if</span> <span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">connected</span><span class="Punctuation">:</span>
  765. <span class="Identifier">echo</span> <span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">getSocket</span><span class="Operator">.</span><span class="Identifier">getLocalAddr</span>
  766. <span class="Identifier">echo</span> <span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">getSocket</span><span class="Operator">.</span><span class="Identifier">getPeerAddr</span></pre></p>
  767. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L711" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  768. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L711" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  769. </dd>
  770. </div>
  771. </div>
  772. <div id="head-procs-all">
  773. <div id="head,AsyncHttpClient,">
  774. <dt><pre><span class="Keyword">proc</span> <a href="#head%2CAsyncHttpClient%2C"><span class="Identifier">head</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#AsyncHttpClient"><span class="Identifier">AsyncHttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="httpclient.html#AsyncResponse"><span class="Identifier">AsyncResponse</span></a><span class="Other">]</span> {.
  775. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span></span>.}</pre></dt>
  776. <dd>
  777. <p>Connects to the hostname specified by the URL and performs a HEAD request.</p>
  778. <p>This procedure uses httpClient values such as <tt class="docutils literal"><span class="pre"><span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">maxRedirects</span></span></tt>.</p>
  779. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1243" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  780. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1243" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  781. </dd>
  782. </div>
  783. <div id="head,HttpClient,">
  784. <dt><pre><span class="Keyword">proc</span> <a href="#head%2CHttpClient%2C"><span class="Identifier">head</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#HttpClient"><span class="Identifier">HttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="httpclient.html#Response"><span class="Identifier">Response</span></a></pre></dt>
  785. <dd>
  786. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1244" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  787. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1244" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  788. </dd>
  789. </div>
  790. </div>
  791. <div id="lastModified-procs-all">
  792. <div id="lastModified">
  793. <dt><pre><span class="Keyword">proc</span> <a href="#lastModified"><span class="Identifier">lastModified</span></a><span class="Other">(</span><span class="Identifier">response</span><span class="Other">:</span> <a href="httpclient.html#Response"><span class="Identifier">Response</span></a> <span class="Operator">|</span> <a href="httpclient.html#AsyncResponse"><span class="Identifier">AsyncResponse</span></a><span class="Other">)</span><span class="Other">:</span> <a href="times.html#DateTime"><span class="Identifier">DateTime</span></a></pre></dt>
  794. <dd>
  795. <p>Retrieves the specified response's last modified time.</p>
  796. <p>This is effectively the value of the &quot;Last-Modified&quot; header.</p>
  797. <p>Raises a <tt class="docutils literal"><span class="pre"><span class="Identifier">ValueError</span></span></tt> if the parsing fails or the value is not a correctly formatted time.</p>
  798. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L313" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  799. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L313" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  800. </dd>
  801. </div>
  802. </div>
  803. <div id="newAsyncHttpClient-procs-all">
  804. <div id="newAsyncHttpClient,int,Proxy">
  805. <dt><pre><span class="Keyword">proc</span> <a href="#newAsyncHttpClient%2Cint%2CProxy"><span class="Identifier">newAsyncHttpClient</span></a><span class="Other">(</span><span class="Identifier">userAgent</span> <span class="Other">=</span> <span class="Identifier">defUserAgent</span><span class="Other">;</span> <span class="Identifier">maxRedirects</span> <span class="Other">=</span> <span class="DecNumber">5</span><span class="Other">;</span>
  806. <span class="Identifier">sslContext</span> <span class="Other">=</span> <span class="Identifier">getDefaultSSL</span><span class="Other">(</span><span class="Other">)</span><span class="Other">;</span> <span class="Identifier">proxy</span><span class="Other">:</span> <a href="httpclient.html#Proxy"><span class="Identifier">Proxy</span></a> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">;</span>
  807. <span class="Identifier">headers</span> <span class="Other">=</span> <span class="Identifier">newHttpHeaders</span><span class="Other">(</span><span class="Other">)</span><span class="Other">)</span><span class="Other">:</span> <a href="httpclient.html#AsyncHttpClient"><span class="Identifier">AsyncHttpClient</span></a> {.
  808. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  809. <dd>
  810. <p>Creates a new AsyncHttpClient instance.</p>
  811. <p><tt class="docutils literal"><span class="pre"><span class="Identifier">userAgent</span></span></tt> specifies the user agent that will be used when making requests.</p>
  812. <p><tt class="docutils literal"><span class="pre"><span class="Identifier">maxRedirects</span></span></tt> specifies the maximum amount of redirects to follow, default is 5.</p>
  813. <p><tt class="docutils literal"><span class="pre"><span class="Identifier">sslContext</span></span></tt> specifies the SSL context to use for HTTPS requests.</p>
  814. <p><tt class="docutils literal"><span class="pre"><span class="Identifier">proxy</span></span></tt> specifies an HTTP proxy to use for this HTTP client's connections.</p>
  815. <p><tt class="docutils literal"><span class="pre"><span class="Identifier">headers</span></span></tt> specifies the HTTP Headers.</p>
  816. <p><strong class="examples_text">Example:</strong></p>
  817. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Punctuation">[</span><span class="Identifier">asyncdispatch</span><span class="Punctuation">,</span> <span class="Identifier">strutils</span><span class="Punctuation">]</span>
  818. <span class="Keyword">proc</span> <span class="Identifier">asyncProc</span><span class="Punctuation">(</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Identifier">Future</span><span class="Punctuation">[</span><span class="Identifier">string</span><span class="Punctuation">]</span> <span class="Punctuation">{</span><span class="Operator">.</span><span class="Identifier">async</span><span class="Operator">.</span><span class="Punctuation">}</span> <span class="Operator">=</span>
  819. <span class="Keyword">let</span> <span class="Identifier">client</span> <span class="Operator">=</span> <span class="Identifier">newAsyncHttpClient</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  820. <span class="Identifier">result</span> <span class="Operator">=</span> <span class="Identifier">await</span> <span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">getContent</span><span class="Punctuation">(</span><span class="StringLit">&quot;http://example.com&quot;</span><span class="Punctuation">)</span>
  821. <span class="Keyword">let</span> <span class="Identifier">exampleHtml</span> <span class="Operator">=</span> <span class="Identifier">waitFor</span> <span class="Identifier">asyncProc</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  822. <span class="Identifier">assert</span> <span class="StringLit">&quot;Example Domain&quot;</span> <span class="Keyword">in</span> <span class="Identifier">exampleHtml</span>
  823. <span class="Identifier">assert</span> <span class="StringLit">&quot;Pizza&quot;</span> <span class="Keyword">notin</span> <span class="Identifier">exampleHtml</span></pre>
  824. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L665" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  825. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L665" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  826. </dd>
  827. </div>
  828. </div>
  829. <div id="newHttpClient-procs-all">
  830. <div id="newHttpClient,int,Proxy,int">
  831. <dt><pre><span class="Keyword">proc</span> <a href="#newHttpClient%2Cint%2CProxy%2Cint"><span class="Identifier">newHttpClient</span></a><span class="Other">(</span><span class="Identifier">userAgent</span> <span class="Other">=</span> <span class="Identifier">defUserAgent</span><span class="Other">;</span> <span class="Identifier">maxRedirects</span> <span class="Other">=</span> <span class="DecNumber">5</span><span class="Other">;</span>
  832. <span class="Identifier">sslContext</span> <span class="Other">=</span> <span class="Identifier">getDefaultSSL</span><span class="Other">(</span><span class="Other">)</span><span class="Other">;</span> <span class="Identifier">proxy</span><span class="Other">:</span> <a href="httpclient.html#Proxy"><span class="Identifier">Proxy</span></a> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">;</span>
  833. <span class="Identifier">timeout</span> <span class="Other">=</span> <span class="DecNumber">-1</span><span class="Other">;</span> <span class="Identifier">headers</span> <span class="Other">=</span> <span class="Identifier">newHttpHeaders</span><span class="Other">(</span><span class="Other">)</span><span class="Other">)</span><span class="Other">:</span> <a href="httpclient.html#HttpClient"><span class="Identifier">HttpClient</span></a> {.
  834. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  835. <dd>
  836. <p>Creates a new HttpClient instance.</p>
  837. <p><tt class="docutils literal"><span class="pre"><span class="Identifier">userAgent</span></span></tt> specifies the user agent that will be used when making requests.</p>
  838. <p><tt class="docutils literal"><span class="pre"><span class="Identifier">maxRedirects</span></span></tt> specifies the maximum amount of redirects to follow, default is 5.</p>
  839. <p><tt class="docutils literal"><span class="pre"><span class="Identifier">sslContext</span></span></tt> specifies the SSL context to use for HTTPS requests. See <a class="reference external" href="#sslslashtls-support">SSL/TLS support</a></p>
  840. <p><tt class="docutils literal"><span class="pre"><span class="Identifier">proxy</span></span></tt> specifies an HTTP proxy to use for this HTTP client's connections.</p>
  841. <p><tt class="docutils literal"><span class="pre"><span class="Identifier">timeout</span></span></tt> specifies the number of milliseconds to allow before a <tt class="docutils literal"><span class="pre"><span class="Identifier">TimeoutError</span></span></tt> is raised.</p>
  842. <p><tt class="docutils literal"><span class="pre"><span class="Identifier">headers</span></span></tt> specifies the HTTP Headers.</p>
  843. <p><strong class="examples_text">Example:</strong></p>
  844. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">strutils</span>
  845. <span class="Keyword">let</span> <span class="Identifier">exampleHtml</span> <span class="Operator">=</span> <span class="Identifier">newHttpClient</span><span class="Punctuation">(</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">getContent</span><span class="Punctuation">(</span><span class="StringLit">&quot;http://example.com&quot;</span><span class="Punctuation">)</span>
  846. <span class="Identifier">assert</span> <span class="StringLit">&quot;Example Domain&quot;</span> <span class="Keyword">in</span> <span class="Identifier">exampleHtml</span>
  847. <span class="Identifier">assert</span> <span class="StringLit">&quot;Pizza&quot;</span> <span class="Keyword">notin</span> <span class="Identifier">exampleHtml</span></pre>
  848. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L622" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  849. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L622" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  850. </dd>
  851. </div>
  852. </div>
  853. <div id="newMultipartData-procs-all">
  854. <div id="newMultipartData">
  855. <dt><pre><span class="Keyword">proc</span> <a href="#newMultipartData"><span class="Identifier">newMultipartData</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  856. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  857. <dd>
  858. Constructs a new <tt class="docutils literal"><span class="pre"><span class="Identifier">MultipartData</span></span></tt> object.
  859. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L398" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  860. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L398" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  861. </dd>
  862. </div>
  863. <div id="newMultipartData,MultipartEntries">
  864. <dt><pre><span class="Keyword">proc</span> <a href="#newMultipartData%2CMultipartEntries"><span class="Identifier">newMultipartData</span></a><span class="Other">(</span><span class="Identifier">xs</span><span class="Other">:</span> <a href="httpclient.html#MultipartEntries"><span class="Identifier">MultipartEntries</span></a><span class="Other">)</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a> {.
  865. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  866. <dd>
  867. <p>Create a new multipart data object and fill it with the entries <tt class="docutils literal"><span class="pre"><span class="Identifier">xs</span></span></tt> directly.</p>
  868. <p><pre class="listing"><span class="Keyword">var</span> <span class="Identifier">data</span> <span class="Operator">=</span> <span class="Identifier">newMultipartData</span><span class="Punctuation">(</span><span class="Punctuation">{</span><span class="StringLit">&quot;action&quot;</span><span class="Punctuation">:</span> <span class="StringLit">&quot;login&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;format&quot;</span><span class="Punctuation">:</span> <span class="StringLit">&quot;json&quot;</span><span class="Punctuation">}</span><span class="Punctuation">)</span></pre></p>
  869. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L455" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  870. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L455" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  871. </dd>
  872. </div>
  873. </div>
  874. <div id="newProxy-procs-all">
  875. <div id="newProxy,string,string">
  876. <dt><pre><span class="Keyword">proc</span> <a href="#newProxy%2Cstring%2Cstring"><span class="Identifier">newProxy</span></a><span class="Other">(</span><span class="Identifier">url</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">auth</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">)</span><span class="Other">:</span> <a href="httpclient.html#Proxy"><span class="Identifier">Proxy</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  877. <dd>
  878. Constructs a new <tt class="docutils literal"><span class="pre"><span class="Identifier">TProxy</span></span></tt> object.
  879. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L390" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  880. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L390" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  881. </dd>
  882. </div>
  883. <div id="newProxy,Uri,string">
  884. <dt><pre><span class="Keyword">proc</span> <a href="#newProxy%2CUri%2Cstring"><span class="Identifier">newProxy</span></a><span class="Other">(</span><span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a><span class="Other">;</span> <span class="Identifier">auth</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">)</span><span class="Other">:</span> <a href="httpclient.html#Proxy"><span class="Identifier">Proxy</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  885. <dd>
  886. Constructs a new <tt class="docutils literal"><span class="pre"><span class="Identifier">TProxy</span></span></tt> object.
  887. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L394" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  888. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L394" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  889. </dd>
  890. </div>
  891. </div>
  892. <div id="patch-procs-all">
  893. <div id="patch,AsyncHttpClient,,string,MultipartData">
  894. <dt><pre><span class="Keyword">proc</span> <a href="#patch%2CAsyncHttpClient%2C%2Cstring%2CMultipartData"><span class="Identifier">patch</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#AsyncHttpClient"><span class="Identifier">AsyncHttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">body</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
  895. <span class="Identifier">multipart</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">)</span><span class="Other">:</span> <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="httpclient.html#AsyncResponse"><span class="Identifier">AsyncResponse</span></a><span class="Other">]</span> {.
  896. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span></span>.}</pre></dt>
  897. <dd>
  898. Connects to the hostname specified by the URL and performs a PATCH request. This procedure uses httpClient values such as <tt class="docutils literal"><span class="pre"><span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">maxRedirects</span></span></tt>.
  899. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1302" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  900. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1302" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  901. </dd>
  902. </div>
  903. <div id="patch,HttpClient,,string,MultipartData">
  904. <dt><pre><span class="Keyword">proc</span> <a href="#patch%2CHttpClient%2C%2Cstring%2CMultipartData"><span class="Identifier">patch</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#HttpClient"><span class="Identifier">HttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">body</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
  905. <span class="Identifier">multipart</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">)</span><span class="Other">:</span> <a href="httpclient.html#Response"><span class="Identifier">Response</span></a></pre></dt>
  906. <dd>
  907. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1304" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  908. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1304" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  909. </dd>
  910. </div>
  911. </div>
  912. <div id="patchContent-procs-all">
  913. <div id="patchContent,AsyncHttpClient,,string,MultipartData">
  914. <dt><pre><span class="Keyword">proc</span> <a href="#patchContent%2CAsyncHttpClient%2C%2Cstring%2CMultipartData"><span class="Identifier">patchContent</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#AsyncHttpClient"><span class="Identifier">AsyncHttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">body</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
  915. <span class="Identifier">multipart</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">)</span><span class="Other">:</span> <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span> {.
  916. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span></span>.}</pre></dt>
  917. <dd>
  918. Connects to the hostname specified by the URL and returns the content of a PATCH request.
  919. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1309" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  920. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1309" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  921. </dd>
  922. </div>
  923. <div id="patchContent,HttpClient,,string,MultipartData">
  924. <dt><pre><span class="Keyword">proc</span> <a href="#patchContent%2CHttpClient%2C%2Cstring%2CMultipartData"><span class="Identifier">patchContent</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#HttpClient"><span class="Identifier">HttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">body</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
  925. <span class="Identifier">multipart</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
  926. <dd>
  927. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1311" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  928. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1311" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  929. </dd>
  930. </div>
  931. </div>
  932. <div id="post-procs-all">
  933. <div id="post,AsyncHttpClient,,string,MultipartData">
  934. <dt><pre><span class="Keyword">proc</span> <a href="#post%2CAsyncHttpClient%2C%2Cstring%2CMultipartData"><span class="Identifier">post</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#AsyncHttpClient"><span class="Identifier">AsyncHttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">body</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
  935. <span class="Identifier">multipart</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">)</span><span class="Other">:</span> <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="httpclient.html#AsyncResponse"><span class="Identifier">AsyncResponse</span></a><span class="Other">]</span> {.
  936. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span></span>.}</pre></dt>
  937. <dd>
  938. Connects to the hostname specified by the URL and performs a POST request. This procedure uses httpClient values such as <tt class="docutils literal"><span class="pre"><span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">maxRedirects</span></span></tt>.
  939. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1275" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  940. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1275" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  941. </dd>
  942. </div>
  943. <div id="post,HttpClient,,string,MultipartData">
  944. <dt><pre><span class="Keyword">proc</span> <a href="#post%2CHttpClient%2C%2Cstring%2CMultipartData"><span class="Identifier">post</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#HttpClient"><span class="Identifier">HttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">body</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
  945. <span class="Identifier">multipart</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">)</span><span class="Other">:</span> <a href="httpclient.html#Response"><span class="Identifier">Response</span></a></pre></dt>
  946. <dd>
  947. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1277" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  948. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1277" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  949. </dd>
  950. </div>
  951. </div>
  952. <div id="postContent-procs-all">
  953. <div id="postContent,AsyncHttpClient,,string,MultipartData">
  954. <dt><pre><span class="Keyword">proc</span> <a href="#postContent%2CAsyncHttpClient%2C%2Cstring%2CMultipartData"><span class="Identifier">postContent</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#AsyncHttpClient"><span class="Identifier">AsyncHttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">body</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
  955. <span class="Identifier">multipart</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">)</span><span class="Other">:</span> <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span> {.
  956. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span></span>.}</pre></dt>
  957. <dd>
  958. Connects to the hostname specified by the URL and returns the content of a POST request.
  959. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1282" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  960. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1282" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  961. </dd>
  962. </div>
  963. <div id="postContent,HttpClient,,string,MultipartData">
  964. <dt><pre><span class="Keyword">proc</span> <a href="#postContent%2CHttpClient%2C%2Cstring%2CMultipartData"><span class="Identifier">postContent</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#HttpClient"><span class="Identifier">HttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">body</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
  965. <span class="Identifier">multipart</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
  966. <dd>
  967. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1284" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  968. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1284" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  969. </dd>
  970. </div>
  971. </div>
  972. <div id="put-procs-all">
  973. <div id="put,AsyncHttpClient,,string,MultipartData">
  974. <dt><pre><span class="Keyword">proc</span> <a href="#put%2CAsyncHttpClient%2C%2Cstring%2CMultipartData"><span class="Identifier">put</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#AsyncHttpClient"><span class="Identifier">AsyncHttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">body</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
  975. <span class="Identifier">multipart</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">)</span><span class="Other">:</span> <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="httpclient.html#AsyncResponse"><span class="Identifier">AsyncResponse</span></a><span class="Other">]</span> {.
  976. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span></span>.}</pre></dt>
  977. <dd>
  978. Connects to the hostname specified by the URL and performs a PUT request. This procedure uses httpClient values such as <tt class="docutils literal"><span class="pre"><span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">maxRedirects</span></span></tt>.
  979. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1289" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  980. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1289" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  981. </dd>
  982. </div>
  983. <div id="put,HttpClient,,string,MultipartData">
  984. <dt><pre><span class="Keyword">proc</span> <a href="#put%2CHttpClient%2C%2Cstring%2CMultipartData"><span class="Identifier">put</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#HttpClient"><span class="Identifier">HttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">body</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
  985. <span class="Identifier">multipart</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">)</span><span class="Other">:</span> <a href="httpclient.html#Response"><span class="Identifier">Response</span></a></pre></dt>
  986. <dd>
  987. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1291" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  988. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1291" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  989. </dd>
  990. </div>
  991. </div>
  992. <div id="putContent-procs-all">
  993. <div id="putContent,AsyncHttpClient,,string,MultipartData">
  994. <dt><pre><span class="Keyword">proc</span> <a href="#putContent%2CAsyncHttpClient%2C%2Cstring%2CMultipartData"><span class="Identifier">putContent</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#AsyncHttpClient"><span class="Identifier">AsyncHttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">body</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
  995. <span class="Identifier">multipart</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">)</span><span class="Other">:</span> <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span> {.
  996. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span></span>.}</pre></dt>
  997. <dd>
  998. Connects to the hostname specified by the URL andreturns the content of a PUT request.
  999. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1296" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1000. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1296" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1001. </dd>
  1002. </div>
  1003. <div id="putContent,HttpClient,,string,MultipartData">
  1004. <dt><pre><span class="Keyword">proc</span> <a href="#putContent%2CHttpClient%2C%2Cstring%2CMultipartData"><span class="Identifier">putContent</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#HttpClient"><span class="Identifier">HttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">body</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
  1005. <span class="Identifier">multipart</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
  1006. <dd>
  1007. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1297" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1008. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1297" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1009. </dd>
  1010. </div>
  1011. </div>
  1012. <div id="request-procs-all">
  1013. <div id="request,AsyncHttpClient,,string,HttpHeaders,MultipartData">
  1014. <dt><pre><span class="Keyword">proc</span> <a href="#request%2CAsyncHttpClient%2C%2Cstring%2CHttpHeaders%2CMultipartData"><span class="Identifier">request</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#AsyncHttpClient"><span class="Identifier">AsyncHttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span>
  1015. <span class="Identifier">httpMethod</span><span class="Other">:</span> <a href="httpcore.html#HttpMethod"><span class="Identifier">HttpMethod</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a> <span class="Other">=</span> <span class="Identifier">HttpGet</span><span class="Other">;</span> <span class="Identifier">body</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
  1016. <span class="Identifier">headers</span><span class="Other">:</span> <a href="httpcore.html#HttpHeaders"><span class="Identifier">HttpHeaders</span></a> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">;</span> <span class="Identifier">multipart</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">)</span><span class="Other">:</span> <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span>
  1017. <a href="httpclient.html#AsyncResponse"><span class="Identifier">AsyncResponse</span></a><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">stackTrace</span><span class="Other">:</span> <span class="DecNumber">false</span></span>.}</pre></dt>
  1018. <dd>
  1019. <p>Connects to the hostname specified by the URL and performs a request using the custom method string specified by <tt class="docutils literal"><span class="pre"><span class="Identifier">httpMethod</span></span></tt>.</p>
  1020. <p>Connection will be kept alive. Further requests on the same <tt class="docutils literal"><span class="pre"><span class="Identifier">client</span></span></tt> to the same hostname will not require a new connection to be made. The connection can be closed by using the <tt class="docutils literal"><span class="pre"><span class="Identifier">close</span></span></tt> procedure.</p>
  1021. <p>This procedure will follow redirects up to a maximum number of redirects specified in <tt class="docutils literal"><span class="pre"><span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">maxRedirects</span></span></tt>.</p>
  1022. <p>You need to make sure that the <tt class="docutils literal"><span class="pre"><span class="Identifier">url</span></span></tt> doesn't contain any newline characters. Failing to do so will raise <tt class="docutils literal"><span class="pre"><span class="Identifier">AssertionDefect</span></span></tt>.</p>
  1023. <p><tt class="docutils literal"><span class="pre"><span class="Identifier">headers</span></span></tt> are HTTP headers that override the <tt class="docutils literal"><span class="pre"><span class="Identifier">client</span><span class="Operator">.</span><span class="Identifier">headers</span></span></tt> for this specific request only and will not be persisted.</p>
  1024. <p><strong>Deprecated since v1.5</strong>: use HttpMethod enum instead; string parameter httpMethod is deprecated</p>
  1025. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1131" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1026. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1131" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1027. </dd>
  1028. </div>
  1029. <div id="request,HttpClient,,string,HttpHeaders,MultipartData">
  1030. <dt><pre><span class="Keyword">proc</span> <a href="#request%2CHttpClient%2C%2Cstring%2CHttpHeaders%2CMultipartData"><span class="Identifier">request</span></a><span class="Other">(</span><span class="Identifier">client</span><span class="Other">:</span> <a href="httpclient.html#HttpClient"><span class="Identifier">HttpClient</span></a><span class="Other">;</span> <span class="Identifier">url</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span>
  1031. <span class="Identifier">httpMethod</span><span class="Other">:</span> <a href="httpcore.html#HttpMethod"><span class="Identifier">HttpMethod</span></a> <span class="Operator">|</span> <a href="system.html#string"><span class="Identifier">string</span></a> <span class="Other">=</span> <span class="Identifier">HttpGet</span><span class="Other">;</span> <span class="Identifier">body</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span>
  1032. <span class="Identifier">headers</span><span class="Other">:</span> <a href="httpcore.html#HttpHeaders"><span class="Identifier">HttpHeaders</span></a> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">;</span> <span class="Identifier">multipart</span><span class="Other">:</span> <a href="httpclient.html#MultipartData"><span class="Identifier">MultipartData</span></a> <span class="Other">=</span> <span class="Keyword">nil</span><span class="Other">)</span><span class="Other">:</span> <a href="httpclient.html#Response"><span class="Identifier">Response</span></a></pre></dt>
  1033. <dd>
  1034. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/httpclient.nim#L1135" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1035. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/httpclient.nim#L1135" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1036. </dd>
  1037. </div>
  1038. </div>
  1039. </dl>
  1040. </div>
  1041. </div>
  1042. </div>
  1043. <div class="twelve-columns footer">
  1044. <span class="nim-sprite"></span>
  1045. <br>
  1046. <small style="color: var(--hint);">Made with Nim. Generated: 2024-12-25 13:28:09 UTC</small>
  1047. </div>
  1048. </div>
  1049. </div>
  1050. <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
  1051. </body>
  1052. </html>