Пример #1
0
 /**
  * @param Actions\ActionsInterface $action
  * @param array                    $requestParams
  * @return Url
  */
 protected function buildRequestUrl(Actions\ActionsInterface $action, array $requestParams)
 {
     $url = new Url('https', $this->connection->getEndpoint());
     $url->setPath($action->getAction());
     $url->setQuery($requestParams);
     return $url;
 }
Пример #2
0
 private function validateUrl(Url $url)
 {
     // The host must match the following pattern
     $hostPattern = '/^sns\\.[a-zA-Z0-9\\-]{3,}\\.amazonaws\\.com(\\.cn)?$/';
     if ($url->getScheme() !== 'https' || substr($url, -4) !== '.pem' || !preg_match($hostPattern, $url->getHost())) {
         throw new CertificateFromUnrecognizedSourceException();
     }
 }
Пример #3
0
 /**
  * Parse the AWS service name from a URL
  *
  * @param Url $url HTTP URL
  *
  * @return string Returns a service name (or empty string)
  * @link http://docs.amazonwebservices.com/general/latest/gr/rande.html
  */
 public static function parseServiceName(Url $url)
 {
     // The service name is the first part of the host
     $parts = explode('.', $url->getHost(), 2);
     // Special handling for S3
     if (stripos($parts[0], 's3') === 0) {
         return 's3';
     }
     return $parts[0];
 }
Пример #4
0
 /**
  * Gets an array of issue uri's from an d.o project issue page(s). Will use
  * the pager to determine when all the issues have been scraped.
  *
  * @return array
  *   An array of d.o issue uris.
  */
 public function getIssueUris()
 {
     if (empty($this->issueUris)) {
         while ($page = $this->getPage()) {
             $issues = $page->filter('table.project-issue td.views-field-title a');
             foreach ($issues as $issue) {
                 $this->issueUris[] = $this->uri->getScheme() . '://' . $this->uri->getHost() . $issue->getAttribute('href');
             }
         }
     }
     return $this->issueUris;
 }
Пример #5
0
 /**
  * Запрос На авторизацию
  *
  * @param string $redirectUrl Урл для
  * @param string $state       дополнительный get параметр который подставляется к урл
  *
  * @return string
  */
 public function getLoginUrl($redirectUrl, $state = ' ')
 {
     $this->redirectUrl = $redirectUrl;
     $query = new QueryString();
     $query->add('response_type', 'code');
     $query->add('client_id', $this->clientId);
     $query->add('redirect_uri', $redirectUrl);
     $query->add('state', $state);
     //$url = new Url('https','o2.mail.ru',null,null,null,'login',$query);
     $url = new Url('https', 'oauth.yandex.ru', null, null, null, 'authorize', $query);
     return $url->__toString();
 }
Пример #6
0
 /**
  * Override __construct() to default scheme to s3.
  *
  * @param string $bucket
  *   The bucket to use for the URL.
  * @param string $key
  *   (optional) Key for the URL.
  */
 public function __construct($bucket, $key = null)
 {
     if ($key) {
         $key = '/' . $key;
     }
     parent::__construct('s3', $bucket, null, null, null, $key);
 }
Пример #7
0
 /**
  * Get description URL
  *
  * @return Url
  */
 public function getDescriptionUrl()
 {
     if (is_null($this->descriptionUrl)) {
         return Url::factory(SsdpInterface::DEFAULT_DESCRIPTION_URL);
     }
     return $this->descriptionUrl;
 }
Пример #8
0
 /**
  * @dataProvider cookieParserDataProvider
  */
 public function testParseCookie($cookie, $parsed, $url = null)
 {
     $c = $this->cookieParserClass;
     $parser = new $c();
     $request = null;
     if ($url) {
         $url = Url::factory($url);
         $host = $url->getHost();
         $path = $url->getPath();
     } else {
         $host = '';
         $path = '';
     }
     foreach ((array) $cookie as $c) {
         $p = $parser->parseCookie($c, $host, $path);
         // Remove expires values from the assertion if they are relatively equal by allowing a 5 minute difference
         if ($p['expires'] != $parsed['expires']) {
             if (abs($p['expires'] - $parsed['expires']) < 300) {
                 unset($p['expires']);
                 unset($parsed['expires']);
             }
         }
         if (is_array($parsed)) {
             foreach ($parsed as $key => $value) {
                 $this->assertEquals($parsed[$key], $p[$key], 'Comparing ' . $key . ' ' . var_export($value, true) . ' : ' . var_export($parsed, true) . ' | ' . var_export($p, true));
             }
             foreach ($p as $key => $value) {
                 $this->assertEquals($p[$key], $parsed[$key], 'Comparing ' . $key . ' ' . var_export($value, true) . ' : ' . var_export($parsed, true) . ' | ' . var_export($p, true));
             }
         } else {
             $this->assertEquals($parsed, $p);
         }
     }
 }
Пример #9
0
 /**
  * Create response from string
  *
  * @param string $string
  *
  * @return $this
  */
 public static function fromString($string)
 {
     /** @var Discover $message */
     $message = new static();
     foreach (explode(PHP_EOL, trim($string)) as $line) {
         $tuple = explode(':', trim($line), 2);
         if (2 == count($tuple)) {
             $value = trim(array_pop($tuple));
             switch (strtoupper(array_pop($tuple))) {
                 case 'CACHE-CONTROL':
                     $message->setLifetime(intval(substr($value, strpos($value, '=') + 1)));
                     break;
                 case 'DATE':
                     $message->setDate(new DateTime($value));
                     break;
                 case 'LOCATION':
                     $message->setDescriptionUrl(Url::factory($value));
                     break;
                 case 'SERVER':
                     $message->setServerString($value);
                     break;
                 case 'ST':
                     $message->setSearchTarget(SearchTarget::fromString($value));
                     break;
                 case 'USN':
                     $message->setUniqueServiceName(UniqueServiceName::fromString($value));
                     break;
             }
         }
     }
     return $message;
 }
Пример #10
0
 public function testCreatesPresignedUrlsWithStrtotime()
 {
     /** @var $client S3Client */
     $client = $this->getServiceBuilder()->get('s3');
     $url = Url::factory($client->createPresignedUrl($client->get('/foobar'), '10 minutes'));
     $this->assertTrue(time() < $url->getQuery()->get('Expires'));
 }
Пример #11
0
 /**
  * Returns the URL of the metadata (key or block)
  *
  * @return string
  * @param string $subresource not used; required for strict compatibility
  * @throws ServerUrlerror
  */
 public function getUrl($path = null, array $query = array())
 {
     if (!isset($this->url)) {
         throw new Exceptions\ServerUrlError('Metadata has no URL (new object)');
     }
     return Url::factory($this->url)->addPath($this->key);
 }
Пример #12
0
 public function testEstimatingTemplateCostMarshalsDataCorrectly()
 {
     self::log('Estimate a template\'s cost.');
     $result = $this->client->estimateTemplateCost(array('TemplateBody' => file_get_contents(__DIR__ . '/template.json'), 'Parameters' => array(array('ParameterKey' => 'KeyName', 'ParameterValue' => 'keypair-name'))));
     $url = Url::factory($result->get('Url'));
     $this->assertEquals('calculator.s3.amazonaws.com', $url->getHost());
 }
Пример #13
0
 /**
  * {@inheritdoc}
  * @throws \UnexpectedValueException If a controller is not \Ratchet\Http\HttpServerInterface
  */
 public function onOpen(ConnectionInterface $conn, RequestInterface $request = null)
 {
     if (null === $request) {
         throw new \UnexpectedValueException('$request can not be null');
     }
     $context = $this->_matcher->getContext();
     $context->setMethod($request->getMethod());
     $context->setHost($request->getHost());
     try {
         $route = $this->_matcher->match($request->getPath());
     } catch (MethodNotAllowedException $nae) {
         return $this->close($conn, 403);
     } catch (ResourceNotFoundException $nfe) {
         return $this->close($conn, 404);
     }
     if (is_string($route['_controller']) && class_exists($route['_controller'])) {
         $route['_controller'] = new $route['_controller']();
     }
     if (!$route['_controller'] instanceof HttpServerInterface) {
         throw new \UnexpectedValueException('All routes must implement Ratchet\\Http\\HttpServerInterface');
     }
     $parameters = array();
     foreach ($route as $key => $value) {
         if (is_string($key) && '_' !== substr($key, 0, 1)) {
             $parameters[$key] = $value;
         }
     }
     $url = Url::factory($request->getPath());
     $url->setQuery($parameters);
     $request->setUrl($url);
     $conn->controller = $route['_controller'];
     $conn->controller->onOpen($conn, $request);
 }
Пример #14
0
 protected function createRedirectRequest(RequestInterface $request, $statusCode, $location, RequestInterface $original)
 {
     $redirectRequest = null;
     $strict = $original->getParams()->get(self::STRICT_REDIRECTS);
     if ($request instanceof EntityEnclosingRequestInterface && ($statusCode == 303 || !$strict && $statusCode <= 302)) {
         $redirectRequest = RequestFactory::getInstance()->cloneRequestWithMethod($request, 'GET');
     } else {
         $redirectRequest = clone $request;
     }
     $redirectRequest->setIsRedirect(true);
     $redirectRequest->setResponseBody($request->getResponseBody());
     $location = Url::factory($location);
     if (!$location->isAbsolute()) {
         $originalUrl = $redirectRequest->getUrl(true);
         $originalUrl->getQuery()->clear();
         $location = $originalUrl->combine((string) $location, true);
     }
     $redirectRequest->setUrl($location);
     $redirectRequest->getEventDispatcher()->addListener('request.before_send', $func = function ($e) use(&$func, $request, $redirectRequest) {
         $redirectRequest->getEventDispatcher()->removeListener('request.before_send', $func);
         $e['request']->getParams()->set(RedirectPlugin::PARENT_REQUEST, $request);
     });
     if ($redirectRequest instanceof EntityEnclosingRequestInterface && $redirectRequest->getBody()) {
         $body = $redirectRequest->getBody();
         if ($body->ftell() && !$body->rewind()) {
             throw new CouldNotRewindStreamException('Unable to rewind the non-seekable entity body of the request after redirecting. cURL probably ' . 'sent part of body before the redirect occurred. Try adding acustom rewind function using on the ' . 'entity body of the request using setRewindFunction().');
         }
     }
     return $redirectRequest;
 }
Пример #15
0
 public function testCreatesPutRequests()
 {
     // Test using a string
     $request = RequestFactory::getInstance()->create('PUT', 'http://www.google.com/path?q=1&v=2', null, 'Data');
     $this->assertInstanceOf('Guzzle\\Http\\Message\\EntityEnclosingRequest', $request);
     $this->assertEquals('PUT', $request->getMethod());
     $this->assertEquals('http', $request->getScheme());
     $this->assertEquals('http://www.google.com/path?q=1&v=2', $request->getUrl());
     $this->assertEquals('www.google.com', $request->getHost());
     $this->assertEquals('/path', $request->getPath());
     $this->assertEquals('/path?q=1&v=2', $request->getResource());
     $this->assertInstanceOf('Guzzle\\Http\\EntityBody', $request->getBody());
     $this->assertEquals('Data', (string) $request->getBody());
     unset($request);
     // Test using an EntityBody
     $request = RequestFactory::getInstance()->create('PUT', 'http://www.google.com/path?q=1&v=2', null, EntityBody::factory('Data'));
     $this->assertInstanceOf('Guzzle\\Http\\Message\\EntityEnclosingRequest', $request);
     $this->assertEquals('Data', (string) $request->getBody());
     // Test using a resource
     $resource = fopen('php://temp', 'w+');
     fwrite($resource, 'Data');
     $request = RequestFactory::getInstance()->create('PUT', 'http://www.google.com/path?q=1&v=2', null, $resource);
     $this->assertInstanceOf('Guzzle\\Http\\Message\\EntityEnclosingRequest', $request);
     $this->assertEquals('Data', (string) $request->getBody());
     // Test using an object that can be cast as a string
     $request = RequestFactory::getInstance()->create('PUT', 'http://www.google.com/path?q=1&v=2', null, Url::factory('http://www.example.com/'));
     $this->assertInstanceOf('Guzzle\\Http\\Message\\EntityEnclosingRequest', $request);
     $this->assertEquals('http://www.example.com/', (string) $request->getBody());
 }
Пример #16
0
 /**
  * {@inheritdoc}
  */
 public function onOpen(ConnectionInterface $conn, RequestInterface $request = null)
 {
     if (null === $request) {
         throw new \UnexpectedValueException('$request can not be null');
     }
     $context = $this->_matcher->getContext();
     $context->setMethod($request->getMethod());
     $context->setHost($request->getHost());
     try {
         $parameters = $this->_matcher->match($request->getPath());
     } catch (MethodNotAllowedException $nae) {
         return $this->close($conn, 403);
     } catch (ResourceNotFoundException $nfe) {
         return $this->close($conn, 404);
     }
     if ($parameters['_controller'] instanceof ServingCapableInterface) {
         $parameters['_controller']->serve($conn, $request, $parameters);
     } else {
         $query = array();
         foreach ($query as $key => $value) {
             if (is_string($key) && '_' !== substr($key, 0, 1)) {
                 $query[$key] = $value;
             }
         }
         $url = Url::factory($request->getPath());
         $url->setQuery($query);
         $request->setUrl($url);
         $conn->controller = $parameters['_controller'];
         $conn->controller->onOpen($conn, $request);
     }
 }
Пример #17
0
 /**
  * @param string $baseUrl
  * @param ConsumerCredentials $consumer
  * @param TokenCredentials $tokenCredentials
  */
 public function __construct($baseUrl, ConsumerCredentials $consumerCredentials, TokenCredentials $tokenCredentials = null)
 {
     // @todo check type of $baseUrl
     $this->baseUrl = Url::factory($baseUrl);
     $this->consumerCredentials = $consumerCredentials;
     $this->tokenCredentials = $tokenCredentials;
 }
Пример #18
0
 /**
  * Factory method that instantiates an object from a Response object.
  *
  * @param Response         $response
  * @param ServiceInterface $service
  * @return static
  */
 public static function fromResponse(Response $response, ServiceInterface $service)
 {
     $self = parent::fromResponse($response, $service);
     $segments = Url::factory($response->getEffectiveUrl())->getPathSegments();
     $self->name = end($segments);
     return $self;
 }
Пример #19
0
 private function generateUrl($pathfile, array $entry)
 {
     $path = substr($pathfile, strlen($entry['directory']));
     $hexTime = dechex(time() + 3600);
     $token = md5($entry['passphrase'] . $path . $hexTime);
     return Url::factory($entry['mount-point'] . '/' . $token . "/" . $hexTime . $path);
 }
  /**
   * @param string $url
   * @param string $username
   * @param string $password
   * @throws NuxeoClientException
   */
  public function __construct($url = 'http://localhost:8080/nuxeo', $username = '******', $password = '******') {
    try {
      $this->baseUrl = Url::factory($url);
      $this->httpClient = new Client($url, array(
        Client::REQUEST_OPTIONS => array(
          'headers' => array(
            'Content-Type' => 'application/json+nxrequest'
          )
        )
      ));
    } catch(GuzzleException $ex) {
      throw NuxeoClientException::fromPrevious($ex);
    }

    $this->httpClient->setRequestFactory(new RequestFactory());

    $self = $this;

    /**
     * @param RequestInterface $request
     */
    $this->interceptors[] = function($request) use ($self, $username, $password) {
      try {
        $request->setAuth($username, $password);
      } catch(GuzzleException $ex) {
        throw NuxeoClientException::fromPrevious($ex);
      }
    };

  }
Пример #21
0
 public function getStringToSign(RequestInterface $request, $timestamp, $nonce)
 {
     $params = $this->getParamsToSign($request, $timestamp, $nonce);
     $params = $this->prepareParameters($params);
     $parameterString = new QueryString($params);
     $url = Url::factory($request->getUrl())->setQuery('')->setFragment(null);
     return strtoupper($request->getMethod()) . '&' . rawurlencode($url) . '&' . rawurlencode((string) $parameterString);
 }
 /**
  * Generate a base string for a HMAC-SHA1 signature
  * based on the given a url, method, and any parameters.
  *
  * @param Url    $url
  * @param string $method
  * @param array  $parameters
  *
  * @return string
  */
 protected function baseString(Url $url, $method = 'POST', array $parameters = array())
 {
     $baseString = rawurlencode($method) . '&';
     $schemeHostPath = Url::buildUrl(array('scheme' => $url->getScheme(), 'host' => $url->getHost(), 'path' => $url->getPath()));
     $baseString .= rawurlencode($schemeHostPath) . '&';
     $data = array();
     parse_str($url->getQuery(), $query);
     $data = array_merge($query, $parameters);
     // normalize data key/values
     array_walk_recursive($data, function (&$key, &$value) {
         $key = rawurlencode(rawurldecode($key));
         $value = rawurlencode(rawurldecode($value));
     });
     ksort($data);
     $baseString .= $this->queryStringFromData($data);
     return $baseString;
 }
Пример #23
0
 /**
  * Generate a base string for a HMAC-SHA1 signature
  * based on the given a url, method, and any parameters.
  *
  * @param Url    $url
  * @param string $method
  * @param array  $parameters
  *
  * @return string
  */
 protected function baseString(Url $url, $method = 'POST', array $parameters = array())
 {
     $baseString = rawurlencode($method) . '&';
     $schemeHostPath = Url::buildUrl(array('scheme' => $url->getScheme(), 'host' => $url->getHost(), 'path' => $url->getPath()));
     $baseString .= rawurlencode($schemeHostPath) . '&';
     $data = array();
     parse_str($url->getQuery(), $query);
     foreach (array_merge($query, $parameters) as $key => $value) {
         $data[rawurlencode($key)] = rawurlencode($value);
     }
     ksort($data);
     array_walk($data, function (&$value, $key) {
         $value = $key . '=' . $value;
     });
     $baseString .= rawurlencode(implode('&', $data));
     return $baseString;
 }
Пример #24
0
 /**
  * Return a authorize url.
  */
 public function getAuthorizeUrl($request_token, $callback_uri = NULL, $state = NULL)
 {
     $request_token = array('oauth_token' => is_array($request_token) ? $request_token['oauth_token'] : $request_token);
     // authorize
     $url = Url::factory($this->getConfig('base_url'));
     $url->addPath($this->getConfig('authorize_path'));
     $url->setQuery($request_token);
     return (string) $url;
 }
Пример #25
0
 /**
  * Return the URL as a string
  *
  * @return string
  */
 public function __toString()
 {
     $asString = parent::__toString();
     if ($this->privateKey) {
         $accessToken = hash_hmac('sha256', urldecode($asString), $this->privateKey);
         $url = GuzzleUrl::factory($asString);
         $url->getQuery()->set('accessToken', $accessToken);
         return (string) $url;
     }
     return $asString;
 }
 public function testCreatesSignedUrlsWithCustomPolicy()
 {
     /** @var $client \Aws\CloudFront\CloudFrontClient */
     $client = $this->getServiceBuilder()->get('cloudfront');
     if ($client->getConfig('private_key') == 'change_me') {
         $this->markTestSkipped('CloudFront private_key not set');
     }
     $url = $client->getSignedUrl(array('url' => 'http://abc.cloudfront.net/images/image.jpg', 'policy' => '{}'));
     $policy = Url::factory($url)->getQuery()->get('Policy');
     $this->assertRegExp('/^[0-9a-zA-Z-_~]+$/', $policy);
 }
Пример #27
0
 protected function filterRequest(Request $request)
 {
     $server = $request->getServer();
     $uri = Url::factory($request->getUri());
     $server['HTTP_HOST'] = $uri->getHost();
     $port = $uri->getPort();
     if ($port !== null && $port !== 443 && $port != 80) {
         $server['HTTP_HOST'] .= ':' . $port;
     }
     return new Request($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getFiles(), $request->getCookies(), $server, $request->getContent());
 }
Пример #28
0
public function fromParts(
$method,
array $urlParts,
$headers = null,
$body = null,
$protocol = 'HTTP',
$protocolVersion = '1.1'
) {
return $this->create($method, Url::buildUrl($urlParts), $headers, $body)
->setProtocolVersion($protocolVersion);
}
 /**
  * Ensures that the client marshals correctly
  *
  * @example Aws\CloudFormation\CloudFormationClient::estimateTemplateCost
  */
 public function testEstimatesTemplateCosts()
 {
     self::log('Estimate a template\'s cost.');
     $client = $this->client;
     $templateBody = file_get_contents(__DIR__ . '/template.json');
     // @begin
     $result = $client->estimateTemplateCost(array('TemplateBody' => $templateBody, 'Parameters' => array(array('ParameterKey' => 'KeyName', 'ParameterValue' => 'keypair-name'))));
     echo 'Result URL: ' . $result['Url'] . "\n";
     // @end
     $url = Url::factory($result['Url']);
     $this->assertEquals('calculator.s3.amazonaws.com', $url->getHost());
 }
 public function __construct(RequestInterface $request)
 {
     $url = Url::factory($request->getUrl());
     $url->setUsername($request->getUsername());
     $url->setPassword($request->getPassword());
     $this->url = $url;
     $this->request = $request;
     $this->finalRequest = array();
     $this->method = 'POST';
     $this->iterationNumber = 0;
     $this->blobList = null;
     $this->NXVoidOperation = 'true';
 }