cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / app_engine_handler.py
blob14bcdf3ba31971a584b3b1ab87f3c8a5dcfda68e
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
3 # found in the LICENSE file.
5 import logging
6 import webapp2
8 from handler import Handler
9 from servlet import Request
12 class AppEngineHandler(webapp2.RequestHandler):
13 '''Top-level handler for AppEngine requests. Just converts them into our
14 internal Servlet architecture.
15 '''
17 def post(self):
18 self._HandleRequest()
20 def get(self):
21 self._HandleRequest()
23 def _HandleRequest(self):
24 profile_mode = self.request.get('profile')
25 if profile_mode:
26 import cProfile, pstats, StringIO
27 pr = cProfile.Profile()
28 pr.enable()
30 try:
31 response = None
32 arguments = {}
33 for argument in self.request.arguments():
34 arguments[argument] = self.request.get(argument)
35 request = Request(self.request.path,
36 self.request.host,
37 self.request.headers,
38 arguments)
39 response = Handler(request).Get()
40 except Exception as e:
41 logging.exception(e)
42 finally:
43 if profile_mode:
44 pr.disable()
45 s = StringIO.StringIO()
46 pstats.Stats(pr, stream=s).sort_stats(profile_mode).print_stats()
47 self.response.out.write(s.getvalue())
48 self.response.headers['Content-Type'] = 'text/plain'
49 self.response.status = 200
50 elif response:
51 self.response.out.write(response.content.ToString())
52 self.response.headers.update(response.headers)
53 self.response.status = response.status
54 else:
55 self.response.out.write('Internal server error')
56 self.response.status = 500