add digest generation

This commit is contained in:
Fred 2021-10-22 08:52:42 +08:00
parent 920ddd3cfb
commit 7efe3cb56f
1 changed files with 5 additions and 4 deletions

View File

@ -25,13 +25,14 @@ class GuzzleHttpSignatures
*/ */
public static function middlewareFromContext(Context $context) public static function middlewareFromContext(Context $context)
{ {
return function (callable $handler) use ($context) return function (callable $handler) use ($context) {
{
return function ( return function (
Request $request, Request $request,
array $options array $options
) use ($handler, $context) ) use ($handler, $context) {
{
$contentsRequest = (string) $request->getBody();
$request = $request->withAddedHeader("digest", base64_encode(hash('sha512', $contentsRequest, true)));
$request = $context->signer()->sign($request); $request = $context->signer()->sign($request);
return $handler($request, $options); return $handler($request, $options);
}; };