aboutsummaryrefslogtreecommitdiff
path: root/lib/Cro/BodyParser/VlcXML.rakumod
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Cro/BodyParser/VlcXML.rakumod')
-rw-r--r--lib/Cro/BodyParser/VlcXML.rakumod38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/Cro/BodyParser/VlcXML.rakumod b/lib/Cro/BodyParser/VlcXML.rakumod
new file mode 100644
index 0000000..0750c9a
--- /dev/null
+++ b/lib/Cro/BodyParser/VlcXML.rakumod
@@ -0,0 +1,38 @@
+use v6.d;
+use Cro::BodyParser;
+use Cro::HTTP::Message;
+use XML;
+
+class Cro::BodyParser::VlcXML does Cro::BodyParser {
+ method is-applicable(Cro::HTTP::Message $message --> Bool) {
+ with $message.content-type {
+ .type eq 'application'|'text' && .subtype eq 'xml' || .suffix eq 'json'
+ }
+ else {
+ False
+ }
+ }
+
+ method parse(Cro::HTTP::Message $message --> Promise) {
+ Promise(
+ supply {
+ my $payload = Blob.new;
+
+ whenever $message.body-byte-stream -> $blob {
+ $payload ~= $blob;
+ LAST emit from-xml($payload.decode('utf-8'));
+ }
+
+ # if we had LibXML
+
+ # my LibXML::PushParser $parser .= new();
+ #
+ # whenever $message.body-byte-stream -> $blob {
+ # $parser.push($blob);
+ # $payload ~= $blob;
+ # LAST emit $parser.finish-push;
+ # }
+ }
+ )
+ }
+}