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'|'text' && .subtype eq 'xml' || .suffix eq 'xml') && ($body ~~ Map || $body ~~ List) } else { False } } method serialize(Cro::HTTP::Message $message, $body --> Supply) { my $xml = ( qq{\n} ~ XML::Writer.serialize( subsonic-response => [ :xmlns, :version<1.13.0>, |$body, ], ) ).encode('utf-8'); self!set-content-length($message, $xml.bytes); supply { emit $xml } } }