Example #1
0
 /**
  * Prepares the contents of a POST file.
  *
  * @param mixed $content Content of the POST file
  */
 private function prepareContent($content)
 {
     $this->content = $content;
     if (!$this->content instanceof StreamInterface) {
         $this->content = \GuzzleHttp\Stream\create($this->content);
     } elseif ($this->content instanceof MultipartBody) {
         if (!$this->hasHeader('Content-Disposition')) {
             $disposition = 'form-data; name="' . $this->name . '"';
             $this->headers['Content-Disposition'] = $disposition;
         }
         if (!$this->hasHeader('Content-Type')) {
             $this->headers['Content-Type'] = sprintf("multipart/form-data; boundary=%s", $this->content->getBoundary());
         }
     }
 }
Example #2
0
 public function cacheCheck(BeforeEvent $event, $name)
 {
     $request = $event->getRequest();
     if ($request->getMethod() == 'GET') {
         $url = substr($request->getUrl(), 0, strpos($request->getUrl(), '?'));
         if (!preg_match('/token|oauth/', $url)) {
             $this->_cache_name = md5($request->getUrl() . (string) $request->getBody());
             if ($cache = $this->store->get($this->_cache_name, NULL)) {
                 \Log::info('getting response from cache');
                 $body = \GuzzleHttp\Stream\create(json_encode($cache));
                 $response = new \GuzzleHttp\Message\Response(200, array(), $body);
                 $event->intercept($response);
                 $event->stopPropagation();
             }
         }
     }
 }
 public function cacheCheck(BeforeEvent $event, $name)
 {
     if (!$this->cache) {
         return;
     }
     $request = $event->getRequest();
     if ($request->getMethod() == 'GET') {
         $this->_cache_name = md5($request->getUrl() . (string) $request->getBody());
         if ($cache = $this->store->get($this->_cache_name, NULL)) {
             \Log::info('getting response from cache');
             $body = \GuzzleHttp\Stream\create($cache);
             $response = new \GuzzleHttp\Message\Response(200, array(), $body);
             $event->intercept($response);
             $event->stopPropagation();
         }
     }
 }