/** * 通过提供的凭证,对特定请求进行签名,并添加对应的 HTTP 头至请求中。 * * @param RequestInterface $request 要签名的请求。 * @param CredentialsInterface $credential 使用的凭证。 * * @return RequestInterface 修改(签名)过的请求。 */ public function signRequest(RequestInterface $request, CredentialsInterface $credential) { $content = base64_encode($credential['key'] . ':' . $credential['secret']); $basicSignature = "Basic {$content}"; // 先清除之前可能存在的 HTTP 头。 return $request->withoutHeader('Authorization')->withHeader('Authorization', $basicSignature); }
/** * @param string $header * @return \Psr\Http\Message\MessageInterface */ public function withoutHeader($header) { $this->request = $this->request->withoutHeader($header); return $this; }
public function withoutHeader($name) { $new = clone $this; $new->request = $this->request->withoutHeader($name); return $new; }