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


PHP Google_HttpRequest::setRequestHeaders方法代码示例

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


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

示例1: testIsResponseCacheable

 public function testIsResponseCacheable()
 {
     $resp = new Google_HttpRequest('http://localhost', 'POST');
     $result = Google_CacheParser::isResponseCacheable($resp);
     $this->assertFalse($result);
     // The response has expired, and we don't have an etag for
     // revalidation.
     $resp = new Google_HttpRequest('http://localhost', 'GET');
     $resp->setResponseHttpCode('200');
     $resp->setResponseHeaders(array('Cache-Control' => 'max-age=3600, must-revalidate', 'Expires' => 'Fri, 30 Oct 1998 14:19:41 GMT', 'Date' => 'Mon, 29 Jun 1998 02:28:12 GMT', 'Last-Modified' => 'Mon, 29 Jun 1998 02:28:12 GMT'));
     $result = Google_CacheParser::isResponseCacheable($resp);
     $this->assertFalse($result);
     // Verify cacheable responses.
     $resp = new Google_HttpRequest('http://localhost', 'GET');
     $resp->setResponseHttpCode('200');
     $resp->setResponseHeaders(array('Cache-Control' => 'max-age=3600, must-revalidate', 'Expires' => 'Fri, 30 Oct 2013 14:19:41 GMT', 'Date' => 'Mon, 29 Jun 2011 02:28:12 GMT', 'Last-Modified' => 'Mon, 29 Jun 2011 02:28:12 GMT', 'ETag' => '3e86-410-3596fbbc'));
     $result = Google_CacheParser::isResponseCacheable($resp);
     $this->assertTrue($result);
     // Verify that responses to HEAD requests are cacheable.
     $resp = new Google_HttpRequest('http://localhost', 'HEAD');
     $resp->setResponseHttpCode('200');
     $resp->setResponseBody(null);
     $resp->setResponseHeaders(array('Cache-Control' => 'max-age=3600, must-revalidate', 'Expires' => 'Fri, 30 Oct 2013 14:19:41 GMT', 'Date' => 'Mon, 29 Jun 2011 02:28:12 GMT', 'Last-Modified' => 'Mon, 29 Jun 2011 02:28:12 GMT', 'ETag' => '3e86-410-3596fbbc'));
     $result = Google_CacheParser::isResponseCacheable($resp);
     $this->assertTrue($result);
     // Verify that Vary: * cannot get cached.
     $resp = new Google_HttpRequest('http://localhost', 'GET');
     $resp->setResponseHttpCode('200');
     $resp->setResponseHeaders(array('Cache-Control' => 'max-age=3600, must-revalidate', 'Expires' => 'Fri, 30 Oct 2013 14:19:41 GMT', 'Date' => 'Mon, 29 Jun 2011 02:28:12 GMT', 'Last-Modified' => 'Mon, 29 Jun 2011 02:28:12 GMT', 'Vary' => 'foo', 'ETag' => '3e86-410-3596fbbc'));
     $result = Google_CacheParser::isResponseCacheable($resp);
     $this->assertFalse($result);
     // Verify 201s cannot get cached.
     $resp = new Google_HttpRequest('http://localhost', 'GET');
     $resp->setResponseHttpCode('201');
     $resp->setResponseBody(null);
     $resp->setResponseHeaders(array('Cache-Control' => 'max-age=3600, must-revalidate', 'Expires' => 'Fri, 30 Oct 2013 14:19:41 GMT', 'Last-Modified' => 'Mon, 29 Jun 2011 02:28:12 GMT', 'ETag' => '3e86-410-3596fbbc'));
     $result = Google_CacheParser::isResponseCacheable($resp);
     $this->assertFalse($result);
     // Verify pragma: no-cache.
     $resp = new Google_HttpRequest('http://localhost', 'GET');
     $resp->setResponseHttpCode('200');
     $resp->setResponseHeaders(array('Expires' => 'Wed, 11 Jan 2012 04:03:37 GMT', 'Date' => 'Wed, 11 Jan 2012 04:03:37 GMT', 'Pragma' => 'no-cache', 'Cache-Control' => 'private, max-age=0, must-revalidate, no-transform', 'ETag' => '3e86-410-3596fbbc'));
     $result = Google_CacheParser::isResponseCacheable($resp);
     $this->assertFalse($result);
     // Verify Cache-Control: no-store.
     $resp = new Google_HttpRequest('GET');
     $resp->setResponseHttpCode('200');
     $resp->setResponseHeaders(array('Expires' => 'Wed, 11 Jan 2012 04:03:37 GMT', 'Date' => 'Wed, 11 Jan 2012 04:03:37 GMT', 'Cache-Control' => 'no-store', 'ETag' => '3e86-410-3596fbbc'));
     $result = Google_CacheParser::isResponseCacheable($resp);
     $this->assertFalse($result);
     // Verify that authorized responses are not cacheable.
     $resp = new Google_HttpRequest('http://localhost', 'GET');
     $resp->setRequestHeaders(array('Authorization' => 'Bearer Token'));
     $resp->setResponseHttpCode('200');
     $resp->setResponseHeaders(array('Cache-Control' => 'max-age=3600, must-revalidate', 'Expires' => 'Fri, 30 Oct 2013 14:19:41 GMT', 'Last-Modified' => 'Mon, 29 Jun 2011 02:28:12 GMT', 'ETag' => '3e86-410-3596fbbc'));
     $result = Google_CacheParser::isResponseCacheable($resp);
     $this->assertFalse($result);
 }
开发者ID:ricain59,项目名称:fortaff,代码行数:58,代码来源:ApiCacheParserTest.php

示例2: execute

 public function execute()
 {
     $body = '';
     /** @var Google_HttpRequest $req */
     foreach ($this->requests as $key => $req) {
         $body .= "--{$this->boundary}\n";
         $body .= $req->toBatchString($key) . "\n";
     }
     $body = rtrim($body);
     $body .= "\n--{$this->boundary}--";
     $url = $GLOBALS['googleApiConfig']['basePath'] . '/batch';
     $httpRequest = new Google_HttpRequest($url, 'POST');
     $httpRequest->setRequestHeaders(array('Content-Type' => 'multipart/mixed; boundary=' . $this->boundary));
     $httpRequest->setPostBody($body);
     $response = Google_Client::$io->makeRequest($httpRequest);
     $response = $this->parseResponse($response);
     return $response;
 }
开发者ID:JamesLinus,项目名称:platform,代码行数:18,代码来源:Google_BatchRequest.php

示例3: processEntityRequest

 /**
  * @visible for testing
  * Process an http request that contains an enclosed entity.
  * @param Google_HttpRequest $request
  * @return Google_HttpRequest Processed request with the enclosed entity.
  */
 public function processEntityRequest(Google_HttpRequest $request)
 {
     $postBody = $request->getPostBody();
     $contentType = $request->getRequestHeader("content-type");
     // Set the default content-type as application/x-www-form-urlencoded.
     if (false == $contentType) {
         $contentType = self::FORM_URLENCODED;
         $request->setRequestHeaders(array('content-type' => $contentType));
     }
     // Force the payload to match the content-type asserted in the header.
     if ($contentType == self::FORM_URLENCODED && is_array($postBody)) {
         $postBody = http_build_query($postBody, '', '&');
         $request->setPostBody($postBody);
     }
     // Make sure the content-length header is set.
     if (!$postBody || is_string($postBody)) {
         $postsLength = strlen($postBody);
         $request->setRequestHeaders(array('content-length' => $postsLength));
     }
     return $request;
 }
开发者ID:raffaelemorgese,项目名称:levasoo,代码行数:27,代码来源:Google_IO.php

示例4: sign

 /**
  * Include an accessToken in a given apiHttpRequest.
  * @param Google_HttpRequest $request
  * @return Google_HttpRequest
  * @throws Google_AuthException
  */
 public function sign(Google_HttpRequest $request)
 {
     // add the developer key to the request before signing it
     if ($this->developerKey) {
         $requestUrl = $request->getUrl();
         $requestUrl .= strpos($request->getUrl(), '?') === false ? '?' : '&';
         $requestUrl .= 'key=' . urlencode($this->developerKey);
         $request->setUrl($requestUrl);
     }
     // Cannot sign the request without an OAuth access token.
     if (null == $this->token && null == $this->assertionCredentials) {
         return $request;
     }
     // Check if the token is set to expire in the next 30 seconds
     // (or has already expired).
     if ($this->isAccessTokenExpired()) {
         if ($this->assertionCredentials) {
             $this->refreshTokenWithAssertion();
         } else {
             if (!array_key_exists('refresh_token', $this->token)) {
                 throw new Google_AuthException("The OAuth 2.0 access token has expired, " . "and a refresh token is not available. Refresh tokens are not " . "returned for responses that were auto-approved.");
             }
             $this->refreshToken($this->token['refresh_token']);
         }
     }
     // Add the OAuth2 header to the request
     $request->setRequestHeaders(array('Authorization' => 'Bearer ' . $this->token['access_token']));
     return $request;
 }
开发者ID:rockst,项目名称:Google,代码行数:35,代码来源:Google_OAuth2.php

示例5: __call

 /**
  * @param $name
  * @param $arguments
  * @return Google_HttpRequest|array
  * @throws Google_Exception
  */
 public function __call($name, $arguments)
 {
     if (!isset($this->methods[$name])) {
         throw new Google_Exception("Unknown function: {$this->serviceName}->{$this->resourceName}->{$name}()");
     }
     $method = $this->methods[$name];
     $parameters = $arguments[0];
     // postBody is a special case since it's not defined in the discovery document as parameter, but we abuse the param entry for storing it
     $postBody = null;
     if (isset($parameters['postBody'])) {
         if (is_object($parameters['postBody'])) {
             $this->stripNull($parameters['postBody']);
         }
         // Some APIs require the postBody to be set under the data key.
         if (is_array($parameters['postBody']) && 'latitude' == $this->serviceName) {
             if (!isset($parameters['postBody']['data'])) {
                 $rawBody = $parameters['postBody'];
                 unset($parameters['postBody']);
                 $parameters['postBody']['data'] = $rawBody;
             }
         }
         $postBody = is_array($parameters['postBody']) || is_object($parameters['postBody']) ? json_encode($parameters['postBody']) : $parameters['postBody'];
         unset($parameters['postBody']);
         if (isset($parameters['optParams'])) {
             $optParams = $parameters['optParams'];
             unset($parameters['optParams']);
             $parameters = array_merge($parameters, $optParams);
         }
     }
     if (!isset($method['parameters'])) {
         $method['parameters'] = array();
     }
     $method['parameters'] = array_merge($method['parameters'], $this->stackParameters);
     foreach ($parameters as $key => $val) {
         if ($key != 'postBody' && !isset($method['parameters'][$key])) {
             throw new Google_Exception("({$name}) unknown parameter: '{$key}'");
         }
     }
     if (isset($method['parameters'])) {
         foreach ($method['parameters'] as $paramName => $paramSpec) {
             if (isset($paramSpec['required']) && $paramSpec['required'] && !isset($parameters[$paramName])) {
                 throw new Google_Exception("({$name}) missing required param: '{$paramName}'");
             }
             if (isset($parameters[$paramName])) {
                 $value = $parameters[$paramName];
                 $parameters[$paramName] = $paramSpec;
                 $parameters[$paramName]['value'] = $value;
                 unset($parameters[$paramName]['required']);
             } else {
                 unset($parameters[$paramName]);
             }
         }
     }
     // Discovery v1.0 puts the canonical method id under the 'id' field.
     if (!isset($method['id'])) {
         $method['id'] = $method['rpcMethod'];
     }
     // Discovery v1.0 puts the canonical path under the 'path' field.
     if (!isset($method['path'])) {
         $method['path'] = $method['restPath'];
     }
     $servicePath = $this->service->servicePath;
     // Process Media Request
     $contentType = false;
     if (isset($method['mediaUpload'])) {
         $media = Google_MediaFileUpload::process($postBody, $parameters);
         if ($media) {
             $contentType = isset($media['content-type']) ? $media['content-type'] : null;
             $postBody = isset($media['postBody']) ? $media['postBody'] : null;
             $servicePath = $method['mediaUpload']['protocols']['simple']['path'];
             $method['path'] = '';
         }
     }
     $url = Google_REST::createRequestUri($servicePath, $method['path'], $parameters);
     $httpRequest = new Google_HttpRequest($url, $method['httpMethod'], null, $postBody);
     if ($postBody) {
         $contentTypeHeader = array();
         if (isset($contentType) && $contentType) {
             $contentTypeHeader['content-type'] = $contentType;
         } else {
             $contentTypeHeader['content-type'] = 'application/json; charset=UTF-8';
             $contentTypeHeader['content-length'] = Google_Utils::getStrLen($postBody);
         }
         $httpRequest->setRequestHeaders($contentTypeHeader);
     }
     $httpRequest = Google_Client::$auth->sign($httpRequest);
     if (Google_Client::$useBatch) {
         return $httpRequest;
     }
     // Terminate immediatly if this is a resumable request.
     if (isset($parameters['uploadType']['value']) && 'resumable' == $parameters['uploadType']['value']) {
         return $httpRequest;
     }
     return Google_REST::execute($httpRequest);
//.........这里部分代码省略.........
开发者ID:shimion,项目名称:ap,代码行数:101,代码来源:Google_ServiceResource.php

示例6: testAuthCache

 public function testAuthCache()
 {
     $io = new Google_CurlIO();
     $url = "http://www.googleapis.com/protected/resource";
     // Create a cacheable request/response, but it should not be cached.
     $cacheReq = new Google_HttpRequest($url, "GET");
     $cacheReq->setRequestHeaders(array("Accept" => "*/*", "Authorization" => "Bearer Foo"));
     $cacheReq->setResponseBody("{\"a\": \"foo\"}");
     $cacheReq->setResponseHttpCode(200);
     $cacheReq->setResponseHeaders(array("Cache-Control" => "private", "ETag" => "\"this-is-an-etag\"", "Expires" => "Sun, 22 Jan 2022 09:00:56 GMT", "Date: Sun, 1 Jan 2012 09:00:56 GMT", "Content-Type" => "application/json; charset=UTF-8"));
     $result = $io->setCachedRequest($cacheReq);
     $this->assertFalse($result);
 }
开发者ID:ankush1990,项目名称:google-api-php-client,代码行数:13,代码来源:IoTest.php

示例7: checkMustRevaliadateCachedRequest

 /**
  * Check if an already cached request must be revalidated, and if so update
  * the request with the correct ETag headers.
  * @param Google_HttpRequest $cached A previously cached response.
  * @param Google_HttpRequest $request The outbound request.
  * return bool If the cached object needs to be revalidated, false if it is
  * still current and can be re-used.
  */
 protected function checkMustRevaliadateCachedRequest($cached, $request)
 {
     if (Google_CacheParser::mustRevalidate($cached)) {
         $addHeaders = array();
         if ($cached->getResponseHeader('etag')) {
             // [13.3.4] If an entity tag has been provided by the origin server,
             // we must use that entity tag in any cache-conditional request.
             $addHeaders['If-None-Match'] = $cached->getResponseHeader('etag');
         } elseif ($cached->getResponseHeader('date')) {
             $addHeaders['If-Modified-Since'] = $cached->getResponseHeader('date');
         }
         $request->setRequestHeaders($addHeaders);
         return true;
     } else {
         return false;
     }
 }
开发者ID:ActiveWebsite,项目名称:BoojPressPlugins,代码行数:25,代码来源:Google_IO.php

示例8: getResumeUri

 private function getResumeUri(Google_HttpRequest $httpRequest)
 {
     $result = null;
     $body = $httpRequest->getPostBody();
     if ($body) {
         $httpRequest->setRequestHeaders(array('content-type' => 'application/json; charset=UTF-8', 'content-length' => Google_Utils::getStrLen($body), 'x-upload-content-type' => $this->mimeType, 'x-upload-content-length' => $this->size, 'expect' => ''));
     }
     $response = Google_Client::$io->makeRequest($httpRequest);
     $location = $response->getResponseHeader('location');
     $code = $response->getResponseHttpCode();
     if (200 == $code && true == $location) {
         return $location;
     }
     throw new Google_Exception("Failed to start the resumable upload");
 }
开发者ID:Adeelgill,项目名称:livehelperchat,代码行数:15,代码来源:Google_MediaFileUpload.php


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