blob: 4b12e9d65a5b09395f4c6a721b48ab08390373f2 [file] [log] [blame]
Phillip J. Eby5cf565d2006-06-09 16:40:18 +00001\section{\module{wsgiref} --- WSGI Utilities and Reference
2Implementation}
3\declaremodule{}{wsgiref}
4\moduleauthor{Phillip J. Eby}{pje@telecommunity.com}
5\sectionauthor{Phillip J. Eby}{pje@telecommunity.com}
6\modulesynopsis{WSGI Utilities and Reference Implementation}
7
Neal Norwitza754a222006-06-11 05:45:47 +00008\versionadded{2.5}
9
Phillip J. Eby5cf565d2006-06-09 16:40:18 +000010The Web Server Gateway Interface (WSGI) is a standard interface
11between web server software and web applications written in Python.
12Having a standard interface makes it easy to use an application
13that supports WSGI with a number of different web servers.
14
15Only authors of web servers and programming frameworks need to know
16every detail and corner case of the WSGI design. You don't need to
17understand every detail of WSGI just to install a WSGI application or
18to write a web application using an existing framework.
19
20\module{wsgiref} is a reference implementation of the WSGI specification
21that can be used to add WSGI support to a web server or framework. It
22provides utilities for manipulating WSGI environment variables and
23response headers, base classes for implementing WSGI servers, a demo
24HTTP server that serves WSGI applications, and a validation tool that
25checks WSGI servers and applications for conformance to the
26WSGI specification (\pep{333}).
27
28% XXX If you're just trying to write a web application...
29% XXX should create a URL on python.org to point people to.
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44\subsection{\module{wsgiref.util} -- WSGI environment utilities}
45\declaremodule{}{wsgiref.util}
46
47This module provides a variety of utility functions for working with
48WSGI environments. A WSGI environment is a dictionary containing
49HTTP request variables as described in \pep{333}. All of the functions
50taking an \var{environ} parameter expect a WSGI-compliant dictionary to
51be supplied; please see \pep{333} for a detailed specification.
52
53\begin{funcdesc}{guess_scheme}{environ}
54Return a guess for whether \code{wsgi.url_scheme} should be ``http'' or
55``https'', by checking for a \code{HTTPS} environment variable in the
56\var{environ} dictionary. The return value is a string.
57
58This function is useful when creating a gateway that wraps CGI or a
59CGI-like protocol such as FastCGI. Typically, servers providing such
60protocols will include a \code{HTTPS} variable with a value of ``1''
61``yes'', or ``on'' when a request is received via SSL. So, this
62function returns ``https'' if such a value is found, and ``http''
63otherwise.
64\end{funcdesc}
65
66\begin{funcdesc}{request_uri}{environ \optional{, include_query=1}}
67Return the full request URI, optionally including the query string,
68using the algorithm found in the ``URL Reconstruction'' section of
69\pep{333}. If \var{include_query} is false, the query string is
70not included in the resulting URI.
71\end{funcdesc}
72
73\begin{funcdesc}{application_uri}{environ}
74Similar to \function{request_uri}, except that the \code{PATH_INFO} and
75\code{QUERY_STRING} variables are ignored. The result is the base URI
76of the application object addressed by the request.
77\end{funcdesc}
78
79\begin{funcdesc}{shift_path_info}{environ}
80Shift a single name from \code{PATH_INFO} to \code{SCRIPT_NAME} and
81return the name. The \var{environ} dictionary is \emph{modified}
82in-place; use a copy if you need to keep the original \code{PATH_INFO}
83or \code{SCRIPT_NAME} intact.
84
85If there are no remaining path segments in \code{PATH_INFO}, \code{None}
86is returned.
87
88Typically, this routine is used to process each portion of a request
89URI path, for example to treat the path as a series of dictionary keys.
90This routine modifies the passed-in environment to make it suitable for
91invoking another WSGI application that is located at the target URI.
92For example, if there is a WSGI application at \code{/foo}, and the
93request URI path is \code{/foo/bar/baz}, and the WSGI application at
94\code{/foo} calls \function{shift_path_info}, it will receive the string
95``bar'', and the environment will be updated to be suitable for passing
96to a WSGI application at \code{/foo/bar}. That is, \code{SCRIPT_NAME}
97will change from \code{/foo} to \code{/foo/bar}, and \code{PATH_INFO}
98will change from \code{/bar/baz} to \code{/baz}.
99
100When \code{PATH_INFO} is just a ``/'', this routine returns an empty
101string and appends a trailing slash to \code{SCRIPT_NAME}, even though
102empty path segments are normally ignored, and \code{SCRIPT_NAME} doesn't
103normally end in a slash. This is intentional behavior, to ensure that
104an application can tell the difference between URIs ending in \code{/x}
105from ones ending in \code{/x/} when using this routine to do object
106traversal.
107
108\end{funcdesc}
109
110\begin{funcdesc}{setup_testing_defaults}{environ}
111Update \var{environ} with trivial defaults for testing purposes.
112
113This routine adds various parameters required for WSGI, including
114\code{HTTP_HOST}, \code{SERVER_NAME}, \code{SERVER_PORT},
115\code{REQUEST_METHOD}, \code{SCRIPT_NAME}, \code{PATH_INFO}, and all of
116the \pep{333}-defined \code{wsgi.*} variables. It only supplies default
117values, and does not replace any existing settings for these variables.
118
119This routine is intended to make it easier for unit tests of WSGI
120servers and applications to set up dummy environments. It should NOT
121be used by actual WSGI servers or applications, since the data is fake!
122\end{funcdesc}
123
124
125
126In addition to the environment functions above, the
127\module{wsgiref.util} module also provides these miscellaneous
128utilities:
129
130\begin{funcdesc}{is_hop_by_hop}{header_name}
131Return true if 'header_name' is an HTTP/1.1 ``Hop-by-Hop'' header, as
132defined by \rfc{2616}.
133\end{funcdesc}
134
135\begin{classdesc}{FileWrapper}{filelike \optional{, blksize=8192}}
136A wrapper to convert a file-like object to an iterator. The resulting
137objects support both \method{__getitem__} and \method{__iter__}
138iteration styles, for compatibility with Python 2.1 and Jython.
139As the object is iterated over, the optional \var{blksize} parameter
140will be repeatedly passed to the \var{filelike} object's \method{read()}
141method to obtain strings to yield. When \method{read()} returns an
142empty string, iteration is ended and is not resumable.
143
144If \var{filelike} has a \method{close()} method, the returned object
145will also have a \method{close()} method, and it will invoke the
146\var{filelike} object's \method{close()} method when called.
147\end{classdesc}
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167\subsection{\module{wsgiref.headers} -- WSGI response header tools}
168\declaremodule{}{wsgiref.headers}
169
170This module provides a single class, \class{Headers}, for convenient
171manipulation of WSGI response headers using a mapping-like interface.
172
173\begin{classdesc}{Headers}{headers}
174Create a mapping-like object wrapping \var{headers}, which must be a
175list of header name/value tuples as described in \pep{333}. Any changes
176made to the new \class{Headers} object will directly update the
177\var{headers} list it was created with.
178
179\class{Headers} objects support typical mapping operations including
180\method{__getitem__}, \method{get}, \method{__setitem__},
181\method{setdefault}, \method{__delitem__}, \method{__contains__} and
182\method{has_key}. For each of these methods, the key is the header name
183(treated case-insensitively), and the value is the first value
184associated with that header name. Setting a header deletes any existing
185values for that header, then adds a new value at the end of the wrapped
186header list. Headers' existing order is generally maintained, with new
187headers added to the end of the wrapped list.
188
189Unlike a dictionary, \class{Headers} objects do not raise an error when
190you try to get or delete a key that isn't in the wrapped header list.
191Getting a nonexistent header just returns \code{None}, and deleting
192a nonexistent header does nothing.
193
194\class{Headers} objects also support \method{keys()}, \method{values()},
195and \method{items()} methods. The lists returned by \method{keys()}
196and \method{items()} can include the same key more than once if there
197is a multi-valued header. The \code{len()} of a \class{Headers} object
198is the same as the length of its \method{items()}, which is the same
199as the length of the wrapped header list. In fact, the \method{items()}
200method just returns a copy of the wrapped header list.
201
202Calling \code{str()} on a \class{Headers} object returns a formatted
203string suitable for transmission as HTTP response headers. Each header
204is placed on a line with its value, separated by a colon and a space.
205Each line is terminated by a carriage return and line feed, and the
206string is terminated with a blank line.
207
208In addition to their mapping interface and formatting features,
209\class{Headers} objects also have the following methods for querying
210and adding multi-valued headers, and for adding headers with MIME
211parameters:
212
213\begin{methoddesc}{get_all}{name}
214Return a list of all the values for the named header.
215
216The returned list will be sorted in the order they appeared in the
217original header list or were added to this instance, and may contain
218duplicates. Any fields deleted and re-inserted are always appended to
219the header list. If no fields exist with the given name, returns an
220empty list.
221\end{methoddesc}
222
223
224\begin{methoddesc}{add_header}{name, value, **_params}
225Add a (possibly multi-valued) header, with optional MIME parameters
226specified via keyword arguments.
227
228\var{name} is the header field to add. Keyword arguments can be used to
229set MIME parameters for the header field. Each parameter must be a
230string or \code{None}. Underscores in parameter names are converted to
231dashes, since dashes are illegal in Python identifiers, but many MIME
232parameter names include dashes. If the parameter value is a string, it
233is added to the header value parameters in the form \code{name="value"}.
234If it is \code{None}, only the parameter name is added. (This is used
235for MIME parameters without a value.) Example usage:
236
237\begin{verbatim}
238h.add_header('content-disposition', 'attachment', filename='bud.gif')
239\end{verbatim}
240
241The above will add a header that looks like this:
242
243\begin{verbatim}
244Content-Disposition: attachment; filename="bud.gif"
245\end{verbatim}
246\end{methoddesc}
247\end{classdesc}
248
249\subsection{\module{wsgiref.simple_server} -- a simple WSGI HTTP server}
250\declaremodule[wsgiref.simpleserver]{}{wsgiref.simple_server}
251
252This module implements a simple HTTP server (based on
253\module{BaseHTTPServer}) that serves WSGI applications. Each server
254instance serves a single WSGI application on a given host and port. If
255you want to serve multiple applications on a single host and port, you
256should create a WSGI application that parses \code{PATH_INFO} to select
257which application to invoke for each request. (E.g., using the
258\function{shift_path_info()} function from \module{wsgiref.util}.)
259
260
261\begin{funcdesc}{make_server}{host, port, app
262\optional{, server_class=\class{WSGIServer} \optional{,
263handler_class=\class{WSGIRequestHandler}}}}
264Create a new WSGI server listening on \var{host} and \var{port},
265accepting connections for \var{app}. The return value is an instance of
266the supplied \var{server_class}, and will process requests using the
267specified \var{handler_class}. \var{app} must be a WSGI application
268object, as defined by \pep{333}.
269
270Example usage:
271\begin{verbatim}from wsgiref.simple_server import make_server, demo_app
272
273httpd = make_server('', 8000, demo_app)
274print "Serving HTTP on port 8000..."
275
276# Respond to requests until process is killed
277httpd.serve_forever()
278
279# Alternative: serve one request, then exit
280##httpd.handle_request()
281\end{verbatim}
282
283\end{funcdesc}
284
285
286
287
288
289
290\begin{funcdesc}{demo_app}{environ, start_response}
291This function is a small but complete WSGI application that
292returns a text page containing the message ``Hello world!''
293and a list of the key/value pairs provided in the
294\var{environ} parameter. It's useful for verifying that a WSGI server
295(such as \module{wsgiref.simple_server}) is able to run a simple WSGI
296application correctly.
297\end{funcdesc}
298
299
300\begin{classdesc}{WSGIServer}{server_address, RequestHandlerClass}
301Create a \class{WSGIServer} instance. \var{server_address} should be
302a \code{(host,port)} tuple, and \var{RequestHandlerClass} should be
303the subclass of \class{BaseHTTPServer.BaseHTTPRequestHandler} that will
304be used to process requests.
305
306You do not normally need to call this constructor, as the
307\function{make_server()} function can handle all the details for you.
308
309\class{WSGIServer} is a subclass
310of \class{BaseHTTPServer.HTTPServer}, so all of its methods (such as
311\method{serve_forever()} and \method{handle_request()}) are available.
312\class{WSGIServer} also provides these WSGI-specific methods:
313
314\begin{methoddesc}{set_app}{application}
315Sets the callable \var{application} as the WSGI application that will
316receive requests.
317\end{methoddesc}
318
319\begin{methoddesc}{get_app}{}
320Returns the currently-set application callable.
321\end{methoddesc}
322
323Normally, however, you do not need to use these additional methods, as
324\method{set_app()} is normally called by \function{make_server()}, and
325the \method{get_app()} exists mainly for the benefit of request handler
326instances.
327\end{classdesc}
328
329
330
331\begin{classdesc}{WSGIRequestHandler}{request, client_address, server}
332Create an HTTP handler for the given \var{request} (i.e. a socket),
333\var{client_address} (a \code{(\var{host},\var{port})} tuple), and
334\var{server} (\class{WSGIServer} instance).
335
336You do not need to create instances of this class directly; they are
337automatically created as needed by \class{WSGIServer} objects. You
338can, however, subclass this class and supply it as a \var{handler_class}
339to the \function{make_server()} function. Some possibly relevant
340methods for overriding in subclasses:
341
342\begin{methoddesc}{get_environ}{}
343Returns a dictionary containing the WSGI environment for a request. The
344default implementation copies the contents of the \class{WSGIServer}
345object's \member{base_environ} dictionary attribute and then adds
346various headers derived from the HTTP request. Each call to this method
347should return a new dictionary containing all of the relevant CGI
348environment variables as specified in \pep{333}.
349\end{methoddesc}
350
351\begin{methoddesc}{get_stderr}{}
352Return the object that should be used as the \code{wsgi.errors} stream.
353The default implementation just returns \code{sys.stderr}.
354\end{methoddesc}
355
356\begin{methoddesc}{handle}{}
357Process the HTTP request. The default implementation creates a handler
358instance using a \module{wsgiref.handlers} class to implement the actual
359WSGI application interface.
360\end{methoddesc}
361
362\end{classdesc}
363
364
365
366
367
368
369
370
371
372\subsection{\module{wsgiref.validate} -- WSGI conformance checker}
373\declaremodule{}{wsgiref.validate}
374When creating new WSGI application objects, frameworks, servers, or
375middleware, it can be useful to validate the new code's conformance
376using \module{wsgiref.validate}. This module provides a function that
377creates WSGI application objects that validate communications between
378a WSGI server or gateway and a WSGI application object, to check both
379sides for protocol conformance.
380
381Note that this utility does not guarantee complete \pep{333} compliance;
382an absence of errors from this module does not necessarily mean that
383errors do not exist. However, if this module does produce an error,
384then it is virtually certain that either the server or application is
385not 100\% compliant.
386
387This module is based on the \module{paste.lint} module from Ian
388Bicking's ``Python Paste'' library.
389
390\begin{funcdesc}{validator}{application}
391Wrap \var{application} and return a new WSGI application object. The
392returned application will forward all requests to the original
393\var{application}, and will check that both the \var{application} and
394the server invoking it are conforming to the WSGI specification and to
395RFC 2616.
396
397Any detected nonconformance results in an \exception{AssertionError}
398being raised; note, however, that how these errors are handled is
399server-dependent. For example, \module{wsgiref.simple_server} and other
400servers based on \module{wsgiref.handlers} (that don't override the
401error handling methods to do something else) will simply output a
402message that an error has occurred, and dump the traceback to
403\code{sys.stderr} or some other error stream.
404
405This wrapper may also generate output using the \module{warnings} module
406to indicate behaviors that are questionable but which may not actually
407be prohibited by \pep{333}. Unless they are suppressed using Python
408command-line options or the \module{warnings} API, any such warnings
409will be written to \code{sys.stderr} (\emph{not} \code{wsgi.errors},
410unless they happen to be the same object).
411\end{funcdesc}
412
413\subsection{\module{wsgiref.handlers} -- server/gateway base classes}
414\declaremodule{}{wsgiref.handlers}
415
416This module provides base handler classes for implementing WSGI servers
417and gateways. These base classes handle most of the work of
418communicating with a WSGI application, as long as they are given a
419CGI-like environment, along with input, output, and error streams.
420
421
422\begin{classdesc}{CGIHandler}{}
423CGI-based invocation via \code{sys.stdin}, \code{sys.stdout},
424\code{sys.stderr} and \code{os.environ}. This is useful when you have
425a WSGI application and want to run it as a CGI script. Simply invoke
426\code{CGIHandler().run(app)}, where \code{app} is the WSGI application
427object you wish to invoke.
428
429This class is a subclass of \class{BaseCGIHandler} that sets
430\code{wsgi.run_once} to true, \code{wsgi.multithread} to false, and
431\code{wsgi.multiprocess} to true, and always uses \module{sys} and
432\module{os} to obtain the necessary CGI streams and environment.
433\end{classdesc}
434
435
436\begin{classdesc}{BaseCGIHandler}{stdin, stdout, stderr, environ
437\optional{, multithread=True \optional{, multiprocess=False}}}
438
439Similar to \class{CGIHandler}, but instead of using the \module{sys} and
440\module{os} modules, the CGI environment and I/O streams are specified
441explicitly. The \var{multithread} and \var{multiprocess} values are
442used to set the \code{wsgi.multithread} and \code{wsgi.multiprocess}
443flags for any applications run by the handler instance.
444
445This class is a subclass of \class{SimpleHandler} intended for use with
446software other than HTTP ``origin servers''. If you are writing a
447gateway protocol implementation (such as CGI, FastCGI, SCGI, etc.) that
448uses a \code{Status:} header to send an HTTP status, you probably want
449to subclass this instead of \class{SimpleHandler}.
450\end{classdesc}
451
452
453
454\begin{classdesc}{SimpleHandler}{stdin, stdout, stderr, environ
455\optional{,multithread=True \optional{, multiprocess=False}}}
456
457Similar to \class{BaseCGIHandler}, but designed for use with HTTP origin
458servers. If you are writing an HTTP server implementation, you will
459probably want to subclass this instead of \class{BaseCGIHandler}
460
461This class is a subclass of \class{BaseHandler}. It overrides the
462\method{__init__()}, \method{get_stdin()}, \method{get_stderr()},
463\method{add_cgi_vars()}, \method{_write()}, and \method{_flush()}
464methods to support explicitly setting the environment and streams via
465the constructor. The supplied environment and streams are stored in
466the \member{stdin}, \member{stdout}, \member{stderr}, and
467\member{environ} attributes.
468\end{classdesc}
469
470\begin{classdesc}{BaseHandler}{}
471This is an abstract base class for running WSGI applications. Each
472instance will handle a single HTTP request, although in principle you
473could create a subclass that was reusable for multiple requests.
474
475\class{BaseHandler} instances have only one method intended for external
476use:
477
478\begin{methoddesc}{run}{app}
479Run the specified WSGI application, \var{app}.
480\end{methoddesc}
481
482All of the other \class{BaseHandler} methods are invoked by this method
483in the process of running the application, and thus exist primarily to
484allow customizing the process.
485
486The following methods MUST be overridden in a subclass:
487
488\begin{methoddesc}{_write}{data}
489Buffer the string \var{data} for transmission to the client. It's okay
490if this method actually transmits the data; \class{BaseHandler}
491just separates write and flush operations for greater efficiency
492when the underlying system actually has such a distinction.
493\end{methoddesc}
494
495\begin{methoddesc}{_flush}{}
496Force buffered data to be transmitted to the client. It's okay if this
497method is a no-op (i.e., if \method{_write()} actually sends the data).
498\end{methoddesc}
499
500\begin{methoddesc}{get_stdin}{}
501Return an input stream object suitable for use as the \code{wsgi.input}
502of the request currently being processed.
503\end{methoddesc}
504
505\begin{methoddesc}{get_stderr}{}
506Return an output stream object suitable for use as the
507\code{wsgi.errors} of the request currently being processed.
508\end{methoddesc}
509
510\begin{methoddesc}{add_cgi_vars}{}
511Insert CGI variables for the current request into the \member{environ}
512attribute.
513\end{methoddesc}
514
515Here are some other methods and attributes you may wish to override.
516This list is only a summary, however, and does not include every method
517that can be overridden. You should consult the docstrings and source
518code for additional information before attempting to create a customized
519\class{BaseHandler} subclass.
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536Attributes and methods for customizing the WSGI environment:
537
538\begin{memberdesc}{wsgi_multithread}
539The value to be used for the \code{wsgi.multithread} environment
540variable. It defaults to true in \class{BaseHandler}, but may have
541a different default (or be set by the constructor) in the other
542subclasses.
543\end{memberdesc}
544
545\begin{memberdesc}{wsgi_multiprocess}
546The value to be used for the \code{wsgi.multiprocess} environment
547variable. It defaults to true in \class{BaseHandler}, but may have
548a different default (or be set by the constructor) in the other
549subclasses.
550\end{memberdesc}
551
552\begin{memberdesc}{wsgi_run_once}
553The value to be used for the \code{wsgi.run_once} environment
554variable. It defaults to false in \class{BaseHandler}, but
555\class{CGIHandler} sets it to true by default.
556\end{memberdesc}
557
558\begin{memberdesc}{os_environ}
559The default environment variables to be included in every request's
560WSGI environment. By default, this is a copy of \code{os.environ} at
561the time that \module{wsgiref.handlers} was imported, but subclasses can
562either create their own at the class or instance level. Note that the
563dictionary should be considered read-only, since the default value is
564shared between multiple classes and instances.
565\end{memberdesc}
566
567\begin{memberdesc}{server_software}
568If the \member{origin_server} attribute is set, this attribute's value
569is used to set the default \code{SERVER_SOFTWARE} WSGI environment
570variable, and also to set a default \code{Server:} header in HTTP
571responses. It is ignored for handlers (such as \class{BaseCGIHandler}
572and \class{CGIHandler}) that are not HTTP origin servers.
573\end{memberdesc}
574
575
576
577\begin{methoddesc}{get_scheme}{}
578Return the URL scheme being used for the current request. The default
579implementation uses the \function{guess_scheme()} function from
580\module{wsgiref.util} to guess whether the scheme should be ``http'' or
581``https'', based on the current request's \member{environ} variables.
582\end{methoddesc}
583
584\begin{methoddesc}{setup_environ}{}
585Set the \member{environ} attribute to a fully-populated WSGI
586environment. The default implementation uses all of the above methods
587and attributes, plus the \method{get_stdin()}, \method{get_stderr()},
588and \method{add_cgi_vars()} methods and the \member{wsgi_file_wrapper}
589attribute. It also inserts a \code{SERVER_SOFTWARE} key if not present,
590as long as the \member{origin_server} attribute is a true value and the
591\member{server_software} attribute is set.
592\end{methoddesc}
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618Methods and attributes for customizing exception handling:
619
620\begin{methoddesc}{log_exception}{exc_info}
621Log the \var{exc_info} tuple in the server log. \var{exc_info} is a
622\code{(\var{type}, \var{value}, \var{traceback})} tuple. The default
623implementation simply writes the traceback to the request's
624\code{wsgi.errors} stream and flushes it. Subclasses can override this
625method to change the format or retarget the output, mail the traceback
626to an administrator, or whatever other action may be deemed suitable.
627\end{methoddesc}
628
629\begin{memberdesc}{traceback_limit}
630The maximum number of frames to include in tracebacks output by the
631default \method{log_exception()} method. If \code{None}, all frames
632are included.
633\end{memberdesc}
634
635\begin{methoddesc}{error_output}{environ, start_response}
636This method is a WSGI application to generate an error page for the
637user. It is only invoked if an error occurs before headers are sent
638to the client.
639
640This method can access the current error information using
641\code{sys.exc_info()}, and should pass that information to
642\var{start_response} when calling it (as described in the ``Error
643Handling'' section of \pep{333}).
644
645The default implementation just uses the \member{error_status},
646\member{error_headers}, and \member{error_body} attributes to generate
647an output page. Subclasses can override this to produce more dynamic
648error output.
649
650Note, however, that it's not recommended from a security perspective to
651spit out diagnostics to any old user; ideally, you should have to do
652something special to enable diagnostic output, which is why the default
653implementation doesn't include any.
654\end{methoddesc}
655
656
657
658
659\begin{memberdesc}{error_status}
660The HTTP status used for error responses. This should be a status
661string as defined in \pep{333}; it defaults to a 500 code and message.
662\end{memberdesc}
663
664\begin{memberdesc}{error_headers}
665The HTTP headers used for error responses. This should be a list of
666WSGI response headers (\code{(\var{name}, \var{value})} tuples), as
667described in \pep{333}. The default list just sets the content type
668to \code{text/plain}.
669\end{memberdesc}
670
671\begin{memberdesc}{error_body}
672The error response body. This should be an HTTP response body string.
673It defaults to the plain text, ``A server error occurred. Please
674contact the administrator.''
675\end{memberdesc}
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700Methods and attributes for \pep{333}'s ``Optional Platform-Specific File
701Handling'' feature:
702
703\begin{memberdesc}{wsgi_file_wrapper}
704A \code{wsgi.file_wrapper} factory, or \code{None}. The default value
705of this attribute is the \class{FileWrapper} class from
706\module{wsgiref.util}.
707\end{memberdesc}
708
709\begin{methoddesc}{sendfile}{}
710Override to implement platform-specific file transmission. This method
711is called only if the application's return value is an instance of
712the class specified by the \member{wsgi_file_wrapper} attribute. It
713should return a true value if it was able to successfully transmit the
714file, so that the default transmission code will not be executed.
715The default implementation of this method just returns a false value.
716\end{methoddesc}
717
718
719Miscellaneous methods and attributes:
720
721\begin{memberdesc}{origin_server}
722This attribute should be set to a true value if the handler's
723\method{_write()} and \method{_flush()} are being used to communicate
724directly to the client, rather than via a CGI-like gateway protocol that
725wants the HTTP status in a special \code{Status:} header.
726
727This attribute's default value is true in \class{BaseHandler}, but
728false in \class{BaseCGIHandler} and \class{CGIHandler}.
729\end{memberdesc}
730
731\begin{memberdesc}{http_version}
732If \member{origin_server} is true, this string attribute is used to
733set the HTTP version of the response set to the client. It defaults to
734\code{"1.0"}.
735\end{memberdesc}
736
737
738
739
740
741\end{classdesc}
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781