asynchttpserver.html 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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/asynchttpserver</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/asynchttpserver</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>
  50. <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
  51. </li>
  52. <li>
  53. <details open>
  54. <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
  55. <ul class="simple simple-toc-section">
  56. <li><a class="reference" href="#AsyncHttpServer" title="AsyncHttpServer = ref object
  57. ## The maximum content-length that will be read for the body.">AsyncHttpServer</a></li>
  58. <li><a class="reference" href="#Request" title="Request = object
  59. client*: AsyncSocket
  60. reqMethod*: HttpMethod
  61. headers*: HttpHeaders
  62. protocol*: tuple[orig: string, major, minor: int]
  63. url*: Uri
  64. hostname*: string ## The hostname of the client that made the request.
  65. body*: string">Request</a></li>
  66. </ul>
  67. </details>
  68. </li>
  69. <li>
  70. <details open>
  71. <summary><a class="reference reference-toplevel" href="#10" id="60">Consts</a></summary>
  72. <ul class="simple simple-toc-section">
  73. <li><a class="reference" href="#nimMaxDescriptorsFallback" title="nimMaxDescriptorsFallback {.intdefine.} = 16000">nimMaxDescriptorsFallback</a></li>
  74. </ul>
  75. </details>
  76. </li>
  77. <li>
  78. <details open>
  79. <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
  80. <ul class="simple simple-toc-section">
  81. <ul class="simple nested-toc-section">acceptRequest
  82. <li><a class="reference" href="#acceptRequest%2CAsyncHttpServer%2Cproc%28Request%29" title="acceptRequest(server: AsyncHttpServer; callback: proc (request: Request): Future[
  83. void] {.closure, gcsafe.}): owned(Future[void])">acceptRequest(server: AsyncHttpServer; callback: proc (request: Request): Future[
  84. void] {.closure, gcsafe.}): owned(Future[void])</a></li>
  85. </ul>
  86. <ul class="simple nested-toc-section">close
  87. <li><a class="reference" href="#close%2CAsyncHttpServer" title="close(server: AsyncHttpServer)">close(server: AsyncHttpServer)</a></li>
  88. </ul>
  89. <ul class="simple nested-toc-section">getPort
  90. <li><a class="reference" href="#getPort%2CAsyncHttpServer" title="getPort(self: AsyncHttpServer): Port">getPort(self: AsyncHttpServer): Port</a></li>
  91. </ul>
  92. <ul class="simple nested-toc-section">listen
  93. <li><a class="reference" href="#listen%2CAsyncHttpServer%2CPort%2Cstring" title="listen(server: AsyncHttpServer; port: Port; address = &quot;&quot;; domain = AF_INET)">listen(server: AsyncHttpServer; port: Port; address = &quot;&quot;; domain = AF_INET)</a></li>
  94. </ul>
  95. <ul class="simple nested-toc-section">newAsyncHttpServer
  96. <li><a class="reference" href="#newAsyncHttpServer%2Cint" title="newAsyncHttpServer(reuseAddr = true; reusePort = false; maxBody = 8388608): AsyncHttpServer">newAsyncHttpServer(reuseAddr = true; reusePort = false; maxBody = 8388608): AsyncHttpServer</a></li>
  97. </ul>
  98. <ul class="simple nested-toc-section">respond
  99. <li><a class="reference" href="#respond%2CRequest%2CHttpCode%2Cstring%2CHttpHeaders" title="respond(req: Request; code: HttpCode; content: string;
  100. headers: HttpHeaders = nil): Future[void]">respond(req: Request; code: HttpCode; content: string;
  101. headers: HttpHeaders = nil): Future[void]</a></li>
  102. </ul>
  103. <ul class="simple nested-toc-section">sendHeaders
  104. <li><a class="reference" href="#sendHeaders%2CRequest%2CHttpHeaders" title="sendHeaders(req: Request; headers: HttpHeaders): Future[void]">sendHeaders(req: Request; headers: HttpHeaders): Future[void]</a></li>
  105. </ul>
  106. <ul class="simple nested-toc-section">serve
  107. <li><a class="reference" href="#serve%2CAsyncHttpServer%2CPort%2Cproc%28Request%29%2Cstring%2Cint" title="serve(server: AsyncHttpServer; port: Port;
  108. callback: proc (request: Request): Future[void] {.closure, gcsafe.};
  109. address = &quot;&quot;; assumedDescriptorsPerRequest = -1; domain = AF_INET): owned(
  110. Future[void])">serve(server: AsyncHttpServer; port: Port;
  111. callback: proc (request: Request): Future[void] {.closure, gcsafe.};
  112. address = &quot;&quot;; assumedDescriptorsPerRequest = -1; domain = AF_INET): owned(
  113. Future[void])</a></li>
  114. </ul>
  115. <ul class="simple nested-toc-section">shouldAcceptRequest
  116. <li><a class="reference" href="#shouldAcceptRequest%2CAsyncHttpServer%2Cint" title="shouldAcceptRequest(server: AsyncHttpServer; assumedDescriptorsPerRequest = 5): bool">shouldAcceptRequest(server: AsyncHttpServer; assumedDescriptorsPerRequest = 5): bool</a></li>
  117. </ul>
  118. </ul>
  119. </details>
  120. </li>
  121. </ul>
  122. </div>
  123. <div class="nine columns" id="content">
  124. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asynchttpserver.nim#L1" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  125. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asynchttpserver.nim#L1" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  126. <div id="tocRoot"></div>
  127. <p class="module-desc"><p>This module implements a high performance asynchronous HTTP server.</p>
  128. <p>This HTTP server has not been designed to be used in production, but for testing applications locally. Because of this, when deploying your application in production you should use a reverse proxy (for example nginx) instead of allowing users to connect directly to this server.</p>
  129. <p><strong class="examples_text">Example: cmd: -r:off</strong></p>
  130. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">asynchttpserver</span>
  131. <span class="Comment"># This example will create an HTTP server on an automatically chosen port.</span>
  132. <span class="Comment"># It will respond to all requests with a `200 OK` response code and &quot;Hello World&quot;</span>
  133. <span class="Comment"># as the response body.</span>
  134. <span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">asyncdispatch</span>
  135. <span class="Keyword">proc</span> <span class="Identifier">main</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>
  136. <span class="Keyword">var</span> <span class="Identifier">server</span> <span class="Operator">=</span> <span class="Identifier">newAsyncHttpServer</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  137. <span class="Keyword">proc</span> <span class="Identifier">cb</span><span class="Punctuation">(</span><span class="Identifier">req</span><span class="Punctuation">:</span> <span class="Identifier">Request</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>
  138. <span class="Identifier">echo</span> <span class="Punctuation">(</span><span class="Identifier">req</span><span class="Operator">.</span><span class="Identifier">reqMethod</span><span class="Punctuation">,</span> <span class="Identifier">req</span><span class="Operator">.</span><span class="Identifier">url</span><span class="Punctuation">,</span> <span class="Identifier">req</span><span class="Operator">.</span><span class="Identifier">headers</span><span class="Punctuation">)</span>
  139. <span class="Keyword">let</span> <span class="Identifier">headers</span> <span class="Operator">=</span> <span class="Punctuation">{</span><span class="StringLit">&quot;Content-type&quot;</span><span class="Punctuation">:</span> <span class="StringLit">&quot;text/plain; charset=utf-8&quot;</span><span class="Punctuation">}</span>
  140. <span class="Identifier">await</span> <span class="Identifier">req</span><span class="Operator">.</span><span class="Identifier">respond</span><span class="Punctuation">(</span><span class="Identifier">Http200</span><span class="Punctuation">,</span> <span class="StringLit">&quot;Hello World&quot;</span><span class="Punctuation">,</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="Punctuation">)</span>
  141. <span class="Identifier">server</span><span class="Operator">.</span><span class="Identifier">listen</span><span class="Punctuation">(</span><span class="Identifier">Port</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span><span class="Punctuation">)</span> <span class="Comment"># or Port(8080) to hardcode the standard HTTP port.</span>
  142. <span class="Keyword">let</span> <span class="Identifier">port</span> <span class="Operator">=</span> <span class="Identifier">server</span><span class="Operator">.</span><span class="Identifier">getPort</span>
  143. <span class="Identifier">echo</span> <span class="StringLit">&quot;test this with: curl localhost:&quot;</span> <span class="Operator">&amp;</span> <span class="Operator">$</span><span class="Identifier">port</span><span class="Operator">.</span><span class="Identifier">uint16</span> <span class="Operator">&amp;</span> <span class="StringLit">&quot;/&quot;</span>
  144. <span class="Keyword">while</span> <span class="Identifier">true</span><span class="Punctuation">:</span>
  145. <span class="Keyword">if</span> <span class="Identifier">server</span><span class="Operator">.</span><span class="Identifier">shouldAcceptRequest</span><span class="Punctuation">(</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
  146. <span class="Identifier">await</span> <span class="Identifier">server</span><span class="Operator">.</span><span class="Identifier">acceptRequest</span><span class="Punctuation">(</span><span class="Identifier">cb</span><span class="Punctuation">)</span>
  147. <span class="Keyword">else</span><span class="Punctuation">:</span>
  148. <span class="Comment"># too many concurrent connections, `maxFDs` exceeded</span>
  149. <span class="Comment"># wait 500ms for FDs to be closed</span>
  150. <span class="Identifier">await</span> <span class="Identifier">sleepAsync</span><span class="Punctuation">(</span><span class="DecNumber">500</span><span class="Punctuation">)</span>
  151. <span class="Identifier">waitFor</span> <span class="Identifier">main</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre></p>
  152. <div class="section" id="6">
  153. <h1><a class="toc-backref" href="#6">Imports</a></h1>
  154. <dl class="item">
  155. <a class="reference external" href="asyncnet.html">asyncnet</a>, <a class="reference external" href="asyncdispatch.html">asyncdispatch</a>, <a class="reference external" href="parseutils.html">parseutils</a>, <a class="reference external" href="uri.html">uri</a>, <a class="reference external" href="strutils.html">strutils</a>, <a class="reference external" href="httpcore.html">httpcore</a>, <a class="reference external" href="nativesockets.html">nativesockets</a>, <a class="reference external" href="since.html">since</a>, <a class="reference external" href="assertions.html">assertions</a>
  156. </dl>
  157. </div>
  158. <div class="section" id="7">
  159. <h1><a class="toc-backref" href="#7">Types</a></h1>
  160. <dl class="item">
  161. <div id="AsyncHttpServer">
  162. <dt><pre><a href="asynchttpserver.html#AsyncHttpServer"><span class="Identifier">AsyncHttpServer</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <span class="Keyword">object</span>
  163. <span class="Comment">## The maximum content-length that will be read for the body.</span></pre></dt>
  164. <dd>
  165. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asynchttpserver.nim#L70" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  166. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asynchttpserver.nim#L70" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  167. </dd>
  168. </div>
  169. <div id="Request">
  170. <dt><pre><a href="asynchttpserver.html#Request"><span class="Identifier">Request</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
  171. <span class="Identifier">client</span><span class="Operator">*</span><span class="Other">:</span> <a href="asyncnet.html#AsyncSocket"><span class="Identifier">AsyncSocket</span></a>
  172. <span class="Identifier">reqMethod</span><span class="Operator">*</span><span class="Other">:</span> <a href="httpcore.html#HttpMethod"><span class="Identifier">HttpMethod</span></a>
  173. <span class="Identifier">headers</span><span class="Operator">*</span><span class="Other">:</span> <a href="httpcore.html#HttpHeaders"><span class="Identifier">HttpHeaders</span></a>
  174. <span class="Identifier">protocol</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">orig</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">,</span> <span class="Identifier">major</span><span class="Other">,</span> <span class="Identifier">minor</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span>
  175. <span class="Identifier">url</span><span class="Operator">*</span><span class="Other">:</span> <a href="uri.html#Uri"><span class="Identifier">Uri</span></a>
  176. <span class="Identifier">hostname</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> <span class="Comment">## The hostname of the client that made the request.</span>
  177. <span class="Identifier">body</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
  178. <dd>
  179. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asynchttpserver.nim#L61" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  180. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asynchttpserver.nim#L61" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  181. </dd>
  182. </div>
  183. </dl>
  184. </div>
  185. <div class="section" id="10">
  186. <h1><a class="toc-backref" href="#10">Consts</a></h1>
  187. <dl class="item">
  188. <div id="nimMaxDescriptorsFallback">
  189. <dt><pre><a href="asynchttpserver.html#nimMaxDescriptorsFallback"><span class="Identifier">nimMaxDescriptorsFallback</span></a> {.<span class="Identifier">intdefine</span>.} <span class="Other">=</span> <span class="DecNumber">16000</span></pre></dt>
  190. <dd>
  191. fallback value for
  192. when <tt class="docutils literal"><span class="pre"><span class="Identifier">maxDescriptors</span></span></tt> is not available. This can be set on the command line during compilation via <tt class="docutils literal"><span class="pre"><span class="Operator">-</span><span class="Identifier">d</span><span class="Punctuation">:</span><span class="Identifier">nimMaxDescriptorsFallback</span><span class="Operator">=</span><span class="Identifier">N</span></span></tt>
  193. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asynchttpserver.nim#L377" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  194. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asynchttpserver.nim#L377" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  195. </dd>
  196. </div>
  197. </dl>
  198. </div>
  199. <div class="section" id="12">
  200. <h1><a class="toc-backref" href="#12">Procs</a></h1>
  201. <dl class="item">
  202. <div id="acceptRequest-procs-all">
  203. <div id="acceptRequest,AsyncHttpServer,proc(Request)">
  204. <dt><pre><span class="Keyword">proc</span> <a href="#acceptRequest%2CAsyncHttpServer%2Cproc%28Request%29"><span class="Identifier">acceptRequest</span></a><span class="Other">(</span><span class="Identifier">server</span><span class="Other">:</span> <a href="asynchttpserver.html#AsyncHttpServer"><span class="Identifier">AsyncHttpServer</span></a><span class="Other">;</span> <span class="Identifier">callback</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">request</span><span class="Other">:</span> <a href="asynchttpserver.html#Request"><span class="Identifier">Request</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>
  205. <a href="system.html#void"><span class="Identifier">void</span></a><span class="Other">]</span> {.<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>.}<span class="Other">)</span><span class="Other">:</span> <a href="system.html#owned"><span class="Identifier">owned</span></a><span class="Other">(</span><a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#void"><span class="Identifier">void</span></a><span class="Other">]</span><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>
  206. <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="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">SslError</span><span class="Other">,</span> <span class="Identifier">LibraryError</span><span class="Other">,</span> <span class="Identifier">KeyError</span><span class="Other">]</span><span class="Other">,</span>
  207. <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>
  208. <dd>
  209. Accepts a single request. Write an explicit loop around this proc so that errors can be handled properly.
  210. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asynchttpserver.nim#L406" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  211. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asynchttpserver.nim#L406" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  212. </dd>
  213. </div>
  214. </div>
  215. <div id="close-procs-all">
  216. <div id="close,AsyncHttpServer">
  217. <dt><pre><span class="Keyword">proc</span> <a href="#close%2CAsyncHttpServer"><span class="Identifier">close</span></a><span class="Other">(</span><span class="Identifier">server</span><span class="Other">:</span> <a href="asynchttpserver.html#AsyncHttpServer"><span class="Identifier">AsyncHttpServer</span></a><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">LibraryError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">SslError</span><span class="Other">]</span><span class="Other">,</span>
  218. <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>
  219. <dd>
  220. Terminates the async http server instance.
  221. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asynchttpserver.nim#L439" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  222. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asynchttpserver.nim#L439" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  223. </dd>
  224. </div>
  225. </div>
  226. <div id="getPort-procs-all">
  227. <div id="getPort,AsyncHttpServer">
  228. <dt><pre><span class="Keyword">proc</span> <a href="#getPort%2CAsyncHttpServer"><span class="Identifier">getPort</span></a><span class="Other">(</span><span class="Identifier">self</span><span class="Other">:</span> <a href="asynchttpserver.html#AsyncHttpServer"><span class="Identifier">AsyncHttpServer</span></a><span class="Other">)</span><span class="Other">:</span> <a href="nativesockets.html#Port"><span class="Identifier">Port</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">OSError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span>
  229. <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>
  230. <dd>
  231. <p>Returns the port <tt class="docutils literal"><span class="pre"><span class="Identifier">self</span></span></tt> was bound to.</p>
  232. <p>Useful for identifying what port <tt class="docutils literal"><span class="pre"><span class="Identifier">self</span></span></tt> is bound to, if it was chosen automatically, for example via <tt class="docutils literal"><span class="pre"><span class="Identifier">listen</span><span class="Punctuation">(</span><span class="Identifier">Port</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span><span class="Punctuation">)</span></span></tt>.</p>
  233. <p><strong class="examples_text">Example:</strong></p>
  234. <pre class="listing"><span class="Keyword">from</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">nativesockets</span> <span class="Keyword">import</span> <span class="Identifier">Port</span>
  235. <span class="Keyword">let</span> <span class="Identifier">server</span> <span class="Operator">=</span> <span class="Identifier">newAsyncHttpServer</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  236. <span class="Identifier">server</span><span class="Operator">.</span><span class="Identifier">listen</span><span class="Punctuation">(</span><span class="Identifier">Port</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
  237. <span class="Identifier">assert</span> <span class="Identifier">server</span><span class="Operator">.</span><span class="Identifier">getPort</span><span class="Operator">.</span><span class="Identifier">uint16</span> <span class="Operator">&gt;</span> <span class="DecNumber">0</span>
  238. <span class="Identifier">server</span><span class="Operator">.</span><span class="Identifier">close</span><span class="Punctuation">(</span><span class="Punctuation">)</span></pre>
  239. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asynchttpserver.nim#L77" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  240. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asynchttpserver.nim#L77" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  241. </dd>
  242. </div>
  243. </div>
  244. <div id="listen-procs-all">
  245. <div id="listen,AsyncHttpServer,Port,string">
  246. <dt><pre><span class="Keyword">proc</span> <a href="#listen%2CAsyncHttpServer%2CPort%2Cstring"><span class="Identifier">listen</span></a><span class="Other">(</span><span class="Identifier">server</span><span class="Other">:</span> <a href="asynchttpserver.html#AsyncHttpServer"><span class="Identifier">AsyncHttpServer</span></a><span class="Other">;</span> <span class="Identifier">port</span><span class="Other">:</span> <a href="nativesockets.html#Port"><span class="Identifier">Port</span></a><span class="Other">;</span> <span class="Identifier">address</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span> <span class="Identifier">domain</span> <span class="Other">=</span> <span class="Identifier">AF_INET</span><span class="Other">)</span> {.
  247. <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">OSError</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">WriteIOEffect</span><span class="Other">,</span> <span class="Identifier">ReadIOEffect</span><span class="Other">]</span><span class="Other">,</span>
  248. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  249. <dd>
  250. Listen to the given port and address.
  251. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asynchttpserver.nim#L382" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  252. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asynchttpserver.nim#L382" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  253. </dd>
  254. </div>
  255. </div>
  256. <div id="newAsyncHttpServer-procs-all">
  257. <div id="newAsyncHttpServer,int">
  258. <dt><pre><span class="Keyword">proc</span> <a href="#newAsyncHttpServer%2Cint"><span class="Identifier">newAsyncHttpServer</span></a><span class="Other">(</span><span class="Identifier">reuseAddr</span> <span class="Other">=</span> <span class="Identifier">true</span><span class="Other">;</span> <span class="Identifier">reusePort</span> <span class="Other">=</span> <span class="Identifier">false</span><span class="Other">;</span> <span class="Identifier">maxBody</span> <span class="Other">=</span> <span class="DecNumber">8388608</span><span class="Other">)</span><span class="Other">:</span> <a href="asynchttpserver.html#AsyncHttpServer"><span class="Identifier">AsyncHttpServer</span></a> {.
  259. <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>
  260. <dd>
  261. Creates a new <tt class="docutils literal"><span class="pre"><span class="Identifier">AsyncHttpServer</span></span></tt> instance.
  262. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asynchttpserver.nim#L90" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  263. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asynchttpserver.nim#L90" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  264. </dd>
  265. </div>
  266. </div>
  267. <div id="respond-procs-all">
  268. <div id="respond,Request,HttpCode,string,HttpHeaders">
  269. <dt><pre><span class="Keyword">proc</span> <a href="#respond%2CRequest%2CHttpCode%2Cstring%2CHttpHeaders"><span class="Identifier">respond</span></a><span class="Other">(</span><span class="Identifier">req</span><span class="Other">:</span> <a href="asynchttpserver.html#Request"><span class="Identifier">Request</span></a><span class="Other">;</span> <span class="Identifier">code</span><span class="Other">:</span> <a href="httpcore.html#HttpCode"><span class="Identifier">HttpCode</span></a><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>
  270. <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="Other">:</span> <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#void"><span class="Identifier">void</span></a><span class="Other">]</span> {.
  271. <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">Exception</span><span class="Other">,</span> <span class="Identifier">SslError</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>
  272. <dd>
  273. <p>Responds to the request with the specified <tt class="docutils literal"><span class="pre"><span class="Identifier">HttpCode</span></span></tt>, headers and content.</p>
  274. <p>This procedure will <strong>not</strong> close the client socket.</p>
  275. <p>Example:</p>
  276. <p><pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">json</span>
  277. <span class="Keyword">proc</span> <span class="Identifier">handler</span><span class="Punctuation">(</span><span class="Identifier">req</span><span class="Punctuation">:</span> <span class="Identifier">Request</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>
  278. <span class="Keyword">if</span> <span class="Identifier">req</span><span class="Operator">.</span><span class="Identifier">url</span><span class="Operator">.</span><span class="Identifier">path</span> <span class="Operator">==</span> <span class="StringLit">&quot;/hello-world&quot;</span><span class="Punctuation">:</span>
  279. <span class="Keyword">let</span> <span class="Identifier">msg</span> <span class="Operator">=</span> <span class="Operator">%*</span> <span class="Punctuation">{</span><span class="StringLit">&quot;message&quot;</span><span class="Punctuation">:</span> <span class="StringLit">&quot;Hello World&quot;</span><span class="Punctuation">}</span>
  280. <span class="Keyword">let</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="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><span class="Punctuation">)</span>
  281. <span class="Identifier">await</span> <span class="Identifier">req</span><span class="Operator">.</span><span class="Identifier">respond</span><span class="Punctuation">(</span><span class="Identifier">Http200</span><span class="Punctuation">,</span> <span class="Operator">$</span><span class="Identifier">msg</span><span class="Punctuation">,</span> <span class="Identifier">headers</span><span class="Punctuation">)</span>
  282. <span class="Keyword">else</span><span class="Punctuation">:</span>
  283. <span class="Identifier">await</span> <span class="Identifier">req</span><span class="Operator">.</span><span class="Identifier">respond</span><span class="Punctuation">(</span><span class="Identifier">Http404</span><span class="Punctuation">,</span> <span class="StringLit">&quot;Not Found&quot;</span><span class="Punctuation">)</span></pre></p>
  284. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asynchttpserver.nim#L105" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  285. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asynchttpserver.nim#L105" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  286. </dd>
  287. </div>
  288. </div>
  289. <div id="sendHeaders-procs-all">
  290. <div id="sendHeaders,Request,HttpHeaders">
  291. <dt><pre><span class="Keyword">proc</span> <a href="#sendHeaders%2CRequest%2CHttpHeaders"><span class="Identifier">sendHeaders</span></a><span class="Other">(</span><span class="Identifier">req</span><span class="Other">:</span> <a href="asynchttpserver.html#Request"><span class="Identifier">Request</span></a><span class="Other">;</span> <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="Other">:</span> <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#void"><span class="Identifier">void</span></a><span class="Other">]</span> {.
  292. <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">Exception</span><span class="Other">,</span> <span class="Identifier">SslError</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>
  293. <dd>
  294. Sends the specified headers to the requesting client.
  295. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asynchttpserver.nim#L99" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  296. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asynchttpserver.nim#L99" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  297. </dd>
  298. </div>
  299. </div>
  300. <div id="serve-procs-all">
  301. <div id="serve,AsyncHttpServer,Port,proc(Request),string,int">
  302. <dt><pre><span class="Keyword">proc</span> <a href="#serve%2CAsyncHttpServer%2CPort%2Cproc%28Request%29%2Cstring%2Cint"><span class="Identifier">serve</span></a><span class="Other">(</span><span class="Identifier">server</span><span class="Other">:</span> <a href="asynchttpserver.html#AsyncHttpServer"><span class="Identifier">AsyncHttpServer</span></a><span class="Other">;</span> <span class="Identifier">port</span><span class="Other">:</span> <a href="nativesockets.html#Port"><span class="Identifier">Port</span></a><span class="Other">;</span>
  303. <span class="Identifier">callback</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">request</span><span class="Other">:</span> <a href="asynchttpserver.html#Request"><span class="Identifier">Request</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#void"><span class="Identifier">void</span></a><span class="Other">]</span> {.<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>.}<span class="Other">;</span>
  304. <span class="Identifier">address</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">;</span> <span class="Identifier">assumedDescriptorsPerRequest</span> <span class="Other">=</span> <span class="DecNumber">-1</span><span class="Other">;</span> <span class="Identifier">domain</span> <span class="Other">=</span> <span class="Identifier">AF_INET</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#owned"><span class="Identifier">owned</span></a><span class="Other">(</span>
  305. <a href="asyncfutures.html#Future"><span class="Identifier">Future</span></a><span class="Other">[</span><a href="system.html#void"><span class="Identifier">void</span></a><span class="Other">]</span><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> <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">OSError</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">,</span>
  306. <span class="Identifier">SslError</span><span class="Other">,</span> <span class="Identifier">LibraryError</span><span class="Other">,</span> <span class="Identifier">KeyError</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="Identifier">WriteIOEffect</span><span class="Other">,</span>
  307. <span class="Identifier">ReadIOEffect</span><span class="Other">,</span> <span class="Identifier">TimeEffect</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>
  308. <dd>
  309. <p>Starts the process of listening for incoming HTTP connections on the specified address and port.</p>
  310. <p>When a request is made by a client the specified callback will be called.</p>
  311. <p>If <tt class="docutils literal"><span class="pre"><span class="Identifier">assumedDescriptorsPerRequest</span></span></tt> is 0 or greater the server cares about the process's maximum file descriptor limit. It then ensures that the process still has the resources for <tt class="docutils literal"><span class="pre"><span class="Identifier">assumedDescriptorsPerRequest</span></span></tt> file descriptors before accepting a connection.</p>
  312. <p>You should prefer to call <tt class="docutils literal"><span class="pre"><span class="Identifier">acceptRequest</span></span></tt> instead with a custom server loop so that you're in control over the error handling and logging.</p>
  313. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asynchttpserver.nim#L416" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  314. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asynchttpserver.nim#L416" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  315. </dd>
  316. </div>
  317. </div>
  318. <div id="shouldAcceptRequest-procs-all">
  319. <div id="shouldAcceptRequest,AsyncHttpServer,int">
  320. <dt><pre><span class="Keyword">proc</span> <a href="#shouldAcceptRequest%2CAsyncHttpServer%2Cint"><span class="Identifier">shouldAcceptRequest</span></a><span class="Other">(</span><span class="Identifier">server</span><span class="Other">:</span> <a href="asynchttpserver.html#AsyncHttpServer"><span class="Identifier">AsyncHttpServer</span></a><span class="Other">;</span>
  321. <span class="Identifier">assumedDescriptorsPerRequest</span> <span class="Other">=</span> <span class="DecNumber">5</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span>
  322. <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>
  323. <dd>
  324. Returns true if the process's current number of opened file descriptors is still within the maximum limit and so it's reasonable to accept yet another request.
  325. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/asynchttpserver.nim#L397" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  326. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/asynchttpserver.nim#L397" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  327. </dd>
  328. </div>
  329. </div>
  330. </dl>
  331. </div>
  332. </div>
  333. </div>
  334. <div class="twelve-columns footer">
  335. <span class="nim-sprite"></span>
  336. <br>
  337. <small style="color: var(--hint);">Made with Nim. Generated: 2025-04-03 14:18:24 UTC</small>
  338. </div>
  339. </div>
  340. </div>
  341. <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
  342. </body>
  343. </html>