mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-23 06:51:27 +00:00
41 lines
No EOL
963 B
PHP
41 lines
No EOL
963 B
PHP
<?php
|
|
|
|
namespace App\Util\HttpSignatures;
|
|
|
|
use GuzzleHttp\HandlerStack;
|
|
use GuzzleHttp\Psr7\Request;
|
|
use App\Util\HttpSignatures\Context;
|
|
|
|
class GuzzleHttpSignatures
|
|
{
|
|
/**
|
|
* @param Context $context
|
|
* @return HandlerStack
|
|
*/
|
|
public static function defaultHandlerFromContext(Context $context)
|
|
{
|
|
$stack = HandlerStack::create();
|
|
$stack->push(self::middlewareFromContext($context));
|
|
|
|
return $stack;
|
|
}
|
|
|
|
/**
|
|
* @param Context $context
|
|
* @return \Closure
|
|
*/
|
|
public static function middlewareFromContext(Context $context)
|
|
{
|
|
return function (callable $handler) use ($context)
|
|
{
|
|
return function (
|
|
Request $request,
|
|
array $options
|
|
) use ($handler, $context)
|
|
{
|
|
$request = $context->signer()->sign($request);
|
|
return $handler($request, $options);
|
|
};
|
|
};
|
|
}
|
|
} |