summaryrefslogtreecommitdiff
path: root/lib/Ultramarine/Middleware/SetContentType.pm6
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Ultramarine/Middleware/SetContentType.pm6')
-rw-r--r--lib/Ultramarine/Middleware/SetContentType.pm626
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/Ultramarine/Middleware/SetContentType.pm6 b/lib/Ultramarine/Middleware/SetContentType.pm6
new file mode 100644
index 0000000..a3fab94
--- /dev/null
+++ b/lib/Ultramarine/Middleware/SetContentType.pm6
@@ -0,0 +1,26 @@
+use v6.d.PREVIEW;
+use Cro::HTTP::Middleware;
+use Cro::HTTP::BodySerializerSelector;
+use Ultramarine::Serialiser::XML;
+
+my %types = (
+ xml => 'application/xml',
+ json => 'application/json',
+ jsonp => 'application/javascript',
+);
+
+class Ultramarine::Middleware::SetContentType
+ does Cro::HTTP::Middleware::Response {
+ method process(Supply:D $response-stream) {
+ supply whenever $response-stream -> $response {
+ with $response.request {
+ my $format = .query-value('f')[0] // 'xml';
+ with %types{$format} {
+ $response.append-header('Content-type',$_);
+ }
+ }
+
+ emit $response;
+ }
+ }
+}