OLD | NEW |
---|---|
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 from appengine_wrappers import webapp2 | 5 from appengine_wrappers import webapp2 |
6 from handler import Handler | 6 from handler import Handler |
7 from servlet import Request | 7 from servlet import Request |
8 | 8 |
9 class AppEngineHandler(webapp2.RequestHandler): | 9 class AppEngineHandler(webapp2.RequestHandler): |
10 '''Top-level handler for AppEngine requests. Just converts them into our | 10 '''Top-level handler for AppEngine requests. Just converts them into our |
11 internal Servlet architecture. | 11 internal Servlet architecture. |
12 ''' | 12 ''' |
13 | |
13 def get(self): | 14 def get(self): |
14 request = Request(self.request.path, | 15 profile_mode = self.request.get('profile') |
15 self.request.url[:-len(self.request.path)], | 16 if profile_mode: |
16 self.request.headers) | 17 import cProfile, pstats, StringIO |
17 response = Handler(request).Get() | 18 pr = cProfile.Profile() |
18 self.response.out.write(response.content.ToString()) | 19 pr.enable() |
19 self.response.headers.update(response.headers) | 20 |
20 self.response.status = response.status | 21 try: |
22 request = Request(self.request.path, | |
23 self.request.url[:-len(self.request.path)], | |
24 self.request.headers) | |
25 response = Handler(request).Get() | |
26 finally: | |
27 if profile_mode: | |
28 pr.disable() | |
29 s = StringIO.StringIO() | |
30 pstats.Stats(pr, stream=s).sort_stats(profile_mode).print_stats() | |
31 self.response.out.write(s.getvalue()) | |
Yoyo Zhou
2013/12/13 02:18:47
I assume you're not concerned that the response co
not at google - send to devlin
2013/12/13 03:23:35
Correct. There didn't seem to be a sensible way to
| |
32 self.response.headers['Content-Type'] = 'text/plain' | |
33 self.response.status = 200 | |
34 else: | |
35 self.response.out.write(response.content.ToString()) | |
36 self.response.headers.update(response.headers) | |
37 self.response.status = response.status | |
OLD | NEW |