Add a next link for search results

@param \WP_REST_Request $request
@param \WP_REST_Response $response
352874
protected function addNextSearchLinks( $request, $response ) {

		$max_pages = (int) ceil( $this->totalBooks / (int) $request['per_page'] );

		$response->header( 'X-WP-Total', (int) $this->totalBooks );
		$response->header( 'X-WP-TotalPages', $max_pages );

		if ( $this->lastKnownBookId ) {
			unset( $request['page'] );
			$request_params = $request->get_query_params();
			$base = add_query_arg( $request_params, rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) );
			$next_link = add_query_arg( 'next', $this->lastKnownBookId, $base );
			$response->link_header( 'next', $next_link );
		}
	}
1007273
public static function respond(Response $response)
    {
        $next = function () use ($response) {
            return $response;
        };

        (new static())->handle(Request::capture(), $next)->send();

        exit;
    }
1193656
private function addLinkHeader(Response $response, $link)
    {
        if ($response->headers->get('Link')) {
            $link = $response->headers->get('Link') . ',' . $link;
        }

        $response->header('Link', $link);
    }
726538
public function decorateResponse(Request $request, Response $response)
    {
        if ($request->headers->has(self::ORIGIN_REQUEST_HEADER)) {
            $request->headers->set('referer', $request->headers->get(self::ORIGIN_REQUEST_HEADER));
        }

        $this->setTurbolinksLocationHeaderFromSession($request, $response);

        if ($response->isRedirect() && $response->headers->has(self::ORIGIN_RESPONSE_HEADER)) {
            $this->redirectTo($request, $response);
        }

        $this->modifyStatusCode($request, $response);
    }
1341537
public function fetchCookies($request, $response)
    {
        foreach ($response->cookies($request) as $cookie) {
            $this->add($cookie);
        }
        return $this;
    }
174730
protected function notFound(ServerRequestInterface $request, ResponseInterface $response)
    {
        $finalResponse = $response
            ->withProtocolVersion($request->getProtocolVersion())
            ->withStatus(404)
            ->withHeader('Content-Type', 'text/plain');
        
        $finalResponse->getBody()->write("Not found");
        
        return $finalResponse;
    }
936363
public function overrideResponse( $response, $post, $request ) {

		if ( $post->post_type === 'chapter' ) {
			// Add rest link to associated part
			$response->add_link( 'part', trailingslashit( rest_url( sprintf( '%s/%s', $this->namespace, 'parts' ) ) ) . $post->post_parent );
		}

		if ( in_array( $post->post_type, [ 'front-matter', 'chapter', 'back-matter', 'glossary' ], true ) ) {
			// Add rest link to metadata
			$response->add_link( 'metadata', trailingslashit( rest_url( sprintf( '%s/%s/%d/metadata', $this->namespace, $this->rest_base, $post->ID ) ) ) );
		}

		// Check that we are in view/embed context (and)
		// Check that content is password protected (and)
		// Check that content is empty (if not then API has already verified that the user can_access_password_content)
		if ( in_array( $request['context'], [ 'view', 'embed' ], true ) ) {
			if ( ! empty( $response->data['content'] ) ) {
				if ( $response->data['content']['protected'] && empty( $response->data['content']['rendered'] ) ) {
					// Hide raw data
					$response->data['content']['raw'] = '';
				}
			}
			if ( ! empty( $response->data['excerpt'] ) ) {
				if ( $response->data['excerpt']['protected'] && empty( $response->data['excerpt']['rendered'] ) ) {
					// Hide raw data
					$response->data['excerpt']['raw'] = '';
				}
			}
		}

		return $response;
	}
1258259
private function generatePagingLinksHeaders($routeName, Request $request, Response $response)
    {
        $rql = '';
        if ($request->attributes->get('hasRql', false)) {
            $rql = $request->attributes->get('rawRql', '');
        }

        $this->generateLinks(
            $routeName,
            $request->attributes->get('page'),
            $request->attributes->get('numPages'),
            $request->attributes->get('perPage'),
            $request,
            $rql
        );

        $response->headers->set(
            'X-Total-Count',
            (string) $request->attributes->get('totalCount')
        );
    }
871908
public function run(ServerRequestInterface $request, ResponseInterface $response, $next = null)
    {
        if (!$request->getAttribute('route') instanceof Route) {
            $route = $this->routes->getRoute($request);

            if (!$route) {
                return $this->notFound($request, $response);
            }

            $request = $request->withAttribute('route', $route);
        }
        
        $runner = $this->getRunner();

        return $runner($request, $response, $next);
    }
261448
function(request, response, next){
		if (!utils.Misc.isNullOrUndefined(request.user)) {
			next();
		}
		else {
			var error = new Error(errors['213']);
			response.end(utils.Misc.createResponse(null, error, 213));
		}
	}
1079509
public static void addOrigHeader(HttpServletResponse response, String url) {
		response.setHeader(LINK, makeLink(url, ORIGINAL));
	}
115981
public function onHttpRequest(\React\Http\Request $request, $response)
    {
        if ($request->getPath() !== "/auth/github/callback") {
            $response->writeHead(404, ['Content-Type' => 'text/plain']);
            $response->end("Not Found");
            return;
        }

        $query = $request->getQuery();
        if (!isset($query['state']) || !isset($query['code'])) {
            $response->writeHead(200, ['Content-Type' => 'text/plain']);
            $response->end("No Code or State query params found");
            return;
        }

        //If we don't already have a promise for this state, create one
        if (!isset($this->promises[$query['state']])) {
            $deferred                        = new Deferred();
            $this->promises[$query['state']] = $deferred;
        }

        $accessToken = $this->getAccessToken($query['code']);
        if ($accessToken) {
            $email = $this->getEmails($accessToken)[0]->email;
            $this->promises[$query['state']]->resolve(["SUCCESS", ["authid" => $email]]);

        } else {
            $this->promises[$query['state']]->resolve(["FAILURE"]);
        }

        $response->writeHead(200, ['Content-Type' => 'text/html']);
        $response->end("<script>window.close();</script>");


    }
1198069
private function getInfoResponse(Request $request, Response $response)
    {
        try {
            $this->video->getJson();
        } catch (PasswordException $e) {
            return $this->password($request, $response);
        }

        if (isset($this->video->entries)) {
            $template = 'playlist.tpl';
        } else {
            $template = 'info.tpl';
        }
        $title = _('Video download');
        $description = _('Download video from ').$this->video->extractor_key;
        if (isset($this->video->title)) {
            $title = $this->video->title;
            $description = _('Download').' "'.$this->video->title.'" '._('from').' '.$this->video->extractor_key;
        }
        $this->view->render(
            $response,
            $template,
            [
                'video'         => $this->video,
                'class'         => 'info',
                'title'         => $title,
                'description'   => $description,
                'config'        => $this->config,
                'canonical'     => $this->getCanonicalUrl($request),
                'locale'        => $this->localeManager->getLocale(),
                'defaultFormat' => $this->defaultFormat,
            ]
        );

        return $response;
    }
69367
function getNextPageUrl(response) {
  const link = response.headers.get('link');
  if (!link) {
    return null;
  }

  const nextLink = link.split(',').filter(s => s.indexOf('rel="next"') > -1)[0];
  if (!nextLink) {
    return null;
  }

  return nextLink.split(';')[0].slice(1, -1);
}
1365425
public function showDataCollection(Request $request, Response $response)
    {
        $url = $request->getRequestUri();

        // do not capture redirects or modify XML HTTP Requests
        if ($request->isXmlHttpRequest() || $this->adminRouteHelper->isAdminRoute($url) || !$this->isEnabled()) {
            return false;
        }

        if ($response->isRedirection() || ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html'))
            || 'html' !== $request->getRequestFormat()
            || false !== stripos($response->headers->get('Content-Disposition'), 'attachment;')
        ) {
            return false;
        }

        return true;
    }
243480
private function nextPage(JobConfig $config, $response, $data)
    {
        return $this->getScroller()->getNextRequest($this->client, $config, $response, $data);
    }
616400
protected function getHttpResponse($request = null, $response = null)
    {
        // Response cache content
        $is_cache = false;
        $cache_type = null;
        $page_cache_config = Lb::app()->getPageCacheConfig();
        $routeInfo = $this->route_info;
        if (isset($page_cache_config['controllers'][$routeInfo['controller']][$routeInfo['action']])) {
            $is_cache = true;
            $cache_type = $page_cache_config['controllers'][$routeInfo['controller']][$routeInfo['action']];
            if ($page_cache = $this->getPageCache($cache_type)) {
                return $page_cache;
            }
        }

        // Route
        $hproseConfig = Lb::app()->getHproseConfig();
        $thriftProviderConfig = Lb::app()->getThriftProviderConfig();
        if (!empty($thriftProviderConfig[$routeInfo['controller']][$routeInfo['action']])) {
            Route::thrift($routeInfo);
        } elseif (!empty($hproseConfig[$routeInfo['controller']][$routeInfo['action']])) {
            Route::hprose($routeInfo, $request, $response);
        } else {
            ob_start();
            Route::runWebAction($routeInfo, $request, $response);
            $page_content = ob_get_contents();
            ob_end_clean();
            $page_content = $this->compressPage($page_content);
            $is_cache && $this->setPageCache($cache_type, $page_content);
            return $page_content;
        }

        return '';
    }