当前位置: 首页>>代码示例>>PHP>>正文


PHP HttpResponse::getHeader方法代码示例

本文整理汇总了PHP中HttpResponse::getHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpResponse::getHeader方法的具体用法?PHP HttpResponse::getHeader怎么用?PHP HttpResponse::getHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpResponse的用法示例。


在下文中一共展示了HttpResponse::getHeader方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testAddHeaderToResponseObject

 /**
  * Test add header functionality on response object.
  */
 public function testAddHeaderToResponseObject()
 {
     $contentLength = rand(0, 100000);
     $this->response->addHeader(HttpProtocol::HEADER_X_POWERED_BY, 'PhpUnit');
     $this->response->addHeader(HttpProtocol::HEADER_CONTENT_TYPE, $contentLength);
     $this->assertSame('PhpUnit', $this->response->getHeader(HttpProtocol::HEADER_X_POWERED_BY));
     $this->assertSame($contentLength, $this->response->getHeader(HttpProtocol::HEADER_CONTENT_TYPE));
 }
开发者ID:techdivision,项目名称:http,代码行数:11,代码来源:ResponseTest.php

示例2: testGeneral

    function testGeneral()
    {
        $str = <<<EOF
HTTP/1.1 500 Server error
Host: localhost:8080
X-Powered-By: PHP/5.4.31
bc-param1: hello, world
Content-Type: text/plain

Exception: exception 'PDOException'
EOF;
        $res = new HttpResponse($str);
        $this->assertEquals(500, $res->code);
        $this->assertEquals("Server error", $res->message);
        $this->assertEquals("localhost:8080", $res->headers["HOST"]);
        $this->assertEquals("Exception: exception 'PDOException'", $res->body);
        $this->assertEquals("hello, world", $res->getHeader("bc-param1"));
        $this->assertEquals("hello, world", $res->getBCParam("param1"));
        $this->assertNull($res->getHeader("bc-param2"));
        $this->assertNull($res->getBCParam("param2"));
        $this->assertEquals($str, $res->toString());
    }
开发者ID:skyshore2001,项目名称:JDCloud,代码行数:22,代码来源:HttpResponseTest.php

示例3: _parseText

 public function _parseText($uri, HttpResponse $response)
 {
     $body = $response->getBody();
     if (preg_match('/charset=([a-zA-Z0-9-_]+)/i', $response->getHeader('content-type'), $matches) || preg_match('/charset=([a-zA-Z0-9-_]+)/i', $response->getBody(), $matches)) {
         $charset = trim($matches[1]);
     } else {
         $charset = 'UTF-8';
     }
     // Reduce whitespace
     $body = preg_replace('/[\\n\\r\\t\\v ]+/', ' ', $body);
     $arr_result = array();
     $arr_result['title'] = substr($body, 0, 63);
     $arr_result['description'] = substr($body, 0, 255);
     return $arr_result;
 }
开发者ID:vazahat,项目名称:dudex,代码行数:15,代码来源:abstract.php

示例4: handleInput

 public function handleInput(&$data, &$errNo)
 {
     // What is this? we're getting input while we're sending a reply?
     if ($this->sendFile) {
         $this->writeFileReset();
         $this->httpRequest = null;
     } else {
         if ($this->sendQLen > 0) {
             $this->sendQReset();
             $this->httpRequest = null;
         }
     }
     if (!$this->httpRequest) {
         $this->httpRequest = new HttpRequest();
     }
     // Pass the incoming data to the HttpRequest class, so it can handle it.
     if (!$this->httpRequest->handleInput($data)) {
         // An error was encountered while receiving the requst.
         // Send reply (unless 444, a special 'direct reject' code) and return false to close this connection.
         if ($this->httpRequest->errNo != 444) {
             $r = new HttpResponse('1.1', $this->httpRequest->errNo);
             $r->addBody($this->createErrorPage($this->httpRequest->errNo, $this->httpRequest->errStr));
             if ($this->httpRequest->errNo == 405) {
                 $r->addHeader('Allow: GET, POST, HEAD');
                 $r->addHeader('Access-Control-Allow-Methods: GET, POST, HEAD');
             }
             $this->write($r->getHeaders());
             $this->write($r->getBody());
             $this->logRequest($r->getResponseCode(), $r->getHeader('Content-Length') ? $r->getHeader('Content-Length') : 0);
         } else {
             $this->logRequest(444, 0);
         }
         $errNo = $this->httpRequest->errNo;
         return false;
     }
     // If we have no headers, or we are busy with receiving.
     // Just return and wait for more data.
     if (!$this->httpRequest->hasHeaders || $this->httpRequest->isReceiving) {
         // We're still receiving the body of a request
         return true;
     }
     // Return true to just wait and try again later
     // At this point we have a fully qualified and parsed HttpRequest
     // The HttpRequest object contains all info about the headers / GET / POST / COOKIE / FILES
     // Just finalise it by adding some extra client info.
     $this->httpRequest->SERVER['REMOTE_ADDR'] = $this->ip;
     $this->httpRequest->SERVER['REMOTE_PORT'] = $this->port;
     $this->httpRequest->SERVER['SERVER_ADDR'] = $this->localIP;
     $this->httpRequest->SERVER['SERVER_PORT'] = $this->localPort;
     $exp = explode(':', $this->httpRequest->headers['Host']);
     $this->httpRequest->SERVER['SERVER_NAME'] = $exp[0];
     $this->httpRequest->SERVER['HTTP_HOST'] = $this->httpRequest->headers['Host'];
     $this->httpRequest->SERVER['HTTP_USER_AGENT'] = isset($this->httpRequest->headers['User-Agent']) ? $this->httpRequest->headers['User-Agent'] : '';
     $this->httpRequest->SERVER['HTTP_ACCEPT'] = isset($this->httpRequest->headers['Accept']) ? $this->httpRequest->headers['Accept'] : '';
     $this->httpRequest->SERVER['HTTP_ACCEPT_LANGUAGE'] = isset($this->httpRequest->headers['Accept-Language']) ? $this->httpRequest->headers['Accept-Language'] : '';
     $this->httpRequest->SERVER['HTTP_ACCEPT_ENCODING'] = isset($this->httpRequest->headers['Accept-Encoding']) ? $this->httpRequest->headers['Accept-Encoding'] : '';
     $this->httpRequest->SERVER['HTTP_ACCEPT_CHARSET'] = isset($this->httpRequest->headers['Accept-Charset']) ? $this->httpRequest->headers['Accept-Charset'] : '';
     $this->httpRequest->SERVER['HTTP_CONNECTION'] = isset($this->httpRequest->headers['Connection']) ? $this->httpRequest->headers['Connection'] : '';
     $this->httpRequest->SERVER['HTTP_KEEP_ALIVE'] = isset($this->httpRequest->headers['Keep-Alive']) ? $this->httpRequest->headers['Keep-Alive'] : '';
     if (isset($this->httpRequest->headers['Referer'])) {
         $this->httpRequest->SERVER['HTTP_REFERER'] = $this->httpRequest->headers['Referer'];
     }
     if (isset($this->httpRequest->headers['Range'])) {
         $this->httpRequest->SERVER['HTTP_RANGE'] = $this->httpRequest->headers['Range'];
     }
     if (isset($this->httpRequest->headers['Cookie'])) {
         $this->httpRequest->SERVER['HTTP_COOKIE'] = $this->httpRequest->headers['Cookie'];
     }
     if (isset($this->httpRequest->headers['Authorization'])) {
         $this->httpRequest->SERVER['HTTP_AUTHORIZATION'] = $this->httpRequest->headers['Authorization'];
     }
     $this->httpRequest->SERVER['REQUEST_TIME'] = time();
     // Check if we have to match siteDomain
     if ($this->http->getSiteDomain() != '' && $this->http->getSiteDomain() != $this->httpRequest->SERVER['SERVER_NAME']) {
         $r = new HttpResponse($this->httpRequest->SERVER['httpVersion'], 404);
         $r->addBody($this->createErrorPage(404));
         $this->write($r->getHeaders());
         $this->write($r->getBody());
         $errNo = 404;
         $this->logRequest($r->getResponseCode(), $r->getHeader('Content-Length') ? $r->getHeader('Content-Length') : 0);
         return false;
     }
     // HTTP Authorisation?
     if ($this->http->getHttpAuthPath() != '') {
         $scriptPath = pathinfo($this->httpRequest->SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME);
         // Check if path must be auth'd and if HTTP_AUTHORIZATION header exists and if so, validate it
         if (isDirInDir($this->http->getHttpAuthPath(), $this->http->getDocRoot() . $scriptPath) && (!isset($this->httpRequest->SERVER['HTTP_AUTHORIZATION']) || !$this->validateAuthorization())) {
             // Not validated - send 401 Unauthorized
             do {
                 $nonce = createRandomString(17, RAND_HEX);
                 if (!$this->http->getNonceInfo($nonce)) {
                     break;
                 }
             } while (true);
             $opaque = $this->http->addNewNonce($nonce);
             $r = new HttpResponse($this->httpRequest->SERVER['httpVersion'], 401);
             if ($this->http->getHttpAuthType() == 'Digest') {
                 $r->addHeader('WWW-Authenticate: Digest realm="' . HTTP_AUTH_REALM . '", qop="auth", nonce="' . $nonce . '", opaque="' . $opaque . '"');
             } else {
                 $r->addHeader('WWW-Authenticate: Basic realm="' . HTTP_AUTH_REALM . '"');
//.........这里部分代码省略.........
开发者ID:jkaplavka,项目名称:PRISM,代码行数:101,代码来源:prism_http.php

示例5: finish

 /** 	
  * @param string $type NORMAL, BROKEN, TIMEOUT
  */
 public function finish($type = 'NORMAL')
 {
     $this->finished = true;
     if ($type === 'BROKEN') {
         $this->res->error = HttpConn::getLastError();
     } else {
         if ($type !== 'NORMAL') {
             $this->res->error = ucfirst(strtolower($type));
         }
     }
     // gzip decode
     $encoding = $this->res->getHeader('content-encoding');
     if ($encoding !== null && strstr($encoding, 'gzip')) {
         $this->res->body = HttpClient::gzdecode($this->res->body);
     }
     // parser
     $this->res->timeCost = microtime(true) - $this->timeBegin;
     $this->cli->runParser($this->res, $this->req, $this->key);
     // conn
     if ($this->conn) {
         // close conn
         $close = $this->res->getHeader('connection');
         $this->conn->close($type !== 'NORMAL' || !strcasecmp($close, 'close'));
         $this->conn = null;
         // redirect
         if (($this->res->status === 301 || $this->res->status === 302) && $this->res->numRedirected < $this->req->getMaxRedirect() && ($location = $this->res->getHeader('location')) !== null) {
             HttpClient::debug('redirect to \'', $location, '\'');
             $req = $this->req;
             if (!preg_match('/^https?:\\/\\//i', $location)) {
                 $pa = $req->getUrlParams();
                 $url = $pa['scheme'] . '://' . $pa['host'];
                 if (isset($pa['port'])) {
                     $url .= ':' . $pa['port'];
                 }
                 if (substr($location, 0, 1) == '/') {
                     $url .= $location;
                 } else {
                     $url .= substr($pa['path'], 0, strrpos($pa['path'], '/') + 1) . $location;
                 }
                 $location = $url;
                 /// FIXME: strip relative '../../'
             }
             // change new url
             $prevUrl = $req->getUrl();
             $req->setUrl($location);
             if (!$req->getHeader('referer')) {
                 $req->setHeader('referer', $prevUrl);
             }
             if ($req->getMethod() !== 'HEAD') {
                 $req->setMethod('GET');
             }
             $req->clearCookie();
             $req->setHeader('host', null);
             $req->setHeader('x-server-ip', null);
             // reset response
             $this->res->numRedirected++;
             $this->finished = $this->headerOK = false;
             return $this->res->reset();
         }
     }
     HttpClient::debug('finished', $this->res->hasError() ? ' (' . $this->res->error . ')' : '');
     $this->req = $this->cli = null;
 }
开发者ID:sophia2152,项目名称:pspider,代码行数:66,代码来源:HttpClient.class.php

示例6: splitWithContentIdKey

 /**
  * Split batch request and use ContentId as array key
  *
  * @param mixed $pattern
  * @param mixed $string
  *
  * @return array $array - Array of batch-parts
  */
 public function splitWithContentIdKey($pattern, $string)
 {
     $array = array();
     $exploded = explode($pattern, $string);
     foreach ($exploded as $key => $value) {
         $response = new HttpResponse($value);
         $contentId = $response->getHeader('Content-Id');
         if (!is_null($contentId)) {
             $array[$contentId] = $value;
         } else {
             $array[$key] = $value;
         }
     }
     return $array;
 }
开发者ID:vinigomescunha,项目名称:ArangoDB-Ajax-PHP-Example,代码行数:23,代码来源:Batch.php


注:本文中的HttpResponse::getHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。