This repository was archived by the owner on Jan 12, 2022. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717import logging
1818import os
1919
20+ from werkzeug .wrappers import Request
21+ from werkzeug .wrappers import Response
22+
2023
2124RESERVED_ENV_KEYS = {
2225 'AUTH_DOMAIN' : 'gmail.com' , # Default auth domain must be set.
@@ -160,3 +163,23 @@ def get_env_to_hide_service_bridge(wsgi_env):
160163 'SERVER_PORT' , https )
161164
162165 return output
166+
167+
168+ def health_check_middleware (app ):
169+ """Intercept requests to /_ah/health and respond healthy (200 OK).
170+
171+ Args:
172+ app: The WSGI app to wrap.
173+
174+ Returns:
175+ The wrapped app, also a WSGI app.
176+ """
177+
178+ def health_check_intercept_wrapper (wsgi_env , start_response ): # pylint: disable=missing-docstring
179+ request = Request (wsgi_env )
180+ if request .path == '/_ah/health' : # Only intercept exact matches.
181+ return Response ('healthy' , status = 200 )(wsgi_env , start_response )
182+ else :
183+ return app (wsgi_env , start_response )
184+
185+ return health_check_intercept_wrapper
Original file line number Diff line number Diff line change 2525
2626from dispatcher import dispatcher
2727from middleware import reset_environment_middleware
28+ from middleware import health_check_middleware
2829from wsgi_config import env_vars_from_env_config
2930from wsgi_config import get_module_config
3031from wsgi_config import get_module_config_filename
8384# layer (the middleware code that will process a request first). Inside the
8485# innermost layer is the actual dispatcher, above.
8586
87+ # Intercept health check requests on /_ah/health. This is a temporary measure
88+ # until container-level health check handlers are in place and turned on.
89+ meta_app = health_check_middleware (meta_app )
90+
8691# Reset os.environ to the frozen state and add request-specific data.
8792meta_app = reset_environment_middleware (meta_app , frozen_environment ,
8893 frozen_user_env ,
89- frozen_env_config_env )
94+ frozen_env_config_env )
You can’t perform that action at this time.
0 commit comments