def check_empty_response(self, orig_request, method_config, start_response): """If the response from the SPI is empty, return a HTTP 204 No Content. Args: orig_request: An ApiRequest, the original request from the user. method_config: A dict, the API config of the method to be called. start_response: A function with semantics defined in PEP-333. Returns: If the SPI response was empty, this returns a string containing the response body that should be returned to the user. If the SPI response wasn't empty, this returns None, indicating that we should not exit early with a 204. """ response_config = method_config.get('response', {}).get('body') if response_config == 'empty': # The response to this function should be empty. We should return a 204. # Note that it's possible that the SPI returned something, but we'll # ignore it. This matches the behavior in the Endpoints server. cors_handler = EndpointsDispatcher.__CheckCorsHeaders(orig_request) return util.send_wsgi_no_content_response(start_response, cors_handler)
def test_send_wsgi_no_content_response(self): response = util.send_wsgi_no_content_response(self.start_response) self.assert_http_match(response, 204, [('Content-Length', '0')], '')