Handles the request and returns the response.

@return Response the browser response
@throws Exception\HTTPStatus502Exception
484998
public function handle()
    {
        try {
            $event = new BeforeProxyEvent($this->proxy_query);
            $this->event_dispatcher->dispatch('owsproxy.before_proxy', $event);
        } catch (\RuntimeException $e) {
            throw new HTTPStatus502Exception();
        }

        $browserResponse = parent::handle();

        if ($browserResponse->isOk()) {
            $event = new AfterProxyEvent($this->proxy_query, $browserResponse);
            $this->event_dispatcher->dispatch('owsproxy.after_proxy', $event);
        } else {
            // pass auth challenge down to client, but alter realm to make it
            // unique as it will be applied to this server as the auth
            // partition key!
            if (401 === $browserResponse->getStatusCode()) {
                $headers = $browserResponse->getHeaders();
                $needle = 'www-authenticate: basic realm="';
                foreach ($headers as $idx => &$header) {
                    $haystack = strtolower($header);
                    if (0 === strpos($haystack, $needle)) {
                        $origRealm = substr($header, strlen($needle), strlen($header) - strlen($needle) - 1);
                        $rawUrl = $this->proxy_query->getRowUrl(); // ;)

                        $scheme = empty($rawUrl["scheme"]) ? "http://" : $rawUrl["scheme"] . "://";
                        $host = $rawUrl["host"];
                        $port = empty($rawUrl["port"]) ? "" : ":" . $rawUrl["port"];
                        $path = empty($rawUrl["path"]) ? "" : $rawUrl["path"];
                        $server = $scheme . $host . $port . $path;
                        $realm = 'Server: ' . $server . ' - ' . $origRealm;
                        $header = 'WWW-Authenticate: Basic realm="' . $realm . '"';

                        $browserResponse->setHeaders($headers);
                        break;
                    }
                }
                return $browserResponse;
            }
            $message = null;
            if ($browserResponse->getReasonPhrase() !== null) {
                $rawUrl = $this->proxy_query->getRowUrl();
                $message = 'Server "' . $rawUrl['host'] . '" says: ' . $browserResponse->getReasonPhrase();
                throw new HTTPStatus502Exception($message);
            } else {
                throw new HTTPStatus502Exception();
            }
        }
        return $browserResponse;
    }
1015181
public function execute()
    {
        $this->getFields();
        $this->getPagination();
        $this->getHighlight();
        $this->getSuggest();
        $this->getAggregations();
        $this->getSort();
        $this->getPayload();

        $params = [
            'index' => Utils::findKey($this->options, 'index', false) ?: $this->proxy->getIndex()->getName(),
            'type' => Utils::findKey($this->options, 'type', false) ?: $this->proxy->getType(),
            'body' => $this->payload
        ];

        return new Response($this->proxy->getModel(), $this->proxy->getClient()->search($params));
    }
1058375
public function handler(): Response
    {
        $data = $this->validate([
            'email' => [
                new Email()
            ],
            'phone' => []
        ]);
        $member = Member::search($this->getParameter('username'));
        if (!$member) {
            throw new HttpNotFoundException();
        }
        $member->update($data);
        $this->log('info', 'Update member [' . $member->getUsername() . ']');
        return response();
    }
1111036
protected function handleHead() : HttpResponse
    {
        $key = $this->request->key();

        if ( ! $fileMeta = $this->cache->get($key)) {
            return $this->response->send(null, HttpResponse::HTTP_NOT_FOUND);
        }

        $offset = $fileMeta['offset'] ?? false;

        if (false === $offset) {
            return $this->response->send(null, HttpResponse::HTTP_GONE);
        }

        return $this->response->send(null, HttpResponse::HTTP_OK, $this->getHeadersForHeadRequest($fileMeta));
    }
500975
public function handler(): Response
    {
        $mailer = new Mailer([
            'driver' => 'smtp',
            'host' => 'host',
            'port' => 0,
            'encryption' => '',
            'username' => 'username',
            'password' => 'password',
            'sender' => 'sender',
            'remark' => ''
        ]);
        if (Mailer::count() === 0) {
            $mailer->default(true);
        }
        $mailer->save();
        $this->log('info', 'Create a mailer [' . $mailer->getSender() . ']');
        return response([
            'id' => $mailer->getId()
        ]);
    }
469200
public function getResponse()
    {
        $this->matcher = new UrlMatcher($this->routes, $this->context);

        $this->parameters = $this->matcher->matchRequest($this->request);

        $controller = $this->parameters['_controller'];
        if ($controller === null) {
            $response = new Response();
        } else {
            $this->controller = new $controller($this->request, $this->parameters);
            $response = $this->controller->handler();
        }

        return $response;
    }
14885
public function handler(): Response
    {
        $mailer = Mailer::find($this->getParameter('id'));
        if (!$mailer) {
            throw new HttpForbiddenException();
        }
        foreach (Mailer::all() as $m) {
            $m->default(false)->save();
        }
        $mailer->default(true)->save();
        $this->log('info', 'Set mailer [' . $mailer->getSender() . '] as default');
        return response();
    }
1260129
private function handleResponse()
    {
        if (!$this->processor->error) {
            return $this->processor->response;
        }
        $error_message = null;
        $error_code    = null;
        if ($this->processor->error_code) {
            $error_message = $this->processor->error_message;
            $error_code    = $this->processor->error_code;
            if (empty($error_message)) {
                $response = json_decode($this->processor->response);
                $error_message = sprintf('(%u) %s: %s', $response->status, $response->reason, $response->message);
            }
        }
        throw new AuthnetCurlException(sprintf('Connection error: %s (%s)', $error_message, $error_code));
    }
669768
protected function _exec() {
        $response = curl_exec($this->_ch);
        $this->_last_info = curl_getinfo($this->_ch);
        $error = curl_error( $this->_ch );
        if ( $error ) {
            throw new \Exception($error);
        }

        return $response;
    }
844579
protected function handleOptions() : HttpResponse
    {
        $headers = [
            'Allow' => implode(',', $this->request->allowedHttpVerbs()),
            'Tus-Version' => self::TUS_PROTOCOL_VERSION,
            'Tus-Extension' => implode(',', self::TUS_EXTENSIONS),
            'Tus-Checksum-Algorithm' => $this->getSupportedHashAlgorithms(),
        ];

        $maxUploadSize = $this->getMaxUploadSize();

        if ($maxUploadSize > 0) {
            $headers['Tus-Max-Size'] = $maxUploadSize;
        }

        return $this->response->send(null, HttpResponse::HTTP_OK, $headers);
    }
834083
public function httpAction()
	{
	    $status		= self::STATUS_SUCCESS;
	    $responses	= array();
	    $exception	= null;
	    $data       = null;
        $debug      = $this->getRouteParam('debug', false); 
        
        try {
            $service	= $this->fetchService();
            $operation	= $service ? $this->fetchOperation() : false;
            
            if(!$service){
                throw new ServiceNotFoundException("Route doesn't contain service information");
            } elseif (!$operation) {
                throw new OperationNotFoundException("Route doesn't contain operation information");
            }
            
            try {
                $params = $this->fetchParams();
            } catch(\Exception $e) {
                $status = self::STATUS_MALFORMED_REQUEST;
                $exception = $e;
            }
            
            if ($status === self::STATUS_SUCCESS) {
                if (isset($params[self::HEADER_FORCE_CONTENT_HTML])) {
                    
                    if ($params[self::HEADER_FORCE_CONTENT_HTML]) {
                        $this->getRequest()->getHeaders()->addHeaders([
                                self::HEADER_FORCE_CONTENT_HTML => true
                                ]);
                    }
                    unset($params[self::HEADER_FORCE_CONTENT_HTML]);
                }
                
                $data = $this->exec(
                        $service,
                        $operation,
                        $params,
                        Command::CONTEXT_HTTP);
            }
            
        } catch (PermissionDeniedException $exception) {
            $status = self::STATUS_PERMISSION_DENIED;
        } catch (NotFoundException $exception) {
            $status = self::STATUS_NOT_FOUND;
        } catch (ServiceException $exception) {
            $status = self::STATUS_UNKNOWN_EXCEPTION;
        } catch (\Exception $exception) {
            $status = self::STATUS_UNKNOWN_EXCEPTION;
        }
	    
        // Log error
	    if ($exception) {
	        error_log($exception->getMessage() . ' (' . $exception->getFile().':'.$exception->getLine().')');
	        
	        if ($debug) {
	            throw $exception;
	        }
	    }
    
		return $this->prepareHttpResponse(
			$data, 
	        $status,
			$exception);
	}
1198798
public function handler(): Response
    {
        $data = $this->validate([
            'role_id' => [
                new NotBlank()
            ],
            'permission' => [
                new NotBlank()
            ],
            'value' => []
        ]);
        $role = Role::find($data['role_id']);
        if (!$role) {
            throw new HttpForbiddenException();
        }
        $attr = [
            'role' => $role,
            'permission' => $data['permission']
        ];
        if ($data['value'] === true) {
            (new Permission($attr))->save();
            $this->log('info', 'Add permission [' . $data['permission'] . '] of role [' . $role->getSlug() . ']');
        } else {
            $permission = Permission::findBy($attr);
            if (!$permission) {
                throw new HttpForbiddenException();
            }
            $permission->delete(true);
            $this->log('info', 'Delete permission [' . $data['permission'] . '] of role [' . $role->getSlug() . ']');
        }
        return response();
    }
91970
protected function get_response() {
        global $CFG;
        require_once($CFG->libdir.'/filelib.php');

        $curl = new \curl(array('proxy' => true));
        $response = $curl->post($this->prepare_request_url(), $this->prepare_request_params(), $this->prepare_request_options());
        $curlerrno = $curl->get_errno();
        if (!empty($curlerrno)) {
            throw new checker_exception('err_response_curl', 'cURL error '.$curlerrno.': '.$curl->error);
        }
        $curlinfo = $curl->get_info();
        if ($curlinfo['http_code'] != 200) {
            throw new checker_exception('err_response_http_code', $curlinfo['http_code']);
        }
        return $response;
    }
336806
public function handler(): Response
    {
        $data = $this->validate([
            'email' => [
                new NotBlank(),
                new Email()
            ]
        ]);
        $member = Member::findBy($data);
        if ($member) {
            $this->log('info', '[' . $data['email'] . '] get password reset token');
            $token = (new PasswordResetToken())
                ->member($member)
                ->save();
            app()->dispatch(new VerifyTokenNeedsToBeSent($member, $token->getId()));
        } else {
            $this->log('info', '[' . $data['email'] . '] failed to get password reset token');
            sleep(mt_rand(1, 3)); // avoid judging status through time used
        }
        return response();
    }
1249061
private function getResponse()
    {
        $success = $this->handler->recv();
        $this->result = new Response((string)$this->handler->body, $this->handler->statusCode);
        if($success)
        {
            // headers
            foreach($this->handler->headers as $name => $value)
            {
                $this->result = $this->result->withHeader($name, $value);
            }

            // cookies
            $cookies = [];
            if(isset($this->handler->set_cookie_headers))
            {
                foreach($this->handler->set_cookie_headers as $value)
                {
                    $list = explode(';', $value);
                    $count2 = count($list);
                    if(isset($list[0]))
                    {
                        list($cookieName, $value) = explode('=', $list[0], 2);
                        $cookieName = trim($cookieName);
                        $cookies[$cookieName] = array('value'=>$value);
                        for($j = 1; $j < $count2; ++$j)
                        {
                            $kv = explode('=', $list[$j], 2);
                            $cookies[$cookieName][trim($kv[0])] = isset($kv[1]) ? $kv[1] : true;
                        }
                    }
                }
            }
            foreach($this->handler->cookies as $name => $value)
            {
                if(!isset($cookies[$name]))
                {
                    $cookies[$name] = ['value'=>$value];
                }
            }
            $this->result = $this->result->withCookieOriginParams($cookies);
        }
        $this->result = $this->result->withError($this->getErrorString($this->handler->errCode))
                                     ->withErrno($this->handler->errCode);
        $this->handler->close();
        return $this->result;
    }
1194476
protected function getResponse()
    {
        if ($this->response === null) {
            $this->response = $this->client->send($this->request);
        }

        return $this->response;
    }
702072
public function execute()
    {
        if (! $this->ch) {
            throw new Exception('Curl request not initiated');
        }

        $statusCode = (int) isset($this->lushOptions['return_status']) ? $this->lushOptions['return_status'] : 200;
        $contentType = isset($this->lushOptions['return_content_type']) ? $this->lushOptions['return_content_type'] : 'text';

        $this->headers['url'] = $this->ch;
        $this->headers['http_code'] = $statusCode;

        $this->executed = true;

        return $this->createResponse($statusCode, $contentType);
    }