Dispatcher that handles requests to the built-in apiserver handlers.
def google.appengine.tools.devappserver2.endpoints.endpoints_server.EndpointsDispatcher.__init__ |
( |
|
self, |
|
|
|
dispatcher, |
|
|
|
config_manager = None |
|
) |
| |
Constructor for EndpointsDispatcher.
Args:
dispatcher: A Dispatcher instance that can be used to make HTTP requests.
config_manager: An ApiConfigManager instance that allows a caller to
set up an existing configuration for testing.
def google.appengine.tools.devappserver2.endpoints.endpoints_server.EndpointsDispatcher.__call__ |
( |
|
self, |
|
|
|
environ, |
|
|
|
start_response |
|
) |
| |
Handle an incoming request.
Args:
environ: An environ dict for the request as defined in PEP-333.
start_response: A function used to begin the response to the caller.
This follows the semantics defined in PEP-333. In particular, it's
called with (status, response_headers, exc_info=None), and it returns
an object with a write(body_data) function that can be used to write
the body of the response.
Yields:
An iterable over strings containing the body of the HTTP response.
def google.appengine.tools.devappserver2.endpoints.endpoints_server.EndpointsDispatcher.call_spi |
( |
|
self, |
|
|
|
orig_request, |
|
|
|
start_response |
|
) |
| |
Generate SPI 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.
def google.appengine.tools.devappserver2.endpoints.endpoints_server.EndpointsDispatcher.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.
def google.appengine.tools.devappserver2.endpoints.endpoints_server.EndpointsDispatcher.check_error_response |
( |
|
self, |
|
|
|
response |
|
) |
| |
Raise an exception if the response from the SPI was an error.
Args:
response: A ResponseTuple containing the backend response.
Raises:
BackendError if the response is an error.
def google.appengine.tools.devappserver2.endpoints.endpoints_server.EndpointsDispatcher.dispatch |
( |
|
self, |
|
|
|
request, |
|
|
|
start_response |
|
) |
| |
Handles dispatch to apiserver handlers.
This typically ends up calling start_response and returning the entire
body of the response.
Args:
request: An ApiRequest, the request from the user.
start_response: A function with semantics defined in PEP-333.
Returns:
A string, the body of the response.
def google.appengine.tools.devappserver2.endpoints.endpoints_server.EndpointsDispatcher.dispatch_non_api_requests |
( |
|
self, |
|
|
|
request, |
|
|
|
start_response |
|
) |
| |
Dispatch this request if this is a request to a reserved URL.
If the request matches one of our reserved URLs, this calls
start_response and returns the response body. This also handles OPTIONS
CORS requests.
Args:
request: An ApiRequest, the request from the user.
start_response: A function with semantics defined in PEP-333.
Returns:
None if the request doesn't match one of the reserved URLs this
handles. Otherwise, returns the response body.
def google.appengine.tools.devappserver2.endpoints.endpoints_server.EndpointsDispatcher.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.
def google.appengine.tools.devappserver2.endpoints.endpoints_server.EndpointsDispatcher.get_api_configs |
( |
|
self | ) |
|
Makes a call to the BackendService.getApiConfigs endpoint.
Returns:
A ResponseTuple containing the response information from the HTTP
request.
def google.appengine.tools.devappserver2.endpoints.endpoints_server.EndpointsDispatcher.handle_api_explorer_request |
( |
|
self, |
|
|
|
request, |
|
|
|
start_response |
|
) |
| |
Handler for requests to _ah/api/explorer.
This calls start_response and returns the response body.
Args:
request: An ApiRequest, the request from the user.
start_response: A function with semantics defined in PEP-333.
Returns:
A string containing the response body (which is empty, in this case).
def google.appengine.tools.devappserver2.endpoints.endpoints_server.EndpointsDispatcher.handle_api_static_request |
( |
|
self, |
|
|
|
request, |
|
|
|
start_response |
|
) |
| |
Handler for requests to _ah/api/static/.*.
This calls start_response and returns the response body.
Args:
request: An ApiRequest, the request from the user.
start_response: A function with semantics defined in PEP-333.
Returns:
A string containing the response body.
def google.appengine.tools.devappserver2.endpoints.endpoints_server.EndpointsDispatcher.handle_get_api_configs_response |
( |
|
self, |
|
|
|
api_config_response |
|
) |
| |
Parses the result of GetApiConfigs and stores its information.
Args:
api_config_response: The ResponseTuple from the GetApiConfigs call.
Returns:
True on success, False on failure
def google.appengine.tools.devappserver2.endpoints.endpoints_server.EndpointsDispatcher.handle_spi_response |
( |
|
self, |
|
|
|
orig_request, |
|
|
|
spi_request, |
|
|
|
response, |
|
|
|
method_config, |
|
|
|
start_response |
|
) |
| |
Handle SPI response, transforming output as needed.
This calls start_response and returns the response body.
Args:
orig_request: An ApiRequest, the original request from the user.
spi_request: An ApiRequest, the transformed request that was sent to the
SPI handler.
response: A ResponseTuple, the response from the SPI handler.
method_config: A dict, the API config of the method to be called.
start_response: A function with semantics defined in PEP-333.
Returns:
A string containing the response body.
def google.appengine.tools.devappserver2.endpoints.endpoints_server.EndpointsDispatcher.lookup_rest_method |
( |
|
self, |
|
|
|
orig_request |
|
) |
| |
Looks up and returns rest method for the currently-pending request.
Args:
orig_request: An ApiRequest, the original request from the user.
Returns:
A tuple of (method descriptor, parameters), or (None, None) if no method
was found for the current request.
def google.appengine.tools.devappserver2.endpoints.endpoints_server.EndpointsDispatcher.lookup_rpc_method |
( |
|
self, |
|
|
|
orig_request |
|
) |
| |
Looks up and returns RPC method for the currently-pending request.
Args:
orig_request: An ApiRequest, the original request from the user.
Returns:
The RPC method descriptor that was found for the current request, or None
if none was found.
def google.appengine.tools.devappserver2.endpoints.endpoints_server.EndpointsDispatcher.transform_jsonrpc_request |
( |
|
self, |
|
|
|
orig_request |
|
) |
| |
Translates a JsonRpc request/response into apiserving request/response.
Args:
orig_request: An ApiRequest, the original request from the user.
Returns:
A new request with the request_id updated and params moved to the body.
def google.appengine.tools.devappserver2.endpoints.endpoints_server.EndpointsDispatcher.transform_jsonrpc_response |
( |
|
self, |
|
|
|
spi_request, |
|
|
|
response_body |
|
) |
| |
Translates an apiserving response to a JsonRpc response.
Args:
spi_request: An ApiRequest, the transformed request that was sent to the
SPI handler.
response_body: A string containing the backend response to transform
back to JsonRPC.
Returns:
A string with the updated, JsonRPC-formatted request body.
def google.appengine.tools.devappserver2.endpoints.endpoints_server.EndpointsDispatcher.transform_request |
( |
|
self, |
|
|
|
orig_request, |
|
|
|
params, |
|
|
|
method_config |
|
) |
| |
Transforms orig_request to apiserving request.
This method uses orig_request to determine the currently-pending request
and returns a new transformed request ready to send to the SPI. This
method accepts a rest-style or RPC-style request.
Args:
orig_request: An ApiRequest, the original request from the user.
params: A dictionary containing path parameters for rest requests, or
None for an RPC request.
method_config: A dict, the API config of the method to be called.
Returns:
An ApiRequest that's a copy of the current request, modified so it can
be sent to the SPI. The path is updated and parts of the body or other
properties may also be changed.
def google.appengine.tools.devappserver2.endpoints.endpoints_server.EndpointsDispatcher.transform_rest_request |
( |
|
self, |
|
|
|
orig_request, |
|
|
|
params, |
|
|
|
method_parameters |
|
) |
| |
Translates a Rest request into an apiserving request.
This makes a copy of orig_request and transforms it to apiserving
format (moving request parameters to the body).
The request can receive values from the path, query and body and combine
them before sending them along to the SPI server. In cases of collision,
objects from the body take precedence over those from the query, which in
turn take precedence over those from the path.
In the case that a repeated value occurs in both the query and the path,
those values can be combined, but if that value also occurred in the body,
it would override any other values.
In the case of nested values from message fields, non-colliding values
from subfields can be combined. For example, if '?a.c=10' occurs in the
query string and "{'a': {'b': 11}}" occurs in the body, then they will be
combined as
{
'a': {
'b': 11,
'c': 10,
}
}
before being sent to the SPI server.
Args:
orig_request: An ApiRequest, the original request from the user.
params: A dict with URL path parameters extracted by the config_manager
lookup.
method_parameters: A dictionary containing the API configuration for the
parameters for the request.
Returns:
A copy of the current request that's been modified so it can be sent
to the SPI. The body is updated to include parameters from the
URL.
def google.appengine.tools.devappserver2.endpoints.endpoints_server.EndpointsDispatcher.transform_rest_response |
( |
|
self, |
|
|
|
response_body |
|
) |
| |
Translates an apiserving REST response so it's ready to return.
Currently, the only thing that needs to be fixed here is indentation,
so it's consistent with what the live app will return.
Args:
response_body: A string containing the backend response.
Returns:
A reformatted version of the response JSON.
def google.appengine.tools.devappserver2.endpoints.endpoints_server.EndpointsDispatcher.verify_response |
( |
|
response, |
|
|
|
status_code, |
|
|
|
content_type = None |
|
) |
| |
|
static |
Verifies that a response has the expected status and content type.
Args:
response: The ResponseTuple to be checked.
status_code: An int, the HTTP status code to be compared with response
status.
content_type: A string with the acceptable Content-Type header value.
None allows any content type.
Returns:
True if both status_code and content_type match, else False.
The documentation for this class was generated from the following file:
- code/googleappengine-read-only/python/google/appengine/tools/devappserver2/endpoints/endpoints_server.py