本文整理汇总了PHP中Zend\Http\Request::headers方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::headers方法的具体用法?PHP Request::headers怎么用?PHP Request::headers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\Request
的用法示例。
在下文中一共展示了Request::headers方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAtomAcceptHeaderSelectsFeedStrategy
public function testAtomAcceptHeaderSelectsFeedStrategy()
{
$request = new HttpRequest();
$request->headers()->addHeaderLine('Accept', 'application/atom+xml');
$this->event->setRequest($request);
$result = $this->strategy->selectRenderer($this->event);
$this->assertSame($this->renderer, $result);
}
示例2: testRequestCanSetHeaders
public function testRequestCanSetHeaders()
{
$request = new Request();
$headers = new \Zend\Http\Headers();
$ret = $request->setHeaders($headers);
$this->assertInstanceOf('Zend\\Http\\Request', $ret);
$this->assertSame($headers, $request->headers());
}
示例3: _parseDigestAuth
//.........这里部分代码省略.........
// Section 3.2.2.5 seems to suggest that the value of the URI
// Authorization field should be made into an absolute URI if the
// Request URI is absolute, but it's vague, and that's a bunch of
// code I don't want to write right now.
$data['uri'] = $temp[1];
$temp = null;
$ret = preg_match('/response="([^"]+)"/', $header, $temp);
if (!$ret || empty($temp[1])) {
return false;
}
if (32 != strlen($temp[1]) || !ctype_xdigit($temp[1])) {
return false;
} else {
$data['response'] = $temp[1];
}
$temp = null;
// The spec says this should default to MD5 if omitted. OK, so how does
// that square with the algo we send out in the WWW-Authenticate header,
// if it can easily be overridden by the client?
$ret = preg_match('/algorithm="?(' . $this->_algo . ')"?/', $header, $temp);
if ($ret && !empty($temp[1])
&& in_array($temp[1], $this->_supportedAlgos)) {
$data['algorithm'] = $temp[1];
} else {
$data['algorithm'] = 'MD5'; // = $this->_algo; ?
}
$temp = null;
// Not optional in this implementation
$ret = preg_match('/cnonce="([^"]+)"/', $header, $temp);
if (!$ret || empty($temp[1])) {
return false;
}
if (!ctype_print($temp[1])) {
return false;
} else {
$data['cnonce'] = $temp[1];
}
$temp = null;
// If the server sent an opaque value, the client must send it back
if ($this->_useOpaque) {
$ret = preg_match('/opaque="([^"]+)"/', $header, $temp);
if (!$ret || empty($temp[1])) {
// Big surprise: IE isn't RFC 2617-compliant.
$headers = $this->_request->headers();
if (!$headers->has('User-Agent')) {
return false;
}
$userAgent = $headers->get('User-Agent')->getFieldValue();
if (false === strpos($userAgent, 'MSIE')) {
return false;
}
$temp[1] = '';
$this->_ieNoOpaque = true;
}
// This implementation only sends MD5 hex strings in the opaque value
if (!$this->_ieNoOpaque &&
(32 != strlen($temp[1]) || !ctype_xdigit($temp[1]))) {
return false;
} else {
$data['opaque'] = $temp[1];
}
$temp = null;
}
// Not optional in this implementation, but must be one of the supported
// qop types
$ret = preg_match('/qop="?(' . implode('|', $this->_supportedQops) . ')"?/', $header, $temp);
if (!$ret || empty($temp[1])) {
return false;
}
if (!in_array($temp[1], $this->_supportedQops)) {
return false;
} else {
$data['qop'] = $temp[1];
}
$temp = null;
// Not optional in this implementation. The spec says this value
// shouldn't be a quoted string, but apparently some implementations
// quote it anyway. See ZF-1544.
$ret = preg_match('/nc="?([0-9A-Fa-f]{8})"?/', $header, $temp);
if (!$ret || empty($temp[1])) {
return false;
}
if (8 != strlen($temp[1]) || !ctype_xdigit($temp[1])) {
return false;
} else {
$data['nc'] = $temp[1];
}
$temp = null;
return $data;
}
示例4: _doAuth
/**
* Acts like a client sending the given Authenticate header value.
*
* @param string $clientHeader Authenticate header value
* @param string $scheme Which authentication scheme to use
* @return array Containing the result, response headers, and the status
*/
protected function _doAuth($clientHeader, $scheme)
{
// Set up stub request and response objects
$request = new Request;
$response = new Response;
$response->setStatusCode(200);
// Set stub method return values
$request->setUri('http://localhost/');
$request->setMethod('GET');
$request->setServer(new Parameters(array('HTTP_USER_AGENT' => 'PHPUnit')));
$headers = $request->headers();
$headers->addHeaderLine('Authorization', $clientHeader);
// Select an Authentication scheme
switch ($scheme) {
case 'basic':
$use = $this->_basicConfig;
break;
case 'digest':
$use = $this->_digestConfig;
break;
case 'both':
default:
$use = $this->_bothConfig;
}
// Create the HTTP Auth adapter
$a = new HTTP($use);
$a->setBasicResolver($this->_basicResolver);
$a->setDigestResolver($this->_digestResolver);
// Send the authentication request
$a->setRequest($request);
$a->setResponse($response);
$result = $a->authenticate();
$return = array(
'result' => $result,
'status' => $response->getStatusCode(),
'headers' => $response->headers(),
);
return $return;
}
示例5: post
/**
* HTTP POST METHOD (static)
*
* @param string $url
* @param array $params
* @param array $headers
* @return Response|boolean
*/
public static function post($url, $params, $headers = array(), $body = null)
{
if (empty($url)) {
return false;
}
$request = new Request();
$request->setUri($url);
$request->setMethod(Request::METHOD_POST);
if (!empty($params) && is_array($params)) {
$request->post()->fromArray($params);
} else {
throw new Exception\InvalidArgumentException('The array of post parameters is empty');
}
if (!isset($headers['Content-Type'])) {
$headers['Content-Type'] = Client::ENC_URLENCODED;
}
if (!empty($headers) && is_array($headers)) {
$request->headers()->addHeaders($headers);
}
if (!empty($body)) {
$request->setBody($body);
}
return self::getStaticClient()->send($request);
}
示例6: getRequest
/**
* Get the request object
*
* @return Request
*/
public function getRequest()
{
if (!$this->request instanceof Request) {
$request = new HttpRequest();
$request->setQuery(new PhpEnvironment\GetContainer())
->setPost(new PhpEnvironment\PostContainer())
->setEnv(new Parameters($_ENV))
->setServer(new Parameters($_SERVER));
if ($_COOKIE) {
$request->headers()->addHeader(new Cookie($_COOKIE));
}
if ($_FILES) {
$request->setFile(new Parameters($_FILES));
}
if (isset($_SERVER['REQUEST_METHOD'])) {
$request->setMethod($_SERVER['REQUEST_METHOD']);
}
if (isset($_SERVER['REQUEST_URI'])) {
$request->setUri($_SERVER['REQUEST_URI']);
}
$this->setRequest($request);
}
return $this->request;
}