public function HttpController::resolve in JSON-RPC 8
Same name and namespace in other branches
- 2.x src/Controller/HttpController.php \Drupal\jsonrpc\Controller\HttpController::resolve()
Resolves an RPC request over HTTP.
Parameters
\Symfony\Component\HttpFoundation\Request $http_request: The HTTP request.
Return value
\Drupal\Core\Cache\CacheableResponseInterface The HTTP response.
1 string reference to 'HttpController::resolve'
File
- src/
Controller/ HttpController.php, line 74
Class
- HttpController
- The main front controller.
Namespace
Drupal\jsonrpc\ControllerCode
public function resolve(Request $http_request) {
// Map the HTTP request to an RPC request.
try {
$rpc_requests = $this
->getRpcRequests($http_request);
} catch (JsonRpcException $e) {
return $this
->exceptionResponse($e, Response::HTTP_BAD_REQUEST);
}
// Execute the RPC request and get the RPC response.
try {
$rpc_responses = $this
->getRpcResponses($rpc_requests);
// If no RPC response(s) were generated (happens if all of the request(s)
// were notifications), then return a 204 HTTP response.
if (empty($rpc_responses)) {
return CacheableJsonResponse::create(NULL, Response::HTTP_NO_CONTENT);
}
// Map the RPC response(s) to an HTTP response.
$is_batched_response = count($rpc_requests) !== 1 || $rpc_requests[0]
->isInBatch();
return $this
->getHttpResponse($rpc_responses, $is_batched_response);
} catch (JsonRpcException $e) {
return $this
->exceptionResponse($e, Response::HTTP_INTERNAL_SERVER_ERROR);
}
}