def _get_rpc_or_rest(self, api_format, request, start_response): """Sends back HTTP response with API directory. This calls start_response and returns the response body. It will return the discovery doc for the requested api/version. Args: api_format: A string containing either 'rest' or 'rpc'. request: An ApiRequest, the transformed request sent to the Discovery SPI. start_response: A function with semantics defined in PEP-333. Returns: A string, the response body. """ api = request.body_json['api'] version = request.body_json['version'] lookup_key = (api, version) api_config = self._config_manager.configs.get(lookup_key) if not api_config: logging.warn('No discovery doc for version %s of api %s', version, api) return util.send_wsgi_not_found_response(start_response) doc = self._discovery_proxy.generate_discovery_doc( api_config, api_format) if not doc: error_msg = ('Failed to convert .api to discovery doc for ' 'version %s of api %s') % (version, api) logging.error('%s', error_msg) return util.send_wsgi_error_response(error_msg, start_response) return self._send_success_response(doc, start_response)
def _get_rpc_or_rest(self, api_format, request, start_response): """Sends back HTTP response with API directory. This calls start_response and returns the response body. It will return the discovery doc for the requested api/version. Args: api_format: A string containing either 'rest' or 'rpc'. request: An ApiRequest, the transformed request sent to the Discovery SPI. start_response: A function with semantics defined in PEP-333. Returns: A string, the response body. """ api = request.body_json['api'] version = request.body_json['version'] lookup_key = (api, version) api_config = self._config_manager.configs.get(lookup_key) if not api_config: logging.warn('No discovery doc for version %s of api %s', version, api) return util.send_wsgi_not_found_response(start_response) doc = self._discovery_proxy.generate_discovery_doc(api_config, api_format) if not doc: error_msg = ('Failed to convert .api to discovery doc for ' 'version %s of api %s') % (version, api) logging.error('%s', error_msg) return util.send_wsgi_error_response(error_msg, start_response) return self._send_success_response(doc, start_response)
def fail_request(self, orig_request, message, start_response): """Write an immediate failure response to outfile, no redirect. This calls start_response and returns the error body. Args: orig_request: An ApiRequest, the original request from the user. message: A string containing the error message to be displayed to user. start_response: A function with semantics defined in PEP-333. Returns: A string containing the body of the error response. """ cors_handler = EndpointsDispatcher.__CheckCorsHeaders(orig_request) return util.send_wsgi_error_response(message, start_response, cors_handler=cors_handler)