diff Lib/IMPL/Web/Handler/JSONView.pm @ 256:32aceba4ee6d

corrected ViewHandlers to handle cookies and headers. Dirty hacks to handle binary data RestController doesn't deal with file extensions anymore.
author sergey
date Wed, 12 Dec 2012 04:29:50 +0400
parents f48a1a9f4fa2
children 52aae1b85084
line wrap: on
line diff
--- a/Lib/IMPL/Web/Handler/JSONView.pm	Fri Dec 07 16:58:19 2012 +0400
+++ b/Lib/IMPL/Web/Handler/JSONView.pm	Wed Dec 12 04:29:50 2012 +0400
@@ -2,6 +2,7 @@
 use strict;
 use JSON;
 
+use IMPL::lang qw(is);
 use IMPL::declare {
     require => {
         HttpResponse => 'IMPL::Web::HttpResponse',
@@ -24,17 +25,27 @@
 	my $result = $next ? $next->($action) : undef;
 	
 	
-	my $model = ( ref $result and eval { $result->isa(ViewResult) } )
+	my $model = ( ref $result and is($result,ViewResult) )
 	   ? $result->model
 	   : $result;
 	
 	$model = [$model] unless ref $model;
 	
-    return HttpResponse->new({
+	my %params = (
         type => $this->contentType,
         charset => 'utf-8',             
         body => JSON->new->utf8->pretty->encode($model)
-    });
+	);
+	
+	if(is($result,ViewResult)) {
+    	$params{status} = $result->status if $result->status;
+    	$params{headers} = $result->headers if $result->headers;
+    	$params{cookies} = $result->cookies if $result->cookies;
+	}
+	
+    return HttpResponse->new(
+        %params
+    );
 }
 
 1;