NAME
Net::Blossom::Server::PSGI - PSGI adapter for the Blossom server core
SYNOPSIS
use Net::Blossom::Server::PSGI;
my $app = Net::Blossom::Server::PSGI->new(
server => $server,
authorize => sub {
my %ctx = @_;
return $pubkey;
},
)->to_app;
DESCRIPTION
Net::Blossom::Server::PSGI turns a Net::Blossom::Server object into a PSGI application code reference. It does not depend on Plack and does not choose an HTTP daemon for the application.
The adapter translates the PSGI environment into a Net::Blossom::Server::Request, applies optional authorization, and passes the request into Net::Blossom::Server. The returned Net::Blossom::Server::Response is translated into the PSGI response array.
CORS headers required by BUD-01 are added to every PSGI response. OPTIONS requests are handled directly by this adapter as CORS preflight requests and do not reach authorization or server route dispatch.
Malformed requests are returned as 400 responses. Typed Net::Blossom::Server::Error exceptions are returned with their configured status and headers. Other exceptions are returned as generic 500 responses.
CONSTRUCTOR
new
my $adapter = Net::Blossom::Server::PSGI->new(%args);
Required arguments:
serverA
Net::Blossom::Serverobject.
Optional arguments:
authorizeCode reference called before dispatch. It receives
requestandenvnamed arguments. When it returns a defined value, that value is passed to the server core as the verifiedpubkey.authorizationA
Net::Blossom::Server::Authorizationobject. When supplied, the adapter validates BUD-11Authorizationheaders for implemented Blossom endpoints and passes the verified event pubkey and authorization result to the server core.
Unknown arguments or invalid values croak. authorize and authorization are mutually exclusive.
ACCESSORS
server
Returns the Net::Blossom::Server object.
authorize
Returns the optional authorization callback.
authorization
Returns the optional BUD-11 authorization verifier.
METHODS
to_app
my $app = $adapter->to_app;
Returns a PSGI application code reference.