protected function configureCurlOptions($action, array $converted, $streamHandle = null, $contentMd5 = null) { $curlOptions = parent::configureCurlOptions($action, $converted, $streamHandle, $contentMd5); if (RequestType::getRequestType($action) == RequestType::POST_DOWNLOAD) { $this->responseBodyContents = $streamHandle; $curlOptions[CURLOPT_WRITEFUNCTION] = array($this, 'responseCallback'); } return $curlOptions; }
/** * Configures specific curl options based on the request type. * * @param $action * @param $parameters * @param $streamHandle * @return array */ private function configureCurlOptions($action, array $converted, $streamHandle = null, $contentMd5 = null) { $curlOptions = $this->getDefaultCurlOptions(); if (!is_null($this->config['ProxyHost'])) { $proxy = $this->config['ProxyHost']; $proxy .= ':' . ($this->config['ProxyPort'] == -1 ? '80' : $this->config['ProxyPort']); $curlOptions[CURLOPT_PROXY] = $proxy; } $serviceUrl = $this->config['ServiceURL']; // append the '/' character to the end of the service URL if it doesn't exist. if (!(substr($serviceUrl, strlen($serviceUrl) - 1) === '/')) { $serviceUrl .= '/'; } $requestType = RequestType::getRequestType($action); if ($requestType == RequestType::POST_UPLOAD) { if (is_null($streamHandle) || !is_resource($streamHandle)) { require_once dirname(__FILE__) . '/Exception.php'; throw new MarketplaceWebService_Exception(array('Message' => 'Missing stream resource.')); } $serviceUrl .= '?' . $this->getParametersAsString($converted[CONVERTED_PARAMETERS_KEY]); $curlOptions[CURLOPT_URL] = $serviceUrl; $header[] = 'Expect: '; $header[] = 'Accept: '; $header[] = 'Transfer-Encoding: chunked'; $header[] = 'Content-MD5: ' . $contentMd5; $curlOptions[CURLOPT_HTTPHEADER] = array_merge($header, $converted[CONVERTED_HEADERS_KEY]); rewind($streamHandle); $curlOptions[CURLOPT_INFILE] = $streamHandle; $curlOptions[CURLOPT_UPLOAD] = true; $curlOptions[CURLOPT_CUSTOMREQUEST] = self::REQUEST_TYPE; } else { if (!($requestType === RequestType::UNKNOWN)) { $curlOptions[CURLOPT_URL] = $this->config['ServiceURL']; $curlOptions[CURLOPT_POSTFIELDS] = $this->getParametersAsString($converted[CONVERTED_PARAMETERS_KEY]); if ($requestType == RequestType::POST_DOWNLOAD) { $this->responseBodyContents = $streamHandle; $curlOptions[CURLOPT_WRITEFUNCTION] = array($this, 'responseCallback'); } } else { throw new InvalidArgumentException("{$action} is not a valid request type."); } } return $curlOptions; }