gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

912 line
78KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="http.server — HTTP servers" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/http.server.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Source code: Lib/http/server.py This module defines classes for implementing HTTP servers. Availability: not Emscripten, not WASI. This module does not work or is not available on WebAssembly platf..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="Source code: Lib/http/server.py This module defines classes for implementing HTTP servers. Availability: not Emscripten, not WASI. This module does not work or is not available on WebAssembly platf..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>http.server — HTTP servers &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="http.cookies — HTTP state management" href="http.cookies.html" />
  33. <link rel="prev" title="socketserver — A framework for network servers" href="socketserver.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/http.server.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.server</span></code> — HTTP servers</a><ul>
  86. <li><a class="reference internal" href="#security-considerations">Security Considerations</a></li>
  87. </ul>
  88. </li>
  89. </ul>
  90. </div>
  91. <div>
  92. <h4>Previous topic</h4>
  93. <p class="topless"><a href="socketserver.html"
  94. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">socketserver</span></code> — A framework for network servers</a></p>
  95. </div>
  96. <div>
  97. <h4>Next topic</h4>
  98. <p class="topless"><a href="http.cookies.html"
  99. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.cookies</span></code> — HTTP state management</a></p>
  100. </div>
  101. <div role="note" aria-label="source link">
  102. <h3>This Page</h3>
  103. <ul class="this-page-menu">
  104. <li><a href="../bugs.html">Report a Bug</a></li>
  105. <li>
  106. <a href="https://github.com/python/cpython/blob/main/Doc/library/http.server.rst"
  107. rel="nofollow">Show Source
  108. </a>
  109. </li>
  110. </ul>
  111. </div>
  112. </nav>
  113. </div>
  114. </div>
  115. <div class="related" role="navigation" aria-label="related navigation">
  116. <h3>Navigation</h3>
  117. <ul>
  118. <li class="right" style="margin-right: 10px">
  119. <a href="../genindex.html" title="General Index"
  120. accesskey="I">index</a></li>
  121. <li class="right" >
  122. <a href="../py-modindex.html" title="Python Module Index"
  123. >modules</a> |</li>
  124. <li class="right" >
  125. <a href="http.cookies.html" title="http.cookies — HTTP state management"
  126. accesskey="N">next</a> |</li>
  127. <li class="right" >
  128. <a href="socketserver.html" title="socketserver — A framework for network servers"
  129. accesskey="P">previous</a> |</li>
  130. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  131. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  132. <li class="switchers">
  133. <div class="language_switcher_placeholder"></div>
  134. <div class="version_switcher_placeholder"></div>
  135. </li>
  136. <li>
  137. </li>
  138. <li id="cpython-language-and-version">
  139. <a href="../index.html">3.12.3 Documentation</a> &#187;
  140. </li>
  141. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  142. <li class="nav-item nav-item-2"><a href="internet.html" accesskey="U">Internet Protocols and Support</a> &#187;</li>
  143. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.server</span></code> — HTTP servers</a></li>
  144. <li class="right">
  145. <div class="inline-search" role="search">
  146. <form class="inline-search" action="../search.html" method="get">
  147. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  148. <input type="submit" value="Go" />
  149. </form>
  150. </div>
  151. |
  152. </li>
  153. <li class="right">
  154. <label class="theme-selector-label">
  155. Theme
  156. <select class="theme-selector" oninput="activateTheme(this.value)">
  157. <option value="auto" selected>Auto</option>
  158. <option value="light">Light</option>
  159. <option value="dark">Dark</option>
  160. </select>
  161. </label> |</li>
  162. </ul>
  163. </div>
  164. <div class="document">
  165. <div class="documentwrapper">
  166. <div class="bodywrapper">
  167. <div class="body" role="main">
  168. <section id="module-http.server">
  169. <span id="http-server-http-servers"></span><h1><a class="reference internal" href="#module-http.server" title="http.server: HTTP server and request handlers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.server</span></code></a> — HTTP servers<a class="headerlink" href="#module-http.server" title="Link to this heading">¶</a></h1>
  170. <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/http/server.py">Lib/http/server.py</a></p>
  171. <hr class="docutils" id="index-0" />
  172. <p>This module defines classes for implementing HTTP servers.</p>
  173. <div class="admonition warning">
  174. <p class="admonition-title">Warning</p>
  175. <p><a class="reference internal" href="#module-http.server" title="http.server: HTTP server and request handlers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.server</span></code></a> is not recommended for production. It only implements
  176. <a class="reference internal" href="#http-server-security"><span class="std std-ref">basic security checks</span></a>.</p>
  177. </div>
  178. <div class="availability docutils container">
  179. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: not Emscripten, not WASI.</p>
  180. <p>This module does not work or is not available on WebAssembly platforms
  181. <code class="docutils literal notranslate"><span class="pre">wasm32-emscripten</span></code> and <code class="docutils literal notranslate"><span class="pre">wasm32-wasi</span></code>. See
  182. <a class="reference internal" href="intro.html#wasm-availability"><span class="std std-ref">WebAssembly platforms</span></a> for more information.</p>
  183. </div>
  184. <p>One class, <a class="reference internal" href="#http.server.HTTPServer" title="http.server.HTTPServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPServer</span></code></a>, is a <a class="reference internal" href="socketserver.html#socketserver.TCPServer" title="socketserver.TCPServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">socketserver.TCPServer</span></code></a> subclass.
  185. It creates and listens at the HTTP socket, dispatching the requests to a
  186. handler. Code to create and run the server looks like this:</p>
  187. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">run</span><span class="p">(</span><span class="n">server_class</span><span class="o">=</span><span class="n">HTTPServer</span><span class="p">,</span> <span class="n">handler_class</span><span class="o">=</span><span class="n">BaseHTTPRequestHandler</span><span class="p">):</span>
  188. <span class="n">server_address</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="mi">8000</span><span class="p">)</span>
  189. <span class="n">httpd</span> <span class="o">=</span> <span class="n">server_class</span><span class="p">(</span><span class="n">server_address</span><span class="p">,</span> <span class="n">handler_class</span><span class="p">)</span>
  190. <span class="n">httpd</span><span class="o">.</span><span class="n">serve_forever</span><span class="p">()</span>
  191. </pre></div>
  192. </div>
  193. <dl class="py class">
  194. <dt class="sig sig-object py" id="http.server.HTTPServer">
  195. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">http.server.</span></span><span class="sig-name descname"><span class="pre">HTTPServer</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">server_address</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">RequestHandlerClass</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#http.server.HTTPServer" title="Link to this definition">¶</a></dt>
  196. <dd><p>This class builds on the <a class="reference internal" href="socketserver.html#socketserver.TCPServer" title="socketserver.TCPServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">TCPServer</span></code></a> class by storing
  197. the server address as instance variables named <code class="xref py py-attr docutils literal notranslate"><span class="pre">server_name</span></code> and
  198. <code class="xref py py-attr docutils literal notranslate"><span class="pre">server_port</span></code>. The server is accessible by the handler, typically
  199. through the handler’s <code class="xref py py-attr docutils literal notranslate"><span class="pre">server</span></code> instance variable.</p>
  200. </dd></dl>
  201. <dl class="py class">
  202. <dt class="sig sig-object py" id="http.server.ThreadingHTTPServer">
  203. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">http.server.</span></span><span class="sig-name descname"><span class="pre">ThreadingHTTPServer</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">server_address</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">RequestHandlerClass</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#http.server.ThreadingHTTPServer" title="Link to this definition">¶</a></dt>
  204. <dd><p>This class is identical to HTTPServer but uses threads to handle
  205. requests by using the <a class="reference internal" href="socketserver.html#socketserver.ThreadingMixIn" title="socketserver.ThreadingMixIn"><code class="xref py py-class docutils literal notranslate"><span class="pre">ThreadingMixIn</span></code></a>. This
  206. is useful to handle web browsers pre-opening sockets, on which
  207. <a class="reference internal" href="#http.server.HTTPServer" title="http.server.HTTPServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPServer</span></code></a> would wait indefinitely.</p>
  208. <div class="versionadded">
  209. <p><span class="versionmodified added">New in version 3.7.</span></p>
  210. </div>
  211. </dd></dl>
  212. <p>The <a class="reference internal" href="#http.server.HTTPServer" title="http.server.HTTPServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPServer</span></code></a> and <a class="reference internal" href="#http.server.ThreadingHTTPServer" title="http.server.ThreadingHTTPServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">ThreadingHTTPServer</span></code></a> must be given
  213. a <em>RequestHandlerClass</em> on instantiation, of which this module
  214. provides three different variants:</p>
  215. <dl class="py class">
  216. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler">
  217. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">http.server.</span></span><span class="sig-name descname"><span class="pre">BaseHTTPRequestHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">request</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">client_address</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">server</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler" title="Link to this definition">¶</a></dt>
  218. <dd><p>This class is used to handle the HTTP requests that arrive at the server. By
  219. itself, it cannot respond to any actual HTTP requests; it must be subclassed
  220. to handle each request method (e.g. GET or POST).
  221. <a class="reference internal" href="#http.server.BaseHTTPRequestHandler" title="http.server.BaseHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseHTTPRequestHandler</span></code></a> provides a number of class and instance
  222. variables, and methods for use by subclasses.</p>
  223. <p>The handler will parse the request and the headers, then call a method
  224. specific to the request type. The method name is constructed from the
  225. request. For example, for the request method <code class="docutils literal notranslate"><span class="pre">SPAM</span></code>, the <code class="xref py py-meth docutils literal notranslate"><span class="pre">do_SPAM()</span></code>
  226. method will be called with no arguments. All of the relevant information is
  227. stored in instance variables of the handler. Subclasses should not need to
  228. override or extend the <code class="xref py py-meth docutils literal notranslate"><span class="pre">__init__()</span></code> method.</p>
  229. <p><a class="reference internal" href="#http.server.BaseHTTPRequestHandler" title="http.server.BaseHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseHTTPRequestHandler</span></code></a> has the following instance variables:</p>
  230. <dl class="py attribute">
  231. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.client_address">
  232. <span class="sig-name descname"><span class="pre">client_address</span></span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.client_address" title="Link to this definition">¶</a></dt>
  233. <dd><p>Contains a tuple of the form <code class="docutils literal notranslate"><span class="pre">(host,</span> <span class="pre">port)</span></code> referring to the client’s
  234. address.</p>
  235. </dd></dl>
  236. <dl class="py attribute">
  237. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.server">
  238. <span class="sig-name descname"><span class="pre">server</span></span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.server" title="Link to this definition">¶</a></dt>
  239. <dd><p>Contains the server instance.</p>
  240. </dd></dl>
  241. <dl class="py attribute">
  242. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.close_connection">
  243. <span class="sig-name descname"><span class="pre">close_connection</span></span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.close_connection" title="Link to this definition">¶</a></dt>
  244. <dd><p>Boolean that should be set before <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.handle_one_request" title="http.server.BaseHTTPRequestHandler.handle_one_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">handle_one_request()</span></code></a> returns,
  245. indicating if another request may be expected, or if the connection should
  246. be shut down.</p>
  247. </dd></dl>
  248. <dl class="py attribute">
  249. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.requestline">
  250. <span class="sig-name descname"><span class="pre">requestline</span></span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.requestline" title="Link to this definition">¶</a></dt>
  251. <dd><p>Contains the string representation of the HTTP request line. The
  252. terminating CRLF is stripped. This attribute should be set by
  253. <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.handle_one_request" title="http.server.BaseHTTPRequestHandler.handle_one_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">handle_one_request()</span></code></a>. If no valid request line was processed, it
  254. should be set to the empty string.</p>
  255. </dd></dl>
  256. <dl class="py attribute">
  257. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.command">
  258. <span class="sig-name descname"><span class="pre">command</span></span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.command" title="Link to this definition">¶</a></dt>
  259. <dd><p>Contains the command (request type). For example, <code class="docutils literal notranslate"><span class="pre">'GET'</span></code>.</p>
  260. </dd></dl>
  261. <dl class="py attribute">
  262. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.path">
  263. <span class="sig-name descname"><span class="pre">path</span></span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.path" title="Link to this definition">¶</a></dt>
  264. <dd><p>Contains the request path. If query component of the URL is present,
  265. then <code class="docutils literal notranslate"><span class="pre">path</span></code> includes the query. Using the terminology of <span class="target" id="index-1"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc3986.html"><strong>RFC 3986</strong></a>,
  266. <code class="docutils literal notranslate"><span class="pre">path</span></code> here includes <code class="docutils literal notranslate"><span class="pre">hier-part</span></code> and the <code class="docutils literal notranslate"><span class="pre">query</span></code>.</p>
  267. </dd></dl>
  268. <dl class="py attribute">
  269. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.request_version">
  270. <span class="sig-name descname"><span class="pre">request_version</span></span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.request_version" title="Link to this definition">¶</a></dt>
  271. <dd><p>Contains the version string from the request. For example, <code class="docutils literal notranslate"><span class="pre">'HTTP/1.0'</span></code>.</p>
  272. </dd></dl>
  273. <dl class="py attribute">
  274. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.headers">
  275. <span class="sig-name descname"><span class="pre">headers</span></span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.headers" title="Link to this definition">¶</a></dt>
  276. <dd><p>Holds an instance of the class specified by the <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.MessageClass" title="http.server.BaseHTTPRequestHandler.MessageClass"><code class="xref py py-attr docutils literal notranslate"><span class="pre">MessageClass</span></code></a> class
  277. variable. This instance parses and manages the headers in the HTTP
  278. request. The <a class="reference internal" href="http.client.html#http.client.parse_headers" title="http.client.parse_headers"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse_headers()</span></code></a> function from
  279. <a class="reference internal" href="http.client.html#module-http.client" title="http.client: HTTP and HTTPS protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.client</span></code></a> is used to parse the headers and it requires that the
  280. HTTP request provide a valid <span class="target" id="index-2"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc2822.html"><strong>RFC 2822</strong></a> style header.</p>
  281. </dd></dl>
  282. <dl class="py attribute">
  283. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.rfile">
  284. <span class="sig-name descname"><span class="pre">rfile</span></span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.rfile" title="Link to this definition">¶</a></dt>
  285. <dd><p>An <a class="reference internal" href="io.html#io.BufferedIOBase" title="io.BufferedIOBase"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.BufferedIOBase</span></code></a> input stream, ready to read from
  286. the start of the optional input data.</p>
  287. </dd></dl>
  288. <dl class="py attribute">
  289. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.wfile">
  290. <span class="sig-name descname"><span class="pre">wfile</span></span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.wfile" title="Link to this definition">¶</a></dt>
  291. <dd><p>Contains the output stream for writing a response back to the
  292. client. Proper adherence to the HTTP protocol must be used when writing to
  293. this stream in order to achieve successful interoperation with HTTP
  294. clients.</p>
  295. <div class="versionchanged">
  296. <p><span class="versionmodified changed">Changed in version 3.6: </span>This is an <a class="reference internal" href="io.html#io.BufferedIOBase" title="io.BufferedIOBase"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.BufferedIOBase</span></code></a> stream.</p>
  297. </div>
  298. </dd></dl>
  299. <p><a class="reference internal" href="#http.server.BaseHTTPRequestHandler" title="http.server.BaseHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseHTTPRequestHandler</span></code></a> has the following attributes:</p>
  300. <dl class="py attribute">
  301. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.server_version">
  302. <span class="sig-name descname"><span class="pre">server_version</span></span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.server_version" title="Link to this definition">¶</a></dt>
  303. <dd><p>Specifies the server software version. You may want to override this. The
  304. format is multiple whitespace-separated strings, where each string is of
  305. the form name[/version]. For example, <code class="docutils literal notranslate"><span class="pre">'BaseHTTP/0.2'</span></code>.</p>
  306. </dd></dl>
  307. <dl class="py attribute">
  308. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.sys_version">
  309. <span class="sig-name descname"><span class="pre">sys_version</span></span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.sys_version" title="Link to this definition">¶</a></dt>
  310. <dd><p>Contains the Python system version, in a form usable by the
  311. <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.version_string" title="http.server.BaseHTTPRequestHandler.version_string"><code class="xref py py-attr docutils literal notranslate"><span class="pre">version_string</span></code></a> method and the <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.server_version" title="http.server.BaseHTTPRequestHandler.server_version"><code class="xref py py-attr docutils literal notranslate"><span class="pre">server_version</span></code></a> class
  312. variable. For example, <code class="docutils literal notranslate"><span class="pre">'Python/1.4'</span></code>.</p>
  313. </dd></dl>
  314. <dl class="py attribute">
  315. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.error_message_format">
  316. <span class="sig-name descname"><span class="pre">error_message_format</span></span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.error_message_format" title="Link to this definition">¶</a></dt>
  317. <dd><p>Specifies a format string that should be used by <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.send_error" title="http.server.BaseHTTPRequestHandler.send_error"><code class="xref py py-meth docutils literal notranslate"><span class="pre">send_error()</span></code></a> method
  318. for building an error response to the client. The string is filled by
  319. default with variables from <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.responses" title="http.server.BaseHTTPRequestHandler.responses"><code class="xref py py-attr docutils literal notranslate"><span class="pre">responses</span></code></a> based on the status code
  320. that passed to <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.send_error" title="http.server.BaseHTTPRequestHandler.send_error"><code class="xref py py-meth docutils literal notranslate"><span class="pre">send_error()</span></code></a>.</p>
  321. </dd></dl>
  322. <dl class="py attribute">
  323. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.error_content_type">
  324. <span class="sig-name descname"><span class="pre">error_content_type</span></span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.error_content_type" title="Link to this definition">¶</a></dt>
  325. <dd><p>Specifies the Content-Type HTTP header of error responses sent to the
  326. client. The default value is <code class="docutils literal notranslate"><span class="pre">'text/html'</span></code>.</p>
  327. </dd></dl>
  328. <dl class="py attribute">
  329. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.protocol_version">
  330. <span class="sig-name descname"><span class="pre">protocol_version</span></span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.protocol_version" title="Link to this definition">¶</a></dt>
  331. <dd><p>Specifies the HTTP version to which the server is conformant. It is sent
  332. in responses to let the client know the server’s communication
  333. capabilities for future requests. If set to
  334. <code class="docutils literal notranslate"><span class="pre">'HTTP/1.1'</span></code>, the server will permit HTTP persistent connections;
  335. however, your server <em>must</em> then include an accurate <code class="docutils literal notranslate"><span class="pre">Content-Length</span></code>
  336. header (using <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.send_header" title="http.server.BaseHTTPRequestHandler.send_header"><code class="xref py py-meth docutils literal notranslate"><span class="pre">send_header()</span></code></a>) in all of its responses to clients.
  337. For backwards compatibility, the setting defaults to <code class="docutils literal notranslate"><span class="pre">'HTTP/1.0'</span></code>.</p>
  338. </dd></dl>
  339. <dl class="py attribute">
  340. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.MessageClass">
  341. <span class="sig-name descname"><span class="pre">MessageClass</span></span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.MessageClass" title="Link to this definition">¶</a></dt>
  342. <dd><p>Specifies an <a class="reference internal" href="email.compat32-message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">email.message.Message</span></code></a>-like class to parse HTTP
  343. headers. Typically, this is not overridden, and it defaults to
  344. <a class="reference internal" href="http.client.html#http.client.HTTPMessage" title="http.client.HTTPMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">http.client.HTTPMessage</span></code></a>.</p>
  345. </dd></dl>
  346. <dl class="py attribute">
  347. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.responses">
  348. <span class="sig-name descname"><span class="pre">responses</span></span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.responses" title="Link to this definition">¶</a></dt>
  349. <dd><p>This attribute contains a mapping of error code integers to two-element tuples
  350. containing a short and long message. For example, <code class="docutils literal notranslate"><span class="pre">{code:</span> <span class="pre">(shortmessage,</span>
  351. <span class="pre">longmessage)}</span></code>. The <em>shortmessage</em> is usually used as the <em>message</em> key in an
  352. error response, and <em>longmessage</em> as the <em>explain</em> key. It is used by
  353. <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.send_response_only" title="http.server.BaseHTTPRequestHandler.send_response_only"><code class="xref py py-meth docutils literal notranslate"><span class="pre">send_response_only()</span></code></a> and <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.send_error" title="http.server.BaseHTTPRequestHandler.send_error"><code class="xref py py-meth docutils literal notranslate"><span class="pre">send_error()</span></code></a> methods.</p>
  354. </dd></dl>
  355. <p>A <a class="reference internal" href="#http.server.BaseHTTPRequestHandler" title="http.server.BaseHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseHTTPRequestHandler</span></code></a> instance has the following methods:</p>
  356. <dl class="py method">
  357. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.handle">
  358. <span class="sig-name descname"><span class="pre">handle</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.handle" title="Link to this definition">¶</a></dt>
  359. <dd><p>Calls <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.handle_one_request" title="http.server.BaseHTTPRequestHandler.handle_one_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">handle_one_request()</span></code></a> once (or, if persistent connections are
  360. enabled, multiple times) to handle incoming HTTP requests. You should
  361. never need to override it; instead, implement appropriate <code class="xref py py-meth docutils literal notranslate"><span class="pre">do_*()</span></code>
  362. methods.</p>
  363. </dd></dl>
  364. <dl class="py method">
  365. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.handle_one_request">
  366. <span class="sig-name descname"><span class="pre">handle_one_request</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.handle_one_request" title="Link to this definition">¶</a></dt>
  367. <dd><p>This method will parse and dispatch the request to the appropriate
  368. <code class="xref py py-meth docutils literal notranslate"><span class="pre">do_*()</span></code> method. You should never need to override it.</p>
  369. </dd></dl>
  370. <dl class="py method">
  371. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.handle_expect_100">
  372. <span class="sig-name descname"><span class="pre">handle_expect_100</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.handle_expect_100" title="Link to this definition">¶</a></dt>
  373. <dd><p>When an HTTP/1.1 conformant server receives an <code class="docutils literal notranslate"><span class="pre">Expect:</span> <span class="pre">100-continue</span></code>
  374. request header it responds back with a <code class="docutils literal notranslate"><span class="pre">100</span> <span class="pre">Continue</span></code> followed by <code class="docutils literal notranslate"><span class="pre">200</span>
  375. <span class="pre">OK</span></code> headers.
  376. This method can be overridden to raise an error if the server does not
  377. want the client to continue. For e.g. server can choose to send <code class="docutils literal notranslate"><span class="pre">417</span>
  378. <span class="pre">Expectation</span> <span class="pre">Failed</span></code> as a response header and <code class="docutils literal notranslate"><span class="pre">return</span> <span class="pre">False</span></code>.</p>
  379. <div class="versionadded">
  380. <p><span class="versionmodified added">New in version 3.2.</span></p>
  381. </div>
  382. </dd></dl>
  383. <dl class="py method">
  384. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.send_error">
  385. <span class="sig-name descname"><span class="pre">send_error</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">message</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">explain</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.send_error" title="Link to this definition">¶</a></dt>
  386. <dd><p>Sends and logs a complete error reply to the client. The numeric <em>code</em>
  387. specifies the HTTP error code, with <em>message</em> as an optional, short, human
  388. readable description of the error. The <em>explain</em> argument can be used to
  389. provide more detailed information about the error; it will be formatted
  390. using the <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.error_message_format" title="http.server.BaseHTTPRequestHandler.error_message_format"><code class="xref py py-attr docutils literal notranslate"><span class="pre">error_message_format</span></code></a> attribute and emitted, after
  391. a complete set of headers, as the response body. The <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.responses" title="http.server.BaseHTTPRequestHandler.responses"><code class="xref py py-attr docutils literal notranslate"><span class="pre">responses</span></code></a>
  392. attribute holds the default values for <em>message</em> and <em>explain</em> that
  393. will be used if no value is provided; for unknown codes the default value
  394. for both is the string <code class="docutils literal notranslate"><span class="pre">???</span></code>. The body will be empty if the method is
  395. HEAD or the response code is one of the following: <code class="samp docutils literal notranslate"><span class="pre">1</span><em><span class="pre">xx</span></em></code>,
  396. <code class="docutils literal notranslate"><span class="pre">204</span> <span class="pre">No</span> <span class="pre">Content</span></code>, <code class="docutils literal notranslate"><span class="pre">205</span> <span class="pre">Reset</span> <span class="pre">Content</span></code>, <code class="docutils literal notranslate"><span class="pre">304</span> <span class="pre">Not</span> <span class="pre">Modified</span></code>.</p>
  397. <div class="versionchanged">
  398. <p><span class="versionmodified changed">Changed in version 3.4: </span>The error response includes a Content-Length header.
  399. Added the <em>explain</em> argument.</p>
  400. </div>
  401. </dd></dl>
  402. <dl class="py method">
  403. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.send_response">
  404. <span class="sig-name descname"><span class="pre">send_response</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">message</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.send_response" title="Link to this definition">¶</a></dt>
  405. <dd><p>Adds a response header to the headers buffer and logs the accepted
  406. request. The HTTP response line is written to the internal buffer,
  407. followed by <em>Server</em> and <em>Date</em> headers. The values for these two headers
  408. are picked up from the <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.version_string" title="http.server.BaseHTTPRequestHandler.version_string"><code class="xref py py-meth docutils literal notranslate"><span class="pre">version_string()</span></code></a> and
  409. <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.date_time_string" title="http.server.BaseHTTPRequestHandler.date_time_string"><code class="xref py py-meth docutils literal notranslate"><span class="pre">date_time_string()</span></code></a> methods, respectively. If the server does not
  410. intend to send any other headers using the <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.send_header" title="http.server.BaseHTTPRequestHandler.send_header"><code class="xref py py-meth docutils literal notranslate"><span class="pre">send_header()</span></code></a> method,
  411. then <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.send_response" title="http.server.BaseHTTPRequestHandler.send_response"><code class="xref py py-meth docutils literal notranslate"><span class="pre">send_response()</span></code></a> should be followed by an <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.end_headers" title="http.server.BaseHTTPRequestHandler.end_headers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">end_headers()</span></code></a>
  412. call.</p>
  413. <div class="versionchanged">
  414. <p><span class="versionmodified changed">Changed in version 3.3: </span>Headers are stored to an internal buffer and <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.end_headers" title="http.server.BaseHTTPRequestHandler.end_headers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">end_headers()</span></code></a>
  415. needs to be called explicitly.</p>
  416. </div>
  417. </dd></dl>
  418. <dl class="py method">
  419. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.send_header">
  420. <span class="sig-name descname"><span class="pre">send_header</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">keyword</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">value</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.send_header" title="Link to this definition">¶</a></dt>
  421. <dd><p>Adds the HTTP header to an internal buffer which will be written to the
  422. output stream when either <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.end_headers" title="http.server.BaseHTTPRequestHandler.end_headers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">end_headers()</span></code></a> or <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.flush_headers" title="http.server.BaseHTTPRequestHandler.flush_headers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">flush_headers()</span></code></a> is
  423. invoked. <em>keyword</em> should specify the header keyword, with <em>value</em>
  424. specifying its value. Note that, after the send_header calls are done,
  425. <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.end_headers" title="http.server.BaseHTTPRequestHandler.end_headers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">end_headers()</span></code></a> MUST BE called in order to complete the operation.</p>
  426. <div class="versionchanged">
  427. <p><span class="versionmodified changed">Changed in version 3.2: </span>Headers are stored in an internal buffer.</p>
  428. </div>
  429. </dd></dl>
  430. <dl class="py method">
  431. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.send_response_only">
  432. <span class="sig-name descname"><span class="pre">send_response_only</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">message</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.send_response_only" title="Link to this definition">¶</a></dt>
  433. <dd><p>Sends the response header only, used for the purposes when <code class="docutils literal notranslate"><span class="pre">100</span>
  434. <span class="pre">Continue</span></code> response is sent by the server to the client. The headers not
  435. buffered and sent directly the output stream.If the <em>message</em> is not
  436. specified, the HTTP message corresponding the response <em>code</em> is sent.</p>
  437. <div class="versionadded">
  438. <p><span class="versionmodified added">New in version 3.2.</span></p>
  439. </div>
  440. </dd></dl>
  441. <dl class="py method">
  442. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.end_headers">
  443. <span class="sig-name descname"><span class="pre">end_headers</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.end_headers" title="Link to this definition">¶</a></dt>
  444. <dd><p>Adds a blank line
  445. (indicating the end of the HTTP headers in the response)
  446. to the headers buffer and calls <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.flush_headers" title="http.server.BaseHTTPRequestHandler.flush_headers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">flush_headers()</span></code></a>.</p>
  447. <div class="versionchanged">
  448. <p><span class="versionmodified changed">Changed in version 3.2: </span>The buffered headers are written to the output stream.</p>
  449. </div>
  450. </dd></dl>
  451. <dl class="py method">
  452. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.flush_headers">
  453. <span class="sig-name descname"><span class="pre">flush_headers</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.flush_headers" title="Link to this definition">¶</a></dt>
  454. <dd><p>Finally send the headers to the output stream and flush the internal
  455. headers buffer.</p>
  456. <div class="versionadded">
  457. <p><span class="versionmodified added">New in version 3.3.</span></p>
  458. </div>
  459. </dd></dl>
  460. <dl class="py method">
  461. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.log_request">
  462. <span class="sig-name descname"><span class="pre">log_request</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'-'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">size</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'-'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.log_request" title="Link to this definition">¶</a></dt>
  463. <dd><p>Logs an accepted (successful) request. <em>code</em> should specify the numeric
  464. HTTP code associated with the response. If a size of the response is
  465. available, then it should be passed as the <em>size</em> parameter.</p>
  466. </dd></dl>
  467. <dl class="py method">
  468. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.log_error">
  469. <span class="sig-name descname"><span class="pre">log_error</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">...</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.log_error" title="Link to this definition">¶</a></dt>
  470. <dd><p>Logs an error when a request cannot be fulfilled. By default, it passes
  471. the message to <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.log_message" title="http.server.BaseHTTPRequestHandler.log_message"><code class="xref py py-meth docutils literal notranslate"><span class="pre">log_message()</span></code></a>, so it takes the same arguments
  472. (<em>format</em> and additional values).</p>
  473. </dd></dl>
  474. <dl class="py method">
  475. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.log_message">
  476. <span class="sig-name descname"><span class="pre">log_message</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">format</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">...</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.log_message" title="Link to this definition">¶</a></dt>
  477. <dd><p>Logs an arbitrary message to <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code>. This is typically overridden
  478. to create custom error logging mechanisms. The <em>format</em> argument is a
  479. standard printf-style format string, where the additional arguments to
  480. <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.log_message" title="http.server.BaseHTTPRequestHandler.log_message"><code class="xref py py-meth docutils literal notranslate"><span class="pre">log_message()</span></code></a> are applied as inputs to the formatting. The client
  481. ip address and current date and time are prefixed to every message logged.</p>
  482. </dd></dl>
  483. <dl class="py method">
  484. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.version_string">
  485. <span class="sig-name descname"><span class="pre">version_string</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.version_string" title="Link to this definition">¶</a></dt>
  486. <dd><p>Returns the server software’s version string. This is a combination of the
  487. <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.server_version" title="http.server.BaseHTTPRequestHandler.server_version"><code class="xref py py-attr docutils literal notranslate"><span class="pre">server_version</span></code></a> and <a class="reference internal" href="#http.server.BaseHTTPRequestHandler.sys_version" title="http.server.BaseHTTPRequestHandler.sys_version"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys_version</span></code></a> attributes.</p>
  488. </dd></dl>
  489. <dl class="py method">
  490. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.date_time_string">
  491. <span class="sig-name descname"><span class="pre">date_time_string</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">timestamp</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.date_time_string" title="Link to this definition">¶</a></dt>
  492. <dd><p>Returns the date and time given by <em>timestamp</em> (which must be <code class="docutils literal notranslate"><span class="pre">None</span></code> or in
  493. the format returned by <a class="reference internal" href="time.html#time.time" title="time.time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.time()</span></code></a>), formatted for a message
  494. header. If <em>timestamp</em> is omitted, it uses the current date and time.</p>
  495. <p>The result looks like <code class="docutils literal notranslate"><span class="pre">'Sun,</span> <span class="pre">06</span> <span class="pre">Nov</span> <span class="pre">1994</span> <span class="pre">08:49:37</span> <span class="pre">GMT'</span></code>.</p>
  496. </dd></dl>
  497. <dl class="py method">
  498. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.log_date_time_string">
  499. <span class="sig-name descname"><span class="pre">log_date_time_string</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.log_date_time_string" title="Link to this definition">¶</a></dt>
  500. <dd><p>Returns the current date and time, formatted for logging.</p>
  501. </dd></dl>
  502. <dl class="py method">
  503. <dt class="sig sig-object py" id="http.server.BaseHTTPRequestHandler.address_string">
  504. <span class="sig-name descname"><span class="pre">address_string</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#http.server.BaseHTTPRequestHandler.address_string" title="Link to this definition">¶</a></dt>
  505. <dd><p>Returns the client address.</p>
  506. <div class="versionchanged">
  507. <p><span class="versionmodified changed">Changed in version 3.3: </span>Previously, a name lookup was performed. To avoid name resolution
  508. delays, it now always returns the IP address.</p>
  509. </div>
  510. </dd></dl>
  511. </dd></dl>
  512. <dl class="py class">
  513. <dt class="sig sig-object py" id="http.server.SimpleHTTPRequestHandler">
  514. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">http.server.</span></span><span class="sig-name descname"><span class="pre">SimpleHTTPRequestHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">request</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">client_address</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">server</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">directory</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#http.server.SimpleHTTPRequestHandler" title="Link to this definition">¶</a></dt>
  515. <dd><p>This class serves files from the directory <em>directory</em> and below,
  516. or the current directory if <em>directory</em> is not provided, directly
  517. mapping the directory structure to HTTP requests.</p>
  518. <div class="versionchanged">
  519. <p><span class="versionmodified changed">Changed in version 3.7: </span>Added the <em>directory</em> parameter.</p>
  520. </div>
  521. <div class="versionchanged">
  522. <p><span class="versionmodified changed">Changed in version 3.9: </span>The <em>directory</em> parameter accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
  523. </div>
  524. <p>A lot of the work, such as parsing the request, is done by the base class
  525. <a class="reference internal" href="#http.server.BaseHTTPRequestHandler" title="http.server.BaseHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseHTTPRequestHandler</span></code></a>. This class implements the <a class="reference internal" href="#http.server.SimpleHTTPRequestHandler.do_GET" title="http.server.SimpleHTTPRequestHandler.do_GET"><code class="xref py py-func docutils literal notranslate"><span class="pre">do_GET()</span></code></a>
  526. and <a class="reference internal" href="#http.server.SimpleHTTPRequestHandler.do_HEAD" title="http.server.SimpleHTTPRequestHandler.do_HEAD"><code class="xref py py-func docutils literal notranslate"><span class="pre">do_HEAD()</span></code></a> functions.</p>
  527. <p>The following are defined as class-level attributes of
  528. <a class="reference internal" href="#http.server.SimpleHTTPRequestHandler" title="http.server.SimpleHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleHTTPRequestHandler</span></code></a>:</p>
  529. <dl class="py attribute">
  530. <dt class="sig sig-object py" id="http.server.SimpleHTTPRequestHandler.server_version">
  531. <span class="sig-name descname"><span class="pre">server_version</span></span><a class="headerlink" href="#http.server.SimpleHTTPRequestHandler.server_version" title="Link to this definition">¶</a></dt>
  532. <dd><p>This will be <code class="docutils literal notranslate"><span class="pre">&quot;SimpleHTTP/&quot;</span> <span class="pre">+</span> <span class="pre">__version__</span></code>, where <code class="docutils literal notranslate"><span class="pre">__version__</span></code> is
  533. defined at the module level.</p>
  534. </dd></dl>
  535. <dl class="py attribute">
  536. <dt class="sig sig-object py" id="http.server.SimpleHTTPRequestHandler.extensions_map">
  537. <span class="sig-name descname"><span class="pre">extensions_map</span></span><a class="headerlink" href="#http.server.SimpleHTTPRequestHandler.extensions_map" title="Link to this definition">¶</a></dt>
  538. <dd><p>A dictionary mapping suffixes into MIME types, contains custom overrides
  539. for the default system mappings. The mapping is used case-insensitively,
  540. and so should contain only lower-cased keys.</p>
  541. <div class="versionchanged">
  542. <p><span class="versionmodified changed">Changed in version 3.9: </span>This dictionary is no longer filled with the default system mappings,
  543. but only contains overrides.</p>
  544. </div>
  545. </dd></dl>
  546. <p>The <a class="reference internal" href="#http.server.SimpleHTTPRequestHandler" title="http.server.SimpleHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleHTTPRequestHandler</span></code></a> class defines the following methods:</p>
  547. <dl class="py method">
  548. <dt class="sig sig-object py" id="http.server.SimpleHTTPRequestHandler.do_HEAD">
  549. <span class="sig-name descname"><span class="pre">do_HEAD</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#http.server.SimpleHTTPRequestHandler.do_HEAD" title="Link to this definition">¶</a></dt>
  550. <dd><p>This method serves the <code class="docutils literal notranslate"><span class="pre">'HEAD'</span></code> request type: it sends the headers it
  551. would send for the equivalent <code class="docutils literal notranslate"><span class="pre">GET</span></code> request. See the <a class="reference internal" href="#http.server.SimpleHTTPRequestHandler.do_GET" title="http.server.SimpleHTTPRequestHandler.do_GET"><code class="xref py py-meth docutils literal notranslate"><span class="pre">do_GET()</span></code></a>
  552. method for a more complete explanation of the possible headers.</p>
  553. </dd></dl>
  554. <dl class="py method">
  555. <dt class="sig sig-object py" id="http.server.SimpleHTTPRequestHandler.do_GET">
  556. <span class="sig-name descname"><span class="pre">do_GET</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#http.server.SimpleHTTPRequestHandler.do_GET" title="Link to this definition">¶</a></dt>
  557. <dd><p>The request is mapped to a local file by interpreting the request as a
  558. path relative to the current working directory.</p>
  559. <p>If the request was mapped to a directory, the directory is checked for a
  560. file named <code class="docutils literal notranslate"><span class="pre">index.html</span></code> or <code class="docutils literal notranslate"><span class="pre">index.htm</span></code> (in that order). If found, the
  561. file’s contents are returned; otherwise a directory listing is generated
  562. by calling the <code class="xref py py-meth docutils literal notranslate"><span class="pre">list_directory()</span></code> method. This method uses
  563. <a class="reference internal" href="os.html#os.listdir" title="os.listdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.listdir()</span></code></a> to scan the directory, and returns a <code class="docutils literal notranslate"><span class="pre">404</span></code> error
  564. response if the <a class="reference internal" href="os.html#os.listdir" title="os.listdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">listdir()</span></code></a> fails.</p>
  565. <p>If the request was mapped to a file, it is opened. Any <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>
  566. exception in opening the requested file is mapped to a <code class="docutils literal notranslate"><span class="pre">404</span></code>,
  567. <code class="docutils literal notranslate"><span class="pre">'File</span> <span class="pre">not</span> <span class="pre">found'</span></code> error. If there was a <code class="docutils literal notranslate"><span class="pre">'If-Modified-Since'</span></code>
  568. header in the request, and the file was not modified after this time,
  569. a <code class="docutils literal notranslate"><span class="pre">304</span></code>, <code class="docutils literal notranslate"><span class="pre">'Not</span> <span class="pre">Modified'</span></code> response is sent. Otherwise, the content
  570. type is guessed by calling the <code class="xref py py-meth docutils literal notranslate"><span class="pre">guess_type()</span></code> method, which in turn
  571. uses the <em>extensions_map</em> variable, and the file contents are returned.</p>
  572. <p>A <code class="docutils literal notranslate"><span class="pre">'Content-type:'</span></code> header with the guessed content type is output,
  573. followed by a <code class="docutils literal notranslate"><span class="pre">'Content-Length:'</span></code> header with the file’s size and a
  574. <code class="docutils literal notranslate"><span class="pre">'Last-Modified:'</span></code> header with the file’s modification time.</p>
  575. <p>Then follows a blank line signifying the end of the headers, and then the
  576. contents of the file are output. If the file’s MIME type starts with
  577. <code class="docutils literal notranslate"><span class="pre">text/</span></code> the file is opened in text mode; otherwise binary mode is used.</p>
  578. <p>For example usage, see the implementation of the <code class="docutils literal notranslate"><span class="pre">test</span></code> function
  579. in <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/http/server.py">Lib/http/server.py</a>.</p>
  580. <div class="versionchanged">
  581. <p><span class="versionmodified changed">Changed in version 3.7: </span>Support of the <code class="docutils literal notranslate"><span class="pre">'If-Modified-Since'</span></code> header.</p>
  582. </div>
  583. </dd></dl>
  584. </dd></dl>
  585. <p>The <a class="reference internal" href="#http.server.SimpleHTTPRequestHandler" title="http.server.SimpleHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleHTTPRequestHandler</span></code></a> class can be used in the following
  586. manner in order to create a very basic webserver serving files relative to
  587. the current directory:</p>
  588. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">http.server</span>
  589. <span class="kn">import</span> <span class="nn">socketserver</span>
  590. <span class="n">PORT</span> <span class="o">=</span> <span class="mi">8000</span>
  591. <span class="n">Handler</span> <span class="o">=</span> <span class="n">http</span><span class="o">.</span><span class="n">server</span><span class="o">.</span><span class="n">SimpleHTTPRequestHandler</span>
  592. <span class="k">with</span> <span class="n">socketserver</span><span class="o">.</span><span class="n">TCPServer</span><span class="p">((</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">PORT</span><span class="p">),</span> <span class="n">Handler</span><span class="p">)</span> <span class="k">as</span> <span class="n">httpd</span><span class="p">:</span>
  593. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;serving at port&quot;</span><span class="p">,</span> <span class="n">PORT</span><span class="p">)</span>
  594. <span class="n">httpd</span><span class="o">.</span><span class="n">serve_forever</span><span class="p">()</span>
  595. </pre></div>
  596. </div>
  597. <p><a class="reference internal" href="#http.server.SimpleHTTPRequestHandler" title="http.server.SimpleHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleHTTPRequestHandler</span></code></a> can also be subclassed to enhance behavior,
  598. such as using different index file names by overriding the class attribute
  599. <code class="xref py py-attr docutils literal notranslate"><span class="pre">index_pages</span></code>.</p>
  600. <p id="http-server-cli"><a class="reference internal" href="#module-http.server" title="http.server: HTTP server and request handlers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.server</span></code></a> can also be invoked directly using the <a class="reference internal" href="../using/cmdline.html#cmdoption-m"><code class="xref std std-option docutils literal notranslate"><span class="pre">-m</span></code></a>
  601. switch of the interpreter. Similar to
  602. the previous example, this serves files relative to the current directory:</p>
  603. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="o">-</span><span class="n">m</span> <span class="n">http</span><span class="o">.</span><span class="n">server</span>
  604. </pre></div>
  605. </div>
  606. <p>The server listens to port 8000 by default. The default can be overridden
  607. by passing the desired port number as an argument:</p>
  608. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="o">-</span><span class="n">m</span> <span class="n">http</span><span class="o">.</span><span class="n">server</span> <span class="mi">9000</span>
  609. </pre></div>
  610. </div>
  611. <p>By default, the server binds itself to all interfaces. The option <code class="docutils literal notranslate"><span class="pre">-b/--bind</span></code>
  612. specifies a specific address to which it should bind. Both IPv4 and IPv6
  613. addresses are supported. For example, the following command causes the server
  614. to bind to localhost only:</p>
  615. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="o">-</span><span class="n">m</span> <span class="n">http</span><span class="o">.</span><span class="n">server</span> <span class="o">--</span><span class="n">bind</span> <span class="mf">127.0.0.1</span>
  616. </pre></div>
  617. </div>
  618. <div class="versionchanged">
  619. <p><span class="versionmodified changed">Changed in version 3.4: </span>Added the <code class="docutils literal notranslate"><span class="pre">--bind</span></code> option.</p>
  620. </div>
  621. <div class="versionchanged">
  622. <p><span class="versionmodified changed">Changed in version 3.8: </span>Support IPv6 in the <code class="docutils literal notranslate"><span class="pre">--bind</span></code> option.</p>
  623. </div>
  624. <p>By default, the server uses the current directory. The option <code class="docutils literal notranslate"><span class="pre">-d/--directory</span></code>
  625. specifies a directory to which it should serve the files. For example,
  626. the following command uses a specific directory:</p>
  627. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="o">-</span><span class="n">m</span> <span class="n">http</span><span class="o">.</span><span class="n">server</span> <span class="o">--</span><span class="n">directory</span> <span class="o">/</span><span class="n">tmp</span><span class="o">/</span>
  628. </pre></div>
  629. </div>
  630. <div class="versionchanged">
  631. <p><span class="versionmodified changed">Changed in version 3.7: </span>Added the <code class="docutils literal notranslate"><span class="pre">--directory</span></code> option.</p>
  632. </div>
  633. <p>By default, the server is conformant to HTTP/1.0. The option <code class="docutils literal notranslate"><span class="pre">-p/--protocol</span></code>
  634. specifies the HTTP version to which the server is conformant. For example, the
  635. following command runs an HTTP/1.1 conformant server:</p>
  636. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="o">-</span><span class="n">m</span> <span class="n">http</span><span class="o">.</span><span class="n">server</span> <span class="o">--</span><span class="n">protocol</span> <span class="n">HTTP</span><span class="o">/</span><span class="mf">1.1</span>
  637. </pre></div>
  638. </div>
  639. <div class="versionchanged">
  640. <p><span class="versionmodified changed">Changed in version 3.11: </span>Added the <code class="docutils literal notranslate"><span class="pre">--protocol</span></code> option.</p>
  641. </div>
  642. <dl class="py class">
  643. <dt class="sig sig-object py" id="http.server.CGIHTTPRequestHandler">
  644. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">http.server.</span></span><span class="sig-name descname"><span class="pre">CGIHTTPRequestHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">request</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">client_address</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">server</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#http.server.CGIHTTPRequestHandler" title="Link to this definition">¶</a></dt>
  645. <dd><p>This class is used to serve either files or output of CGI scripts from the
  646. current directory and below. Note that mapping HTTP hierarchic structure to
  647. local directory structure is exactly as in <a class="reference internal" href="#http.server.SimpleHTTPRequestHandler" title="http.server.SimpleHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleHTTPRequestHandler</span></code></a>.</p>
  648. <div class="admonition note">
  649. <p class="admonition-title">Note</p>
  650. <p>CGI scripts run by the <a class="reference internal" href="#http.server.CGIHTTPRequestHandler" title="http.server.CGIHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CGIHTTPRequestHandler</span></code></a> class cannot execute
  651. redirects (HTTP code 302), because code 200 (script output follows) is
  652. sent prior to execution of the CGI script. This pre-empts the status
  653. code.</p>
  654. </div>
  655. <p>The class will however, run the CGI script, instead of serving it as a file,
  656. if it guesses it to be a CGI script. Only directory-based CGI are used —
  657. the other common server configuration is to treat special extensions as
  658. denoting CGI scripts.</p>
  659. <p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">do_GET()</span></code> and <code class="xref py py-func docutils literal notranslate"><span class="pre">do_HEAD()</span></code> functions are modified to run CGI scripts
  660. and serve the output, instead of serving files, if the request leads to
  661. somewhere below the <code class="docutils literal notranslate"><span class="pre">cgi_directories</span></code> path.</p>
  662. <p>The <a class="reference internal" href="#http.server.CGIHTTPRequestHandler" title="http.server.CGIHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CGIHTTPRequestHandler</span></code></a> defines the following data member:</p>
  663. <dl class="py attribute">
  664. <dt class="sig sig-object py" id="http.server.CGIHTTPRequestHandler.cgi_directories">
  665. <span class="sig-name descname"><span class="pre">cgi_directories</span></span><a class="headerlink" href="#http.server.CGIHTTPRequestHandler.cgi_directories" title="Link to this definition">¶</a></dt>
  666. <dd><p>This defaults to <code class="docutils literal notranslate"><span class="pre">['/cgi-bin',</span> <span class="pre">'/htbin']</span></code> and describes directories to
  667. treat as containing CGI scripts.</p>
  668. </dd></dl>
  669. <p>The <a class="reference internal" href="#http.server.CGIHTTPRequestHandler" title="http.server.CGIHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CGIHTTPRequestHandler</span></code></a> defines the following method:</p>
  670. <dl class="py method">
  671. <dt class="sig sig-object py" id="http.server.CGIHTTPRequestHandler.do_POST">
  672. <span class="sig-name descname"><span class="pre">do_POST</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#http.server.CGIHTTPRequestHandler.do_POST" title="Link to this definition">¶</a></dt>
  673. <dd><p>This method serves the <code class="docutils literal notranslate"><span class="pre">'POST'</span></code> request type, only allowed for CGI
  674. scripts. Error 501, “Can only POST to CGI scripts”, is output when trying
  675. to POST to a non-CGI url.</p>
  676. </dd></dl>
  677. <p>Note that CGI scripts will be run with UID of user nobody, for security
  678. reasons. Problems with the CGI script will be translated to error 403.</p>
  679. </dd></dl>
  680. <p><a class="reference internal" href="#http.server.CGIHTTPRequestHandler" title="http.server.CGIHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CGIHTTPRequestHandler</span></code></a> can be enabled in the command line by passing
  681. the <code class="docutils literal notranslate"><span class="pre">--cgi</span></code> option:</p>
  682. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="o">-</span><span class="n">m</span> <span class="n">http</span><span class="o">.</span><span class="n">server</span> <span class="o">--</span><span class="n">cgi</span>
  683. </pre></div>
  684. </div>
  685. <div class="admonition warning">
  686. <p class="admonition-title">Warning</p>
  687. <p><a class="reference internal" href="#http.server.CGIHTTPRequestHandler" title="http.server.CGIHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CGIHTTPRequestHandler</span></code></a> and the <code class="docutils literal notranslate"><span class="pre">--cgi</span></code> command line option
  688. are not intended for use by untrusted clients and may be vulnerable
  689. to exploitation. Always use within a secure environment.</p>
  690. </div>
  691. <section id="security-considerations">
  692. <span id="http-server-security"></span><h2>Security Considerations<a class="headerlink" href="#security-considerations" title="Link to this heading">¶</a></h2>
  693. <p id="index-3"><a class="reference internal" href="#http.server.SimpleHTTPRequestHandler" title="http.server.SimpleHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleHTTPRequestHandler</span></code></a> will follow symbolic links when handling
  694. requests, this makes it possible for files outside of the specified directory
  695. to be served.</p>
  696. <p>Earlier versions of Python did not scrub control characters from the
  697. log messages emitted to stderr from <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">http.server</span></code> or the
  698. default <a class="reference internal" href="#http.server.BaseHTTPRequestHandler" title="http.server.BaseHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseHTTPRequestHandler</span></code></a> <code class="docutils literal notranslate"><span class="pre">.log_message</span></code>
  699. implementation. This could allow remote clients connecting to your
  700. server to send nefarious control codes to your terminal.</p>
  701. <div class="versionchanged">
  702. <p><span class="versionmodified changed">Changed in version 3.12: </span>Control characters are scrubbed in stderr logs.</p>
  703. </div>
  704. </section>
  705. </section>
  706. <div class="clearer"></div>
  707. </div>
  708. </div>
  709. </div>
  710. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  711. <div class="sphinxsidebarwrapper">
  712. <div>
  713. <h3><a href="../contents.html">Table of Contents</a></h3>
  714. <ul>
  715. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.server</span></code> — HTTP servers</a><ul>
  716. <li><a class="reference internal" href="#security-considerations">Security Considerations</a></li>
  717. </ul>
  718. </li>
  719. </ul>
  720. </div>
  721. <div>
  722. <h4>Previous topic</h4>
  723. <p class="topless"><a href="socketserver.html"
  724. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">socketserver</span></code> — A framework for network servers</a></p>
  725. </div>
  726. <div>
  727. <h4>Next topic</h4>
  728. <p class="topless"><a href="http.cookies.html"
  729. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.cookies</span></code> — HTTP state management</a></p>
  730. </div>
  731. <div role="note" aria-label="source link">
  732. <h3>This Page</h3>
  733. <ul class="this-page-menu">
  734. <li><a href="../bugs.html">Report a Bug</a></li>
  735. <li>
  736. <a href="https://github.com/python/cpython/blob/main/Doc/library/http.server.rst"
  737. rel="nofollow">Show Source
  738. </a>
  739. </li>
  740. </ul>
  741. </div>
  742. </div>
  743. <div id="sidebarbutton" title="Collapse sidebar">
  744. <span>«</span>
  745. </div>
  746. </div>
  747. <div class="clearer"></div>
  748. </div>
  749. <div class="related" role="navigation" aria-label="related navigation">
  750. <h3>Navigation</h3>
  751. <ul>
  752. <li class="right" style="margin-right: 10px">
  753. <a href="../genindex.html" title="General Index"
  754. >index</a></li>
  755. <li class="right" >
  756. <a href="../py-modindex.html" title="Python Module Index"
  757. >modules</a> |</li>
  758. <li class="right" >
  759. <a href="http.cookies.html" title="http.cookies — HTTP state management"
  760. >next</a> |</li>
  761. <li class="right" >
  762. <a href="socketserver.html" title="socketserver — A framework for network servers"
  763. >previous</a> |</li>
  764. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  765. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  766. <li class="switchers">
  767. <div class="language_switcher_placeholder"></div>
  768. <div class="version_switcher_placeholder"></div>
  769. </li>
  770. <li>
  771. </li>
  772. <li id="cpython-language-and-version">
  773. <a href="../index.html">3.12.3 Documentation</a> &#187;
  774. </li>
  775. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  776. <li class="nav-item nav-item-2"><a href="internet.html" >Internet Protocols and Support</a> &#187;</li>
  777. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.server</span></code> — HTTP servers</a></li>
  778. <li class="right">
  779. <div class="inline-search" role="search">
  780. <form class="inline-search" action="../search.html" method="get">
  781. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  782. <input type="submit" value="Go" />
  783. </form>
  784. </div>
  785. |
  786. </li>
  787. <li class="right">
  788. <label class="theme-selector-label">
  789. Theme
  790. <select class="theme-selector" oninput="activateTheme(this.value)">
  791. <option value="auto" selected>Auto</option>
  792. <option value="light">Light</option>
  793. <option value="dark">Dark</option>
  794. </select>
  795. </label> |</li>
  796. </ul>
  797. </div>
  798. <div class="footer">
  799. &copy;
  800. <a href="../copyright.html">
  801. Copyright
  802. </a>
  803. 2001-2024, Python Software Foundation.
  804. <br />
  805. This page is licensed under the Python Software Foundation License Version 2.
  806. <br />
  807. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  808. <br />
  809. See <a href="/license.html">History and License</a> for more information.<br />
  810. <br />
  811. The Python Software Foundation is a non-profit corporation.
  812. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  813. <br />
  814. <br />
  815. Last updated on Apr 09, 2024 (13:47 UTC).
  816. <a href="/bugs.html">Found a bug</a>?
  817. <br />
  818. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  819. </div>
  820. </body>
  821. </html>
上海开阖软件有限公司 沪ICP备12045867号-1