Return the response format type, derived from a Request's Accept header, and configured priorities.

@param  Request $req
@return string
346286
public function negotiateResponseFormat(Request $req)
    {
        return $this->getFormatNegotiator()->getBestFormat($req->headers->get('Accept'), $this->formatPriorities);
    }
770582
public function send(Request $request)
    {
        $response = new SearchResponse();
        $rpbReq   = $this->createRpbMessage($request);
        $rpbResp  = $this->client->send($rpbReq, RiakMessageCodes::SEARCH_QUERY_REQ, RiakMessageCodes::SEARCH_QUERY_RESP);

        if ( ! $rpbResp instanceof RpbSearchQueryResp) {
            return $response;
        }

        $response->numFound = $rpbResp->num_found;
        $response->maxScore = $rpbResp->max_score;

        if ( ! $rpbResp->hasDocs()) {
            return $response;
        }

        $response->docs = array_map([$this, 'docToArray'], $rpbResp->docs);

        return $response;
    }
690540
private function getPostRequestEncoding( Request $request ) {
		if ( $request instanceof MultipartRequest ) {
			return 'multipart';
		}
		foreach ( $request->getParams() as $value ) {
			if ( is_resource( $value ) ) {
				return 'multipart';
			}
		}
		return 'form_params';
	}
1343295
protected function getAcceptType(ServerRequestInterface $request)
    {
        $accept = $request->getHeaderLine('Accept');
        if (
            strpos($accept, 'text/html') !== false ||
            strpos($accept, 'application/xhtml+xml') !== false
        ) {
            return 'html';
        }
        if (
            strpos($accept, 'application/json') !== false ||
            strpos($accept, 'text/json') !== false ||
            strpos($accept, 'application/x-json') !== false
        ) {
            return 'json';
        }
        return 'text';
    }
349853
public function send(Request $request)
    {
        $response   = new GetIndexResponse();
        $rpbGetReq  = $this->createRpbMessage($request);
        $rpbGetResp = $this->client->send($rpbGetReq, RiakMessageCodes::YOKOZUNA_INDEX_GET_REQ, RiakMessageCodes::YOKOZUNA_INDEX_GET_RESP);

        if ( ! $rpbGetResp instanceof RpbYokozunaIndexGetResp) {
            return $response;
        }

        if ( ! $rpbGetResp->hasIndex()) {
            return $response;
        }

        $rpbIndex = is_array($rpbGetResp->index)
            ? reset($rpbGetResp->index)
            : $rpbGetResp->index;

        $response->nVal   = $rpbIndex->n_val;
        $response->name   = $rpbIndex->name;
        $response->schema = $rpbIndex->schema;

        return $response;
    }
279786
protected function getMimeType(Request $request)
    {
        $acceptHeader = $this->negotiator->getBest(
            $request->headers->get('Accept'),
            $this->getMimeTypes()
        );

        if ($acceptHeader && $this->isAcceptableMimeType($acceptHeader->getType())) {
            return $acceptHeader->getType();
        }

        return $this->defaultMimeType;
    }
375280
protected function getType($rawResponse)
    {
        if ($type = Arr::get($rawResponse, 'type')) {
            return $type;
        }

        switch (Arr::get($rawResponse, 'payment_status')) {
            case 'partially_refunded':
            case 'refunded':
                return 'refund';
        }

        return Arr::get($rawResponse, 'object');
    }
426867
private function getRememberMeCookie(Request $req)
    {
        $encoded = $req->cookies($this->rememberMeCookieName());
        if (!$encoded) {
            return false;
        }

        return RememberMeCookie::decode($encoded);
    }
540191
public function handleRequest(Request $req)
    {
        // set host name from request if not already set
        $config = $this['config'];
        if (!$config->get('app.hostname')) {
            $config->set('app.hostname', $req->host());
        }

        $res = new Response();
        try {
            // determine route by dispatching to router
            $routeInfo = $this['router']->dispatch($req->method(), $req->path());
            $this['routeInfo'] = $routeInfo;

            // set any route arguments on the request
            if (isset($routeInfo[2])) {
                $req->setParams($routeInfo[2]);
            }

            // the dispatch middleware is the final step
            $dispatch = new DispatchMiddleware();
            $dispatch->setApp($this);
            $this->middleware($dispatch);

            // the request is handled by returning the response
            // generated by the middleware chain
            return $this->runMiddleware($req, $res);
        } catch (\Exception $e) {
            return $this['exception_handler']($req, $res, $e);
        } catch (\Error $e) {
            return $this['php_error_handler']($req, $res, $e);
        }
    }
1037203
protected function filterRequestMethod(Request $req)
    {
        $method = strtoupper($req->getMethod());

        if ($method != 'POST') {
            return $req;
        }

        $params = $req->getParsedBody();

        if (isset($params['_method'])) {
            $req = $req->withMethod($params['_method']);
        }

        return $req;
    }
190753
public function changeType(Request $request)
    {
        $typeLst = $request->request->get('types', []);
        $records = RecordsRequest::fromRequest($this->app, $request, false, [\ACL::CANMODIFRECORD]);
        $mimeLst = $request->request->get('mimes', []);
        $forceType = $request->request->get('force_types', '');
        $updated = [];

        foreach ($records as $record) {
            try {
                $recordType = !empty($forceType) ? $forceType : (isset($typeLst[$record->getId()]) ? $typeLst[$record->getId()] : null);
                $mimeType = isset($mimeLst[$record->getId()]) ? $mimeLst[$record->getId()] : null;

                if ($recordType) {
                    $record->setType($recordType);
                    $updated[$record->getId()]['record_type'] = $recordType;
                }

                if ($mimeType) {
                    $record->setMimeType($mimeType);
                    $updated[$record->getId()]['mime_type'] = $mimeType;
                }
            } catch (\Exception $e) {

            }
        }

        return $this->app->json(['success' => true, 'updated' => $updated], 201);
    }
1261384
private function detectFromHeader(ServerRequestInterface $request)
    {
        $headers = call_user_func_array('array_merge', array_column($this->formats, 'mime-type'));
        $accept = $request->getHeaderLine('Accept');
        $mime = $this->negotiateHeader($accept, new Negotiator(), $headers);

        if ($mime !== null) {
            foreach ($this->formats as $format => $data) {
                if (in_array($mime, $data['mime-type'], true)) {
                    return $format;
                }
            }
        }
    }
1091779
public function parseVerb($request)
    {
        if (isset($request->server['http_x_http_method_override'])) {
            return strtoupper($request->server['http_x_http_method_override']);
        }
        if (isset($request->server['request_method'])) {
            return strtoupper($request->server['request_method']);
        }

        return 'GET';
    }
745647
public function getRawRequestResponse($format)
    {
        $result = '';
        if ($this->getRawRequest() !== null || $this->getRawResponse() !== null) {
            $messages = array();
            if ($this->getRawRequest() !== null) {
                $messages[] = $this->t('message_sent') . ":\n" . $this->getRawRequest();
            }
            if ($this->getRawResponse() !== null) {
                $messages[] = $this->t('message_received') . ":\n" . $this->getRawResponse();
            }
            $result .= $this->formatMessages($messages, $format);
        }
        return $result;
    }
1183202
protected function _requestContext($request)
    {
        $message = "\nRequest URL: " . $request->getRequestTarget();

        $referer = $request->getEnv('HTTP_REFERER');
        if ($referer) {
            $message .= "\nReferer URL: " . $referer;
        }
        $clientIp = $request->clientIp();
        if ($clientIp && $clientIp !== '::1') {
            $message .= "\nClient IP: " . $clientIp;
        }

        return $message;
    }
1012060
protected function getRequestOrigin(HTTPRequest $request)
    {
        // Prefer Origin header
        $origin = $request->getHeader('Origin');
        if ($origin) {
            return $origin;
        }

        // Check referer
        $referer = $request->getHeader('Referer');
        if ($referer) {
            // Extract protocol, hostname, and port
            $refererParts = parse_url($referer);
            if (!$refererParts) {
                return null;
            }
            // Rebuild
            $origin = $refererParts['scheme'] . '://' . $refererParts['host'];
            if (isset($refererParts['port'])) {
                $origin .= ':' . $refererParts['port'];
            }
            return $origin;
        }

        return null;
    }
1046289
public function getFormattedResponse()
    {
        list($header, $data) = preg_split("/\r\n\r\n|\n\n|\r\r/", $this->response, 2);

        $headers = preg_split("/\r\n|\n|\r/", $header);
        $status = explode(' ', trim(reset($headers)), 3);

        $result = array(
            'status' => '',
            'http' => $status[0],
            'code' => $status[1]
        );

        if (isset($status[2])) {
            $result['status'] = $status[2];
        }

        return array('data' => $data, 'status' => $result);
    }