1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>paste.httpserver – HTTP server — Paste v1.7.5 documentation</title>
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '1.7.5',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="top" title="Paste v1.7.5 documentation" href="../index.html" />
<link rel="stylesheet" type="text/css"
href="../_static/paste.css.html">
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../index.html">Paste v1.7.5 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="module-paste.httpserver">
<span id="paste-httpserver-http-server"></span><h1><a class="reference internal" href="#module-paste.httpserver"><tt class="xref py py-mod docutils literal"><span class="pre">paste.httpserver</span></tt></a> – HTTP server<a class="headerlink" href="#module-paste.httpserver" title="Permalink to this headline">¶</a></h1>
<p>WSGI HTTP Server</p>
<p>This is a minimalistic WSGI server using Python’s built-in BaseHTTPServer;
if pyOpenSSL is installed, it also provides SSL capabilities.</p>
<div class="section" id="module-contents">
<h2>Module Contents<a class="headerlink" href="#module-contents" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="paste.httpserver.serve">
<tt class="descclassname">paste.httpserver.</tt><tt class="descname">serve</tt><big>(</big><em>application</em>, <em>host=None</em>, <em>port=None</em>, <em>handler=None</em>, <em>ssl_pem=None</em>, <em>ssl_context=None</em>, <em>server_version=None</em>, <em>protocol_version=None</em>, <em>start_loop=True</em>, <em>daemon_threads=None</em>, <em>socket_timeout=None</em>, <em>use_threadpool=None</em>, <em>threadpool_workers=10</em>, <em>threadpool_options=None</em>, <em>request_queue_size=5</em><big>)</big><a class="headerlink" href="#paste.httpserver.serve" title="Permalink to this definition">¶</a></dt>
<dd><p>Serves your <tt class="docutils literal"><span class="pre">application</span></tt> over HTTP(S) via WSGI interface</p>
<p><tt class="docutils literal"><span class="pre">host</span></tt></p>
<blockquote>
This is the ipaddress to bind to (or a hostname if your
nameserver is properly configured). This defaults to
127.0.0.1, which is not a public interface.</blockquote>
<p><tt class="docutils literal"><span class="pre">port</span></tt></p>
<blockquote>
The port to run on, defaults to 8080 for HTTP, or 4443 for
HTTPS. This can be a string or an integer value.</blockquote>
<p><tt class="docutils literal"><span class="pre">handler</span></tt></p>
<blockquote>
This is the HTTP request handler to use, it defaults to
<tt class="docutils literal"><span class="pre">WSGIHandler</span></tt> in this module.</blockquote>
<p><tt class="docutils literal"><span class="pre">ssl_pem</span></tt></p>
<blockquote>
<p>This an optional SSL certificate file (via OpenSSL). You can
supply <tt class="docutils literal"><span class="pre">*</span></tt> and a development-only certificate will be
created for you, or you can generate a self-signed test PEM
certificate file as follows:</p>
<div class="highlight-python"><pre>$ openssl genrsa 1024 > host.key
$ chmod 400 host.key
$ openssl req -new -x509 -nodes -sha1 -days 365 \
-key host.key > host.cert
$ cat host.cert host.key > host.pem
$ chmod 400 host.pem</pre>
</div>
</blockquote>
<p><tt class="docutils literal"><span class="pre">ssl_context</span></tt></p>
<blockquote>
This an optional SSL context object for the server. A SSL
context will be automatically constructed for you if you supply
<tt class="docutils literal"><span class="pre">ssl_pem</span></tt>. Supply this to use a context of your own
construction.</blockquote>
<p><tt class="docutils literal"><span class="pre">server_version</span></tt></p>
<blockquote>
The version of the server as reported in HTTP response line. This
defaults to something like “PasteWSGIServer/0.5”. Many servers
hide their code-base identity with a name like ‘Amnesiac/1.0’</blockquote>
<p><tt class="docutils literal"><span class="pre">protocol_version</span></tt></p>
<blockquote>
This sets the protocol used by the server, by default
<tt class="docutils literal"><span class="pre">HTTP/1.0</span></tt>. There is some support for <tt class="docutils literal"><span class="pre">HTTP/1.1</span></tt>, which
defaults to nicer keep-alive connections. This server supports
<tt class="docutils literal"><span class="pre">100</span> <span class="pre">Continue</span></tt>, but does not yet support HTTP/1.1 Chunked
Encoding. Hence, if you use HTTP/1.1, you’re somewhat in error
since chunked coding is a mandatory requirement of a HTTP/1.1
server. If you specify HTTP/1.1, every response <em>must</em> have a
<tt class="docutils literal"><span class="pre">Content-Length</span></tt> and you must be careful not to read past the
end of the socket.</blockquote>
<p><tt class="docutils literal"><span class="pre">start_loop</span></tt></p>
<blockquote>
This specifies if the server loop (aka <tt class="docutils literal"><span class="pre">server.serve_forever()</span></tt>)
should be called; it defaults to <tt class="xref docutils literal"><span class="pre">True</span></tt>.</blockquote>
<p><tt class="docutils literal"><span class="pre">daemon_threads</span></tt></p>
<blockquote>
This flag specifies if when your webserver terminates all
in-progress client connections should be droppped. It defaults
to <tt class="xref docutils literal"><span class="pre">False</span></tt>. You might want to set this to <tt class="xref docutils literal"><span class="pre">True</span></tt> if you
are using <tt class="docutils literal"><span class="pre">HTTP/1.1</span></tt> and don’t set a <tt class="docutils literal"><span class="pre">socket_timeout</span></tt>.</blockquote>
<p><tt class="docutils literal"><span class="pre">socket_timeout</span></tt></p>
<blockquote>
This specifies the maximum amount of time that a connection to a
given client will be kept open. At this time, it is a rude
disconnect, but at a later time it might follow the RFC a bit
more closely.</blockquote>
<p><tt class="docutils literal"><span class="pre">use_threadpool</span></tt></p>
<blockquote>
Server requests from a pool of worker threads (<tt class="docutils literal"><span class="pre">threadpool_workers</span></tt>)
rather than creating a new thread for each request. This can
substantially reduce latency since there is a high cost associated
with thread creation.</blockquote>
<p><tt class="docutils literal"><span class="pre">threadpool_workers</span></tt></p>
<blockquote>
Number of worker threads to create when <tt class="docutils literal"><span class="pre">use_threadpool</span></tt> is true. This
can be a string or an integer value.</blockquote>
<p><tt class="docutils literal"><span class="pre">threadpool_options</span></tt></p>
<blockquote>
A dictionary of options to be used when instantiating the
threadpool. See paste.httpserver.ThreadPool for specific
options (<tt class="docutils literal"><span class="pre">threadpool_workers</span></tt> is a specific option that can
also go here).</blockquote>
<p><tt class="docutils literal"><span class="pre">request_queue_size</span></tt></p>
<blockquote>
The ‘backlog’ argument to socket.listen(); specifies the
maximum number of queued connections.</blockquote>
</dd></dl>
<dl class="function">
<dt id="paste.httpserver.server_runner">
<tt class="descclassname">paste.httpserver.</tt><tt class="descname">server_runner</tt><big>(</big><em>wsgi_app</em>, <em>global_conf</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#paste.httpserver.server_runner" title="Permalink to this definition">¶</a></dt>
<dd><p>Serves your <tt class="docutils literal"><span class="pre">application</span></tt> over HTTP(S) via WSGI interface</p>
<p><tt class="docutils literal"><span class="pre">host</span></tt></p>
<blockquote>
This is the ipaddress to bind to (or a hostname if your
nameserver is properly configured). This defaults to
127.0.0.1, which is not a public interface.</blockquote>
<p><tt class="docutils literal"><span class="pre">port</span></tt></p>
<blockquote>
The port to run on, defaults to 8080 for HTTP, or 4443 for
HTTPS. This can be a string or an integer value.</blockquote>
<p><tt class="docutils literal"><span class="pre">handler</span></tt></p>
<blockquote>
This is the HTTP request handler to use, it defaults to
<tt class="docutils literal"><span class="pre">WSGIHandler</span></tt> in this module.</blockquote>
<p><tt class="docutils literal"><span class="pre">ssl_pem</span></tt></p>
<blockquote>
<p>This an optional SSL certificate file (via OpenSSL). You can
supply <tt class="docutils literal"><span class="pre">*</span></tt> and a development-only certificate will be
created for you, or you can generate a self-signed test PEM
certificate file as follows:</p>
<div class="highlight-python"><pre>$ openssl genrsa 1024 > host.key
$ chmod 400 host.key
$ openssl req -new -x509 -nodes -sha1 -days 365 \
-key host.key > host.cert
$ cat host.cert host.key > host.pem
$ chmod 400 host.pem</pre>
</div>
</blockquote>
<p><tt class="docutils literal"><span class="pre">ssl_context</span></tt></p>
<blockquote>
This an optional SSL context object for the server. A SSL
context will be automatically constructed for you if you supply
<tt class="docutils literal"><span class="pre">ssl_pem</span></tt>. Supply this to use a context of your own
construction.</blockquote>
<p><tt class="docutils literal"><span class="pre">server_version</span></tt></p>
<blockquote>
The version of the server as reported in HTTP response line. This
defaults to something like “PasteWSGIServer/0.5”. Many servers
hide their code-base identity with a name like ‘Amnesiac/1.0’</blockquote>
<p><tt class="docutils literal"><span class="pre">protocol_version</span></tt></p>
<blockquote>
This sets the protocol used by the server, by default
<tt class="docutils literal"><span class="pre">HTTP/1.0</span></tt>. There is some support for <tt class="docutils literal"><span class="pre">HTTP/1.1</span></tt>, which
defaults to nicer keep-alive connections. This server supports
<tt class="docutils literal"><span class="pre">100</span> <span class="pre">Continue</span></tt>, but does not yet support HTTP/1.1 Chunked
Encoding. Hence, if you use HTTP/1.1, you’re somewhat in error
since chunked coding is a mandatory requirement of a HTTP/1.1
server. If you specify HTTP/1.1, every response <em>must</em> have a
<tt class="docutils literal"><span class="pre">Content-Length</span></tt> and you must be careful not to read past the
end of the socket.</blockquote>
<p><tt class="docutils literal"><span class="pre">start_loop</span></tt></p>
<blockquote>
This specifies if the server loop (aka <tt class="docutils literal"><span class="pre">server.serve_forever()</span></tt>)
should be called; it defaults to <tt class="xref docutils literal"><span class="pre">True</span></tt>.</blockquote>
<p><tt class="docutils literal"><span class="pre">daemon_threads</span></tt></p>
<blockquote>
This flag specifies if when your webserver terminates all
in-progress client connections should be droppped. It defaults
to <tt class="xref docutils literal"><span class="pre">False</span></tt>. You might want to set this to <tt class="xref docutils literal"><span class="pre">True</span></tt> if you
are using <tt class="docutils literal"><span class="pre">HTTP/1.1</span></tt> and don’t set a <tt class="docutils literal"><span class="pre">socket_timeout</span></tt>.</blockquote>
<p><tt class="docutils literal"><span class="pre">socket_timeout</span></tt></p>
<blockquote>
This specifies the maximum amount of time that a connection to a
given client will be kept open. At this time, it is a rude
disconnect, but at a later time it might follow the RFC a bit
more closely.</blockquote>
<p><tt class="docutils literal"><span class="pre">use_threadpool</span></tt></p>
<blockquote>
Server requests from a pool of worker threads (<tt class="docutils literal"><span class="pre">threadpool_workers</span></tt>)
rather than creating a new thread for each request. This can
substantially reduce latency since there is a high cost associated
with thread creation.</blockquote>
<p><tt class="docutils literal"><span class="pre">threadpool_workers</span></tt></p>
<blockquote>
Number of worker threads to create when <tt class="docutils literal"><span class="pre">use_threadpool</span></tt> is true. This
can be a string or an integer value.</blockquote>
<p><tt class="docutils literal"><span class="pre">threadpool_options</span></tt></p>
<blockquote>
A dictionary of options to be used when instantiating the
threadpool. See paste.httpserver.ThreadPool for specific
options (<tt class="docutils literal"><span class="pre">threadpool_workers</span></tt> is a specific option that can
also go here).</blockquote>
<p><tt class="docutils literal"><span class="pre">request_queue_size</span></tt></p>
<blockquote>
The ‘backlog’ argument to socket.listen(); specifies the
maximum number of queued connections.</blockquote>
<p>You can also set these threadpool options:</p>
<p><tt class="docutils literal"><span class="pre">threadpool_max_requests</span></tt>:</p>
<blockquote>
The maximum number of requests a worker thread will process
before dying (and replacing itself with a new worker thread).
Default 100.</blockquote>
<p><tt class="docutils literal"><span class="pre">threadpool_hung_thread_limit</span></tt>:</p>
<blockquote>
The number of seconds a thread can work on a task before it is
considered hung (stuck). Default 30 seconds.</blockquote>
<p><tt class="docutils literal"><span class="pre">threadpool_kill_thread_limit</span></tt>:</p>
<blockquote>
The number of seconds a thread can work before you should kill it
(assuming it will never finish). Default 600 seconds (10 minutes).</blockquote>
<p><tt class="docutils literal"><span class="pre">threadpool_dying_limit</span></tt>:</p>
<blockquote>
The length of time after killing a thread that it should actually
disappear. If it lives longer than this, it is considered a
“zombie”. Note that even in easy situations killing a thread can
be very slow. Default 300 seconds (5 minutes).</blockquote>
<p><tt class="docutils literal"><span class="pre">threadpool_spawn_if_under</span></tt>:</p>
<blockquote>
If there are no idle threads and a request comes in, and there are
less than this number of <em>busy</em> threads, then add workers to the
pool. Busy threads are threads that have taken less than
<tt class="docutils literal"><span class="pre">threadpool_hung_thread_limit</span></tt> seconds so far. So if you get
<em>lots</em> of requests but they complete in a reasonable amount of time,
the requests will simply queue up (adding more threads probably
wouldn’t speed them up). But if you have lots of hung threads and
one more request comes in, this will add workers to handle it.
Default 5.</blockquote>
<p><tt class="docutils literal"><span class="pre">threadpool_max_zombie_threads_before_die</span></tt>:</p>
<blockquote>
If there are more zombies than this, just kill the process. This is
only good if you have a monitor that will automatically restart
the server. This can clean up the mess. Default 0 (disabled).</blockquote>
<p><cite>threadpool_hung_check_period`</cite>:</p>
<blockquote>
Every X requests, check for hung threads that need to be killed,
or for zombie threads that should cause a restart. Default 100
requests.</blockquote>
<p><tt class="docutils literal"><span class="pre">threadpool_logger</span></tt>:</p>
<blockquote>
Logging messages will go the logger named here.</blockquote>
<p><tt class="docutils literal"><span class="pre">threadpool_error_email</span></tt> (or global <tt class="docutils literal"><span class="pre">error_email</span></tt> setting):</p>
<blockquote>
When threads are killed or the process restarted, this email
address will be contacted (using an SMTP server on localhost).</blockquote>
</dd></dl>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="http://pythonpaste.org/" class="invisible-link">Python Paste</a></h3>
<ul>
<li><a href="http://trac.pythonpaste.org">Issue tracker</a></li>
<li><a href="http://pythonpaste.org/">Paste core</a></li>
<li><a href="http://pythonpaste.org/webob/">WebOb</a></li>
<li><a href="http://pythonpaste.org/deploy/">Paste Deploy</a></li>
<li><a href="http://pythonpaste.org/script/">Paste Script</a></li>
<li><a href="http://pythonpaste.org/webtest/">WebTest</a></li>
<li><a href="http://pythonpaste.org/scripttest/">ScriptType</a></li>
<li><a href="http://pythonpaste.org/initools/">INITools</a></li>
<li><a href="http://pythonpaste.org/tempita/">Tempita</a></li>
<li><a href="http://pythonpaste.org/waitforit/">WaitForIt</a></li>
<li><a href="http://pythonpaste.org/wphp/">WPHP</a></li>
<li><a href="http://pythonpaste.org/wsgifilter/">WSGIFilter</a></li>
<li><a href="http://pythonpaste.org/wsgiproxy/">WSGIProxy</a></li>
</ul>
<h3><a href="../index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#"><tt class="docutils literal"><span class="pre">paste.httpserver</span></tt> – HTTP server</a><ul>
<li><a class="reference internal" href="#module-contents">Module Contents</a></li>
</ul>
</li>
</ul>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/modules/httpserver.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../index.html">Paste v1.7.5 documentation</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2008, Ian Bicking.
Last updated on Sep 14, 2010.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.1.
</div>
</body>
</html>
|