Ejemplo n.º 1
0
 /**
  * @param \Kdyby\Curl\Response $response
  * @param string $id
  */
 public function response(Curl\Response $response, $id)
 {
     $content = array();
     foreach ($response->getHeaders() as $name => $value) {
         $content[] = "{$name}: {$value}";
     }
     $content = '< ' . implode("\n< ", $content);
     $this->write($content . "\n\n", $id);
     $body = $response->getResponse();
     foreach ($this->formatters as $formatter) {
         if ($formatted = $formatter($body, $response)) {
             $body = $formatted;
         }
     }
     $this->write($body, $id);
 }
Ejemplo n.º 2
0
 /**
  * @param CurlWrapper $curl
  * @param array $headers
  */
 public function __construct(CurlWrapper $curl, array $headers)
 {
     parent::__construct($curl, $headers);
     $this->file = $curl->file;
 }
Ejemplo n.º 3
0
 /**
  * @param CurlWrapper $curl
  *
  * @return Response|NULL
  */
 protected function buildRedirectResponse(CurlWrapper $curl)
 {
     if ($curl->info['redirect_count'] === 0) {
         return NULL;
     }
     $previous = $last = NULL;
     /** @var Response $last */
     $parts = Strings::split($curl->responseHeaders, '~(HTTP/\\d\\.\\d\\s\\d+\\s.*)~m', PREG_SPLIT_NO_EMPTY);
     while ($rawHeaders = array_shift($parts)) {
         if ($http = Strings::match($rawHeaders, CurlWrapper::VERSION_AND_STATUS)) {
             if ($http['code'] < 200) {
                 continue;
             }
             $rawHeaders .= array_shift($parts);
         }
         if (!$parts) {
             $curl->responseHeaders = $rawHeaders;
             return $last;
         }
         if ($headers = CurlWrapper::parseHeaders($rawHeaders)) {
             $previous = new Response($curl, $headers);
             if ($last !== NULL) {
                 $previous->setPrevious($last);
             }
         }
         $last = $previous;
     }
     return $last;
 }
Ejemplo n.º 4
0
 /**
  * @param string $policyNo
  * @param Response $response
  * @return bool|string
  */
 public function savePdfFile($policyNo, Response $response)
 {
     if ($response->getHeaders()['Content-Type'] !== 'application/pdf') {
         return FALSE;
     }
     $body = $response->getResponse();
     $filename = $this->tempDir . '/' . $policyNo . '-' . Strings::substring(md5($body), 0, 5) . '.pdf';
     $this->toDelete[] = $filename;
     FileSystem::write($filename, $body);
     return $filename;
 }
Ejemplo n.º 5
0
 /**
  * Creates new request that can follow requested location
  * @param Response $response
  *
  * @return Request
  */
 public final function followRedirect(Response $response)
 {
     $request = clone $this;
     if (!$request->isMethod(Request::DOWNLOAD)) {
         $request->setMethod(Request::GET);
     }
     $request->post = $request->files = array();
     $request->cookies = $response->getCookies() + $request->cookies;
     $request->setUrl(static::fixUrl($request->getUrl(), $response->headers['Location']));
     return $request;
 }
Ejemplo n.º 6
0
 /**
  * Funkce parsující stav odpovědi od LM connectu
  * @param CurlResponse $response
  * @param string $message
  * @return string
  * @throws \Exception
  */
 private function parseResponse($response, $message = '')
 {
     $body = $response->getResponse();
     $body = simplexml_load_string($body);
     if (!$response->isOk() || $body['status'] == 'failure') {
         throw new \Exception(isset($body->message) ? (string) $body->message : $response->getCode());
     } else {
         if ($body['status'] == 'success') {
             return isset($body->message) ? (string) $body->message : $message;
         }
     }
     throw new \Exception(sprintf('Response not in expected format (%s)', htmlspecialchars($response->getResponse())));
 }