コード例 #1
0
ファイル: ClientCallPanel.php プロジェクト: dorxy/debug_http
 /**
  * Add a HTTP call to the data
  *
  * @param Request  $request Call request
  * @param Response $response Call response
  * @param float    $time duration of the call
  */
 public static function addCall($request, $response, $time = null)
 {
     $calls = static::config('calls');
     $trace = Debugger::trace(['start' => 2]);
     $calls[] = ['request' => ['uri' => (string) $request->getUri(), 'body' => $request->body(), 'method' => $request->getMethod(), 'headers' => $request->getHeaders(), 'content-type' => $request->getHeader('Content-Type')], 'response' => ['body' => $response->body(), 'status_code' => $response->getStatusCode(), 'headers' => $response->getHeaders(), 'content-type' => $response->getHeader('Content-Type')], 'time' => $time, 'trace' => $trace];
     static::drop('calls');
     static::config('calls', $calls);
 }
コード例 #2
0
ファイル: Oauth.php プロジェクト: nrother/cakephp
 /**
  * Generate the Oauth basestring
  *
  * - Querystring, request data and oauth_* parameters are combined.
  * - Values are sorted by name and then value.
  * - Request values are concatenated and urlencoded.
  * - The request URL (without querystring) is normalized.
  * - The HTTP method, URL and request parameters are concatenated and returned.
  *
  * @param \Cake\Http\Client\Request $request The request object.
  * @param array $oauthValues Oauth values.
  * @return string
  */
 public function baseString($request, $oauthValues)
 {
     $parts = [$request->getMethod(), $this->_normalizedUrl($request->getUri()), $this->_normalizedParams($request, $oauthValues)];
     $parts = array_map([$this, '_encode'], $parts);
     return implode('&', $parts);
 }
コード例 #3
0
ファイル: Digest.php プロジェクト: nrother/cakephp
 /**
  * Generate the header Authorization
  *
  * @param \Cake\Http\Client\Request $request The request object.
  * @param array $credentials Authentication credentials.
  * @return string
  */
 protected function _generateHeader(Request $request, $credentials)
 {
     $path = $request->getUri()->getPath();
     $a1 = md5($credentials['username'] . ':' . $credentials['realm'] . ':' . $credentials['password']);
     $a2 = md5($request->method() . ':' . $path);
     if (empty($credentials['qop'])) {
         $response = md5($a1 . ':' . $credentials['nonce'] . ':' . $a2);
     } else {
         $credentials['cnonce'] = uniqid();
         $nc = sprintf('%08x', $credentials['nc']++);
         $response = md5($a1 . ':' . $credentials['nonce'] . ':' . $nc . ':' . $credentials['cnonce'] . ':auth:' . $a2);
     }
     $authHeader = 'Digest ';
     $authHeader .= 'username="******"'], ['\\\\', '\\"'], $credentials['username']) . '", ';
     $authHeader .= 'realm="' . $credentials['realm'] . '", ';
     $authHeader .= 'nonce="' . $credentials['nonce'] . '", ';
     $authHeader .= 'uri="' . $path . '", ';
     $authHeader .= 'response="' . $response . '"';
     if (!empty($credentials['opaque'])) {
         $authHeader .= ', opaque="' . $credentials['opaque'] . '"';
     }
     if (!empty($credentials['qop'])) {
         $authHeader .= ', qop="auth", nc=' . $nc . ', cnonce="' . $credentials['cnonce'] . '"';
     }
     return $authHeader;
 }