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


PHP Response::setHeader方法代码示例

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


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

示例1: Response

 function it_can_get_the_response_headers(ClientInterface $client)
 {
     $url = 'http://doc.build/api/documents/someid/payload';
     $response = new Response(200);
     $response->setHeader('Content-Disposition', 'attachment');
     $response->setHeader('filename', 'TestDocument1.docx');
     $response->setBody(Stream::factory(""));
     $client->get($url, Argument::any())->willReturn($response);
     $this->get('documents/someid/payload');
     $expected = ['Content-Disposition' => ['attachment'], 'filename' => ['TestDocument1.docx']];
     $this->getResponseHeaders()->shouldEqual($expected);
 }
开发者ID:vivait,项目名称:docbuild-php,代码行数:12,代码来源:GuzzleAdapterSpec.php

示例2: createResponse

 /**
  * Taken from Mink\BrowserKitDriver
  *
  * @param Response $response
  *
  * @return \Symfony\Component\BrowserKit\Response
  */
 protected function createResponse(Response $response)
 {
     $contentType = $response->getHeader('Content-Type');
     $matches = null;
     if (!$contentType or strpos($contentType, 'charset=') === false) {
         $body = $response->getBody(true);
         if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $body, $matches)) {
             $contentType .= ';charset=' . $matches[1];
         }
         $response->setHeader('Content-Type', $contentType);
     }
     $headers = $response->getHeaders();
     $status = $response->getStatusCode();
     $matchesMeta = null;
     $matchesHeader = null;
     $isMetaMatch = preg_match('/\\<meta[^\\>]+http-equiv="refresh" content="(\\d*)\\s*;?\\s*url=(.*?)"/i', $response->getBody(true), $matchesMeta);
     $isHeaderMatch = preg_match('~(\\d*);?url=(.*)~', (string) $response->getHeader('Refresh'), $matchesHeader);
     $matches = $isMetaMatch ? $matchesMeta : $matchesHeader;
     if (!empty($matches) && (empty($matches[1]) || $matches[1] < $this->refreshMaxInterval)) {
         $uri = $this->getAbsoluteUri($matches[2]);
         $partsUri = parse_url($uri);
         $partsCur = parse_url($this->getHistory()->current()->getUri());
         foreach ($partsCur as $key => $part) {
             if ($key === 'fragment') {
                 continue;
             }
             if (!isset($partsUri[$key]) || $partsUri[$key] !== $part) {
                 $status = 302;
                 $headers['Location'] = $uri;
                 break;
             }
         }
     }
     return new BrowserKitResponse($response->getBody(), $status, $headers);
 }
开发者ID:itillawarra,项目名称:cmfive,代码行数:42,代码来源:Guzzle.php

示例3: makeResponse

 /**
  * Create a Response object from a stub.
  *
  * @param $stub
  * @return \GuzzleHttp\Message\Response
  */
 private function makeResponse($stub)
 {
     $response = new Response(200);
     $response->setHeader('Content-Type', 'application/json');
     $responseBody = Stream::factory(fopen('./tests/Destiny/stubs/' . $stub . '.txt', 'r+'));
     $response->setBody($responseBody);
     return $response;
 }
开发者ID:EVPohovich,项目名称:EVPohovich.github.io,代码行数:14,代码来源:TestCase.php

示例4: createResponse

 /**
  * Taken from Mink\BrowserKitDriver
  *
  * @param Response $response
  *
  * @return \Symfony\Component\BrowserKit\Response
  */
 protected function createResponse(Response $response)
 {
     $contentType = $response->getHeader('Content-Type');
     if (!$contentType or strpos($contentType, 'charset=') === false) {
         $body = $response->getBody(true);
         if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $body, $matches)) {
             $contentType .= ';charset=' . $matches[1];
         }
         $response->setHeader('Content-Type', $contentType);
     }
     $headers = $response->getHeaders();
     $status = $response->getStatusCode();
     if (preg_match('/\\<meta[^\\>]+http-equiv="refresh" content=".*?url=(.*?)"/i', $response->getBody(true), $matches)) {
         $status = 302;
         $headers['Location'] = $matches[1];
     }
     if (preg_match('~url=(.*)~', (string) $response->getHeader('Refresh'), $matches)) {
         $status = 302;
         $headers['Location'] = $matches[1];
     }
     return new BrowserKitResponse($response->getBody(), $status, $headers);
 }
开发者ID:aleguisf,项目名称:fvdev1,代码行数:29,代码来源:Guzzle.php

示例5: testGetHeader

 public function testGetHeader()
 {
     $this->guzzleResponse->setHeader('bar', 'foo');
     $this->assertEquals('foo', $this->response->getHeader('bar'));
 }
开发者ID:evanjt,项目名称:core,代码行数:5,代码来源:responsetest.php


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