Complete the request response.
Triggers "finish" events, and returns current application instance.

@param EventManagerInterface $events
@param MvcEvent              $event
@param ResponseInterface     $response

@return $this
179387
protected function completeResponse(EventManagerInterface $events, MvcEvent $event, ResponseInterface $response)
    {
        $event->setName(MvcEvent::EVENT_FINISH);
        $event->setTarget($this);
        $event->setResponse($response);
        $event->stopPropagation(false); // Clear before triggering

        $events->triggerEvent($event);

        $this->response = $response;

        return $this;
    }
215453
public function handleXmlHttpRequest(MvcEvent $event)
	{
		$request = $event->getRequest();
		if ($request->isXMLHttpRequest()) {
			$dispatchResult = $event->getResult();
			if ($dispatchResult instanceof ViewModel) {
				$dispatchResult->setTerminal(true);
			}
		}
	}
49123
public function onDispatch(MvcEvent $event)
    {
        /* @var $response \Zend\Http\Response */
        $response = $event->getResponse();
        if (!method_exists($response, 'getStatusCode') || $response->getStatusCode() !== 404) {
            return;
        }
        $request        = $event->getRequest();
        $serviceManager = $event->getApplication()->getServiceManager();
        $assetManager   = $serviceManager->get(__NAMESPACE__ . '\Service\AssetManager');

        if (!$assetManager->resolvesToAsset($request)) {
            return;
        }

        $response->setStatusCode(200);

        return $assetManager->setAssetOnResponse($response);
    }
526756
public function processEvent(
        Interfaces\EventInterface $event,
        callable $callback = null
    )/*# : EventManagerInterface */ {
        $eventName = $event->getName();

        // check self's queue
        $queue = $this->matchEventQueue($eventName, $this);

        // merge with other managers' queue
        $managers = $this->getOtherManagers();
        foreach ($managers as $mgr) {
            // other manager's own queue
            $q = $this->matchEventQueue($eventName, $mgr);
            if ($q->count()) {
                $queue = $queue->combine($q);
            }
        }

        // run thru the queue
        return $this->runEventQueue($event, $queue, $callback);
    }
931494
public function onFinish(MvcEvent $e)
    {
        if (!$e->getRequest() instanceof HttpRequest || $this->loadedFromCache) {
            return;
        }

        $this->getCacheService()->save($e);
    }
358622
public void afterCompleted(Event event) {
		ChaincodeMessage message = messageHelper(event);
		logger.debug(String.format("[%s]sending COMPLETED to validator for tid", shortID(message)));
		try {
			serialSend(message);
		} catch (Exception e) {
			event.cancel(new Exception("send COMPLETED failed %s", e));
		}
	}
670117
public void requestCompleted (final T result)
    {
        EventQueue.invokeLater(new Runnable() {
            public void run () {
                _target.requestCompleted(result);
            }
        });
    }
478788
public function sendResponse(ResponseInterface $response)
    {
        $e = $this->getEvent();
        $e->setResponse($response);

        $e->getApplication()->getEventManager()->trigger(MvcEvent::EVENT_FINISH, $e);
        exit();
    }
1019307
public function attach(EventManagerInterface $events)
    {
        $this->listeners[] = $events->attach($this->eventBefore, array($this, 'prepareUpload'));
        $this->listeners[] = $events->attach($this->eventAfter, array($this, 'finalizeUpload'));
    }
2007
public function check(MvcEvent $event)
    {
        foreach ($this->limits as $limit) {
            if ($this->storage->check($this->remoteAddress->getIpAddress(), $limit)) {
                foreach ($limit->getActions() as $action) {
                    $action($event);
                }
            }
        }
    }
1023340
public function attach(EventManagerInterface $events)
    {
        $events->attach(
            MvcEvent::EVENT_RENDER,
            function (MvcEvent $event) {
                /** @var ServiceManager $serviceManager */
                $serviceManager = $event->getTarget()->getServiceManager();
                /** @var ControllerManager $controllerManager */
                $controllerManager = $serviceManager->get('ControllerManager');
                $routeMatch = $event->getRouteMatch();
                if ($routeMatch) {
                    $controller = $controllerManager->get($routeMatch->getParam('controller'));
                    $viewHelperManager = $serviceManager->get('ViewHelperManager');
                    /** @var Widget $widgetViewHelper */
                    $widgetViewHelper = $viewHelperManager->get('widget');
                    $widgetViewHelper->setController($controller);
                }
            },
            $this->priority
        );
    }
601450
public void onSuccessRespEvent(ResponseEvent event, ActivityContextInterface aci) {
		
		if (tracer.isFineEnabled())
			tracer.fine("Received 2xx (SUCCESS) response:\n"+event.getResponse());
		
		final SbbLocalObject sbbLocalObject = sbbContext.getSbbLocalObject();
		aci.detach(sbbLocalObject);
		
		final Response response = event.getResponse();
		final SIPETagHeader sipeTagHeader = (SIPETagHeader) response.getHeader(SIPETagHeader.NAME);
		if(sipeTagHeader != null) {
			this.setETagCMP(sipeTagHeader.getETag());
		}
				
		final PublishRequestType type = getPublishRequestTypeCMP();
		
		if (type != PublishRequestType.REMOVE) {
			final ExpiresHeader expiresHeader = (ExpiresHeader) response.getHeader(ExpiresHeader.NAME);
			if(expiresHeader!=null && expiresHeader.getExpires() != 0) {
				//update expires time.
				setExpiresCMP(expiresHeader.getExpires());
				startExpiresTimer();
			}
		}
		
		PostponedRequest postponedRequest = null;
		setPublishRequestTypeCMP(null);

		try{
			switch (type) {
			case NEW:
				postponedRequest = getPostponedRequestCMP();
				getParent().newPublicationSucceed((PublicationClientChildSbbLocalObject) sbbLocalObject);
				break;
			case REFRESH:
				postponedRequest = getPostponedRequestCMP();
				break;
			case UPDATE:
				postponedRequest = getPostponedRequestCMP();
				getParent().modifyPublicationSucceed((PublicationClientChildSbbLocalObject) sbbLocalObject);
				break;
			case REMOVE:
				getParent().removePublicationSucceed((PublicationClientChildSbbLocalObject) sbbLocalObject);
				break;
			}
		}
		catch(Exception e) {
			if(tracer.isSevereEnabled()) {
				tracer.severe("Exception in publication parent!", e);
			}
		}

		if (postponedRequest != null) {
			// refresh may be concurrent with another request, if there is a
			// postponed request resume it now
			postponedRequest.resume(this);
		}
		
	}
414994
public function onRequest(GetResponseEvent $event)
    {
        if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
            return;
        }
        $patterns = $this->provider->getPatterns();
        if ($patterns) {
            foreach ($patterns as $pattern) {
                if ($pattern['matcher']->matches($event->getRequest())) {
                   $firewall = $this->provider->getFirewall($pattern['config']);
                   $firewall->handle();
                }
            }
        }
    }
414436
public function onComplete(CompleteEvent $event)
    {
        $code = (string) $event->getResponse()->getStatusCode();
        // Throw an exception for an unsuccessful response
        if ($code[0] === '4' || $code[0] === '5') {
            throw RequestException::create($event->getRequest(), $event->getResponse());
        }
    }
448151
public function prerenderPage(MvcEvent $event)
    {
        $originalRequest = $event->getRequest();

        if (!$this->shouldPrerenderPage($originalRequest)) {
            return;
        }

        $event->stopPropagation(true);
        $eventManager = $this->getEventManager();

        // Trigger a pre-event (for creating a response from cache, for instance)
        $responses = $eventManager->trigger(PrerenderEvent::EVENT_PRERENDER_PRE, new PrerenderEvent($originalRequest));

        if ($responses->last() instanceof HttpResponse) {
            return $responses->last();
        }

        // Make the actual request to Prerender service
        $client    = $this->getHttpClient();
        $uri       = rtrim($this->moduleOptions->getPrerenderUrl(), '/') . '/' . $originalRequest->getUriString();
        $userAgent = $originalRequest->getHeaders()->get('User-Agent')->getFieldValue();

        $client->setUri($uri)
               ->setMethod(HttpRequest::METHOD_GET);

        $request = $client->getRequest();
        $request->getHeaders()->addHeaderLine('User-Agent', $userAgent)
                              ->addHeaderLine('Accept-Encoding', 'gzip');

        if ($prerenderToken = $this->moduleOptions->getPrerenderToken()) {
            $request->getHeaders()->addHeaderLine('X-Prerender-Token', $prerenderToken);
        }

        $response = $client->send($request);

        // Trigger a post-event (for putting in cache the response, for instance)
        $prerenderEvent = new PrerenderEvent($request, $response);
        $eventManager->trigger(PrerenderEvent::EVENT_PRERENDER_POST, $prerenderEvent);

        return $prerenderEvent->getResponse();
    }
701761
public function processRcmResponses(MvcEvent $event)
    {
        $response = $event->getResult();

        if (!$response instanceof RcmResponse) {
            return null;
        }

        $this->responseHandler->processResponse($response);

        return null;
    }
1085050
public function setTaskAsDone(Event $event)
    {
        $this->checkPermission($event);
        if ($event->isTaskDone()) {
            throw new \Exception('This task is already mark as done.');
        }

        $event->setIsTaskDone(true);
        $om = $this->getDoctrine()->getManager();
        $om->flush();

        return new Response();
    }