def call_backend(self, orig_request, start_response):
    """Generate API call (from earlier-saved request).

    This calls start_response and returns the response body.

    Args:
      orig_request: An ApiRequest, the original request from the user.
      start_response: A function with semantics defined in PEP-333.

    Returns:
      A string containing the response body.
    """
    method_config, params = self.lookup_rest_method(orig_request)
    if not method_config:
      cors_handler = self._create_cors_handler(orig_request)
      return util.send_wsgi_not_found_response(start_response,
                                               cors_handler=cors_handler)

    # Prepare the request for the back end.
    transformed_request = self.transform_request(
        orig_request, params, method_config)

    # Check if this call is for the Discovery service.  If so, route
    # it to our Discovery handler.
    discovery = discovery_service.DiscoveryService(
        self.config_manager, self._backend)
    discovery_response = discovery.handle_discovery_request(
        transformed_request.path, transformed_request, start_response)
    if discovery_response:
      return discovery_response

    url = transformed_request.base_path + transformed_request.path
    transformed_request.headers['Content-Type'] = 'application/json'
    transformed_environ = self.prepare_backend_environ(
        orig_request.server, 'POST', url, transformed_request.headers.items(),
        transformed_request.body, transformed_request.source_ip,
        orig_request.port)

    # Send the transformed request to the backend app and capture the response.
    with util.StartResponseProxy() as start_response_proxy:
      body_iter = self._backend(transformed_environ, start_response_proxy.Proxy)
      status = start_response_proxy.response_status
      headers = start_response_proxy.response_headers

      # Get response body
      body = start_response_proxy.response_body
      # In case standard WSGI behavior is implemented later...
      if not body:
        body = ''.join(body_iter)

    return self.handle_backend_response(orig_request, transformed_request,
                                        status, headers, body, method_config,
                                        start_response)
def call_backend ( self , orig_request , start_response ) : method_config , params = self . lookup_rest_method ( orig_request ) if not method_config : cors_handler = self . _create_cors_handler ( orig_request ) return util . send_wsgi_not_found_response ( start_response , cors_handler = cors_handler ) transformed_request = self . transform_request ( orig_request , params , method_config ) discovery = discovery_service . DiscoveryService ( self . config_manager , self . _backend ) discovery_response = discovery . handle_discovery_request ( transformed_request . path , transformed_request , start_response ) if discovery_response : return discovery_response url = transformed_request . base_path + transformed_request . path transformed_request . headers [ 'Content-Type' ] = 'application/json' transformed_environ = self . prepare_backend_environ ( orig_request . server , 'POST' , url , transformed_request . headers . items ( ) , transformed_request . body , transformed_request . source_ip , orig_request . port ) with util . StartResponseProxy ( ) as start_response_proxy : body_iter = self . _backend ( transformed_environ , start_response_proxy . Proxy ) status = start_response_proxy . response_status headers = start_response_proxy . response_headers body = start_response_proxy . response_body if not body : body = '' . join ( body_iter ) return self . handle_backend_response ( orig_request , transformed_request , status , headers , body , method_config , start_response )
Generate API call (from earlier-saved request).

    This calls start_response and returns the response body.

    Args:
      orig_request: An ApiRequest, the original request from the user.
      start_response: A function with semantics defined in PEP-333.

    Returns:
      A string containing the response body.