public function respond(HTTPRequest $request, $extraCallbacks = array())
    {
        // Prepare the default options and combine with the others
        $callbacks = array_merge($this->callbacks, $extraCallbacks);
        $response = $this->getResponse();

        $responseParts = array();

        if (isset($this->fragmentOverride)) {
            $fragments = $this->fragmentOverride;
        } elseif ($fragmentStr = $request->getHeader('X-Pjax')) {
            $fragments = explode(',', $fragmentStr);
        } else {
            if ($request->isAjax()) {
                throw new HTTPResponse_Exception("Ajax requests to this URL require an X-Pjax header.", 400);
            } elseif (empty($callbacks['default'])) {
                throw new HTTPResponse_Exception("Missing default response handler for this URL", 400);
            }
            $response->setBody(call_user_func($callbacks['default']));
            return $response;
        }

        // Execute the fragment callbacks and build the response.
        foreach ($fragments as $fragment) {
            if (isset($callbacks[$fragment])) {
                $res = call_user_func($callbacks[$fragment]);
                $responseParts[$fragment] = $res ? (string) $res : $res;
            } else {
                throw new HTTPResponse_Exception("X-Pjax = '$fragment' not supported for this URL.", 400);
            }
        }
        $response->setBody(json_encode($responseParts));
        $response->addHeader('Content-Type', 'application/json');

        return $response;
    }