use v6.d.PREVIEW;
use Cro::HTTP::BodySerializer;
use XML::Writer;
class Ultramarine::Serialiser::XML
does Cro::HTTP::BodySerializer {
method is-applicable(Cro::HTTP::Message $message, $body --> Bool) {
with $message.content-type {
(.type eq 'application' && .subtype eq 'xml' || .suffix eq 'xml') &&
($body ~~ Map || $body ~~ List)
}
else {
False
}
}
method serialize(Cro::HTTP::Message $message, $body --> Supply) {
my $xml = XML::Writer.serialize(
subsonic-response => [
:xmlns<http://subsonic.org/restapi>,
:version<1.13.0>,
|$body,
],
).encode('utf-8');
self!set-content-length($message, $xml.bytes);
supply { emit $xml }
}
}