Output a HTTP response with optional context
@param Responses\Response $response
@param Context            $context
@return void
969658
public function response($response, $context = null)
    {
        $responseMessage = $response->asResponseMessage($context);
        $this->responseMessage($responseMessage);
    }
783843
public static function sendResponse(ResponseInterface $response) 
    {
		$code = $response->getStatusCode();
		$reason = $response->getReasonPhrase();
		header(
			sprintf('HTTP/%s %s %s', $response->getProtocolVersion(), $code, $reason),
			true, $code 
		);

		foreach ($response->getHeaders() as $header => $values) {
			foreach ($values as $value) {
				header("$header: $value", false);
			}
		}

		echo $response->getBody();
	}
93288
public function execute($response) {
        global $CFG, $DB;

        $params = $this->parse_template();
        $contextid = $params['context_id'];
        $itemid = $params['item_id'];

        // GET is disabled by the moment, but we have the code ready
        // for a future implementation.

        $isget = $response->get_request_method() === 'GET';
        if ($isget) {
            $contenttype = $response->get_accept();
        } else {
            $contenttype = $response->get_content_type();
        }
        $container = empty($contenttype) || ($contenttype === $this->formats[0]);
        // We will receive typeid when working with LTI 1.x, if not the we are in LTI 2.
        $typeid = optional_param('type_id', null, PARAM_ALPHANUM);
        if (is_null($typeid)) {
            if (!$this->check_tool_proxy(null, $response->get_request_data())) {
                $response->set_code(403);
                return;
            }
        } else {
            switch ($response->get_request_method()) {
                case 'GET':
                    $response->set_code(405);
                    $response->set_reason("GET requests are not allowed.");
                    return;
                case 'POST':
                    if (!$this->check_type($typeid, $contextid, 'Score.collection:post', $response->get_request_data())) {
                        $response->set_code(401);
                        $response->set_reason("This resource does not support POST requests.");
                        return;
                    }
                    break;
                default:  // Should not be possible.
                    $response->set_code(405);
                    return;
            }
        }
        if (empty($contextid) || !($container ^ ($response->get_request_method() === 'POST')) ||
                (!empty($contenttype) && !in_array($contenttype, $this->formats))) {
            $response->set_code(400);
            return;
        }
        if (!$DB->record_exists('course', array('id' => $contextid))) {
            $response->set_code(404);
            $response->set_reason("Not Found: Course $contextid doesn't exist.");
            return;
        }
        if (!$DB->record_exists('grade_items', array('id' => $itemid))) {
            $response->set_code(404);
            $response->set_reason("Not Found: Grade item $itemid doesn't exist.");
            return;
        }
        $item = $this->get_service()->get_lineitem($contextid, $itemid, $typeid);
        if ($item === false) {
            $response->set_code(403);
            $response->set_reason("Line item does not exist.");
            return;
        }
        $gbs = gradebookservices::find_ltiservice_gradebookservice_for_lineitem($itemid);
        $ltilinkid = null;
        if (isset($item->iteminstance)) {
            $ltilinkid = $item->iteminstance;
        } else if ($gbs && isset($gbs->ltilinkid)) {
            $ltilinkid = $gbs->ltilinkid;
        }
        if ($ltilinkid != null) {
            if (is_null($typeid)) {
                if (isset($item->iteminstance) && (!gradebookservices::check_lti_id($ltilinkid, $item->courseid,
                        $this->get_service()->get_tool_proxy()->id))) {
                    $response->set_code(403);
                    $response->set_reason("Invalid LTI id supplied.");
                    return;
                }
            } else {
                if (isset($item->iteminstance) && (!gradebookservices::check_lti_1x_id($ltilinkid, $item->courseid,
                        $typeid))) {
                    $response->set_code(403);
                    $response->set_reason("Invalid LTI id supplied.");
                    return;
                }
            }
        }
        $json = '[]';
        require_once($CFG->libdir.'/gradelib.php');
        switch ($response->get_request_method()) {
            case 'GET':
                $response->set_code(405);
                $response->set_reason("GET requests are not allowed.");
                break;
            case 'POST':
                try {
                    $json = $this->get_json_for_post_request($response, $response->get_request_data(), $item, $contextid, $typeid);
                    $response->set_content_type($this->formats[1]);
                } catch (\Exception $e) {
                    $response->set_code($e->getCode());
                    $response->set_reason($e->getMessage());
                }
                break;
            default:  // Should not be possible.
                $response->set_code(405);
                $response->set_reason("Invalid request method specified.");
                return;
        }
        $response->set_body($json);
    }
477545
protected function processApiResponseContextErrors(ResponseContextAbstract $responseContext): void
    {
        if ($responseContext->hasHttpError()) {
            $jsonResponse = new JsonResponseContext($responseContext->getRaw());

            $responseArray = $jsonResponse->getArray();

            $this->filterIbmWatsonSpecificErrors($responseArray);
        }

        parent::processApiResponseContextErrors($responseContext);
    }
627345
public function output($response)
    {
        // Set format
        switch ($this->format) {
            case 'json':
                $response = array_merge_recursive($response, $this->extra);
                $this->header('Content-type: application/json; charset=utf-8');
                $response = json_encode($response);

                // Replace string numbers for integers
                $response = preg_replace('/(")([0-9]+)(")/is', '\\2', $response);
                break;
            case 'html':
                $this->header('Content-type: text/html; charset=utf-8');
                $response = $this->html($response);
                break;
        }

        // Set cookies
        foreach ($this->cookies as $key => $value) {
            setcookie($key, $value, time() + 3600, '/');
        }

        // Set headers
        foreach ($this->headers as $header) {
            header($header);
        }

        // Return response
        echo $response;
        exit;
    }
120663
public function sendResponseHttpHeaders(ResponseInterface $response):void
    {
        // checking
        if (headers_sent()) {
            throw new ResponseSenderException("A response has already been sent to the web browser",
                $this);
        }

        // removing PHP native HTTP headers (if enabled)
        if ($this->removePhpHttpHeaders) {
            foreach (headers_list() as $header) {
                header_remove(explode(":", $header)[0]);
            }
        }

        // sending response HTTP headers
        $this->sendHttpVersionHeader(
            $response->getProtocolVersion(),
            $response->getStatusCode(),
            $response->getReasonPhrase()
        );
        $this->sendHttpHeaders($this->listResponseHeaders($response));
    }
1090873
public function transform(ApiRequest $request, ApiResponse $response, array $context = []): ApiResponse
	{
		if (isset($context['exception'])) {
			// Convert exception to json
			$content = Json::encode($this->extractException($request, $response, $context));
			if ($context['exception'] instanceof ClientErrorException || $context['exception'] instanceof ServerErrorException) {
				$response = $response->withStatus($context['exception']->getCode());
			} else {
				$response = $response->withStatus(500);
			}
		} else {
			// Convert data to array to json
			$content = Json::encode($this->extractData($request, $response, $context));
		}

		$response->getBody()->write($content);

		// Setup content type
		return $response
			->withHeader('Content-Type', 'application/json');
	}
438297
public function redirect(AnCommandContext $context)
    {
        $url = null;

        if ($context->action == 'delete') {
            $url = 'option=com_'.$this->getIdentifier()->package.'&view='.AnInflector::pluralize($this->getIdentifier()->name);
        } elseif ($context->action == 'add') {
            $url = $context->result->getURL().'&get=settings';
        }

        if ($url) {
            $context->response->setRedirect(route($url));
        }
    }
1212949
protected function _processHandler(Context $c, $handler, &$response): bool
  {
    $processed = $handler !== null && !is_string($handler);
    while(is_callable($handler))
    {
      $handler = $handler($c);
    }

    if($handler instanceof ContextAware)
    {
      $handler->setContext($c);
    }

    if($handler instanceof Handler)
    {
      $c->events()->trigger(PreExecuteEvent::i($c, $handler));
      $response = $handler->handle($c);
      return true;
    }

    if($handler)
    {
      $response = $handler;
    }

    return $processed;
  }
1285929
public function prepareForResponse(\n2n\web\http\Response $response) {
		$this->jsonResponse->prepareForResponse($response);
	}
292218
def render_to_response(self, context, **response_kwargs):
        
        response_kwargs['content_type'] = 'application/json'
        return self.response_class(
            self.convert_context_to_json(context),
            **response_kwargs
        )
172
public function addResponse($key, array $response)
    {
        $originalRequest = isset($this->request[$key]) ? $this->request[$key] : null;
        $responseBody = isset($response['body']) ? $response['body'] : null;
        $responseError = isset($response['error']) ? $response['error'] : null;
        $responseMethod = isset($response['method']) ? $response['method'] : null;

        $this->responses[$key] = new Response($originalRequest, $responseBody, $responseError, $responseMethod);
    }
1188645
public function execute(Framework $framework, WebRequest $request, Response $response)
    {
        $renderedOutput = $this->render('\\Zepi\\Web\\AccessControl\\Templates\\NoAccessMessage');
        
        $response->setOutput($renderedOutput);
    }
1130948
public function call(Request $request, Response $response) : Response {

		return call_user_func($this->callable, $request, $response, $this->slugs);

	}
96649
public function header(ResponseInterface $response = null)
    {
        if (null === $response) {
            /** @var PageInterface $page */
            $page = $this['page'];
            $response = new Response($page->httpResponseCode(), $page->httpHeaders(), '');
        }

        header("HTTP/{$response->getProtocolVersion()} {$response->getStatusCode()} {$response->getReasonPhrase()}");
        foreach ($response->getHeaders() as $key => $values) {
            foreach ($values as $i => $value) {
                header($key . ': ' . $value, $i === 0);
            }
        }
    }
1320972
public static function render($object, string $context = null): void
    {
        self::$renderer->render($object, $context);
    }
66483
protected function _actionValidate($context)
    {
        $data = $context->data;
        $key = $data->key;
        $value = $data->value;
        $method = 'validate'.ucfirst($key);
        $result = true;
        $result = $this->getValidator()->$method($value);
        $output = $this->getValidator()->getMessage();

        if ($result === false) {
            $context->response->status = AnHttpResponse::PRECONDITION_FAILED;

            if (is_string($output)) {
                $output = array('errorMsg' => $output);
            }

            $context->response->validation = json_encode($output);
        } else {
            $context->response->validation = json_encode($output);
        }
    }