Mercurial > piecrust2
annotate piecrust/serving/middlewares.py @ 606:f1e03f85f14d
admin: Fix creating pages.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 27 Jan 2016 22:47:00 -0800 |
parents | 93b656f0af54 |
children | 3ceeca7bb71c |
rev | line source |
---|---|
553
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
1 import os.path |
556
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
2 from werkzeug.exceptions import NotFound, Forbidden |
553
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 from werkzeug.wrappers import Request, Response |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 from werkzeug.wsgi import ClosingIterator |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 from piecrust import RESOURCES_DIR, CACHE_DIR |
556
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
6 from piecrust.data.builder import ( |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
7 DataBuildingContext, build_page_data) |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
8 from piecrust.data.debug import build_var_debug_info |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
9 from piecrust.routing import RouteNotFoundError |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
10 from piecrust.serving.util import ( |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
11 make_wrapped_file_response, get_requested_page, get_app_for_server) |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
12 from piecrust.sources.pageref import PageNotFoundError |
553
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 class StaticResourcesMiddleware(object): |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 """ WSGI middleware that serves static files from the `resources/server` |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 directory in the PieCrust package. |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 """ |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 def __init__(self, app): |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 self.app = app |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
21 |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
22 def __call__(self, environ, start_response): |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
23 static_mount = '/__piecrust_static/' |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
24 |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 request = Request(environ) |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
26 if request.path.startswith(static_mount): |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
27 rel_req_path = request.path[len(static_mount):] |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
28 mount = os.path.join(RESOURCES_DIR, 'server') |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
29 full_path = os.path.join(mount, rel_req_path) |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
30 try: |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
31 response = make_wrapped_file_response( |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
32 environ, request, full_path) |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
33 return response(environ, start_response) |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
34 except OSError: |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
35 pass |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
36 |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
37 return self.app(environ, start_response) |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
38 |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
39 |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
40 class PieCrustDebugMiddleware(object): |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
41 """ WSGI middleware that handles debugging of PieCrust stuff. |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
42 """ |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
43 def __init__(self, app, root_dir, debug=False, |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
44 sub_cache_dir=None, run_sse_check=None): |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
45 self.app = app |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
46 self.root_dir = root_dir |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
47 self.debug = debug |
556
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
48 self.sub_cache_dir = sub_cache_dir |
553
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
49 self.run_sse_check = run_sse_check |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
50 self._proc_loop = None |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
51 self._out_dir = os.path.join(root_dir, CACHE_DIR, 'server') |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
52 if sub_cache_dir: |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
53 self._out_dir = os.path.join(sub_cache_dir, 'server') |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
54 self._handlers = { |
556
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
55 'debug_info': self._getDebugInfo, |
553
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
56 'werkzeug_shutdown': self._shutdownWerkzeug, |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
57 'pipeline_status': self._startSSEProvider} |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
58 |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
59 if not self.run_sse_check or self.run_sse_check(): |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
60 # When using a server with code reloading, some implementations |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
61 # use process forking and we end up going here twice. We only want |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
62 # to start the pipeline loop in the inner process most of the |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
63 # time so we let the implementation tell us if this is OK. |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
64 from piecrust.serving.procloop import ProcessingLoop |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
65 self._proc_loop = ProcessingLoop(root_dir, self._out_dir, |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
66 sub_cache_dir=sub_cache_dir, |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
67 debug=debug) |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
68 self._proc_loop.start() |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
69 |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
70 def __call__(self, environ, start_response): |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
71 debug_mount = '/__piecrust_debug/' |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
72 |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
73 request = Request(environ) |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
74 if request.path.startswith(debug_mount): |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
75 rel_req_path = request.path[len(debug_mount):] |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
76 handler = self._handlers.get(rel_req_path) |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
77 if handler is not None: |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
78 return handler(request, start_response) |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
79 |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
80 return self.app(environ, start_response) |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
81 |
556
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
82 def _getDebugInfo(self, request, start_response): |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
83 app = get_app_for_server(self.root_dir, debug=self.debug, |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
84 sub_cache_dir=self.sub_cache_dir) |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
85 if not app.config.get('site/enable_debug_info'): |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
86 return Forbidden() |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
87 |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
88 found = False |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
89 page_path = request.args.get('page') |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
90 try: |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
91 req_page = get_requested_page(app, page_path) |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
92 found = (req_page is not None) |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
93 except (RouteNotFoundError, PageNotFoundError): |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
94 pass |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
95 if not found: |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
96 return NotFound("No such page: %s" % page_path) |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
97 |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
98 ctx = DataBuildingContext(req_page.qualified_page, |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
99 page_num=req_page.page_num) |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
100 data = build_page_data(ctx) |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
101 |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
102 var_path = request.args.getlist('var') |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
103 if not var_path: |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
104 var_path = None |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
105 output = build_var_debug_info(data, var_path) |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
106 |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
107 response = Response(output, mimetype='text/html') |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
108 return response(request.environ, start_response) |
93b656f0af54
serve: Improve debug information in the preview server.
Ludovic Chabant <ludovic@chabant.com>
parents:
553
diff
changeset
|
109 |
553
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
110 def _shutdownWerkzeug(self, request, start_response): |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
111 shutdown_func = request.environ.get('werkzeug.server.shutdown') |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
112 if shutdown_func is None: |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
113 raise RuntimeError('Not running with the Werkzeug Server') |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
114 shutdown_func() |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
115 response = Response("Server shutting down...") |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
116 return response(request.environ, start_response) |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
117 |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
118 def _startSSEProvider(self, request, start_response): |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
119 from piecrust.serving.procloop import ( |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
120 PipelineStatusServerSentEventProducer) |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
121 provider = PipelineStatusServerSentEventProducer( |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
122 self._proc_loop) |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
123 it = provider.run() |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
124 response = Response(it, mimetype='text/event-stream') |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
125 response.headers['Cache-Control'] = 'no-cache' |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
126 response.headers['Last-Event-ID'] = \ |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
127 self._proc_loop.last_status_id |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
128 return ClosingIterator( |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
129 response(request.environ, start_response), |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
130 [provider.close]) |
cc6f3dbe3048
serve: Extract some of the server's functionality into WSGI middlewares.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
131 |