Changeset 2118

Show
Ignore:
Timestamp:
12/21/06 10:16:44
Author:
miyagawa
Message:

add no_x_json_header config. Add utf-8 BOM for Safari. This be 0.13

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Catalyst-View-JSON/trunk/Changes

    r2056 r2118  
    11Revision history for Perl extension Catalyst::View::JSON 
     2 
     30.13  Wed Dec 20 17:12:32 PST 2006 
     4        - Added UTF-8 BOM if the User-Agent is Safari and encoding is utf-8 (Jun Kuriyama) 
     5        - Added 'no_x_json_header' option to disable auto-setting X-JSON for Prototype.js 
     6          (Jun Kuriyama) 
     7        - Documented json_driver config 
    28 
    390.12  Thu Oct 26 17:37:58 JST 2006 
  • Catalyst-View-JSON/trunk/lib/Catalyst/View/JSON.pm

    r2106 r2118  
    22 
    33use strict; 
    4 our $VERSION = '0.12'; 
     4our $VERSION = '0.13'; 
    55 
    66use base qw( Catalyst::View ); 
     
    99use Catalyst::Exception; 
    1010 
    11 __PACKAGE__->mk_accessors(qw( allow_callback callback_param expose_stash encoding json_dumper )); 
     11__PACKAGE__->mk_accessors(qw( allow_callback callback_param expose_stash encoding json_dumper no_x_json_header )); 
    1212 
    1313sub new { 
     
    9494    } 
    9595 
    96     if ($c->req->header('X-Prototype-Version')) { 
     96    if ($c->req->header('X-Prototype-Version') && $self->no_x_json_header) { 
    9797        $c->res->header('X-JSON' => 'eval("("+this.transport.responseText+")")'); 
    9898    } 
    9999 
    100100    my $output; 
     101 
     102    ## add UTF-8 BOM if the client is Safari 
     103    if (($c->req->user_agent || '') =~ m/Safari/ and $encoding eq 'utf-8') { 
     104        $output = "\xEF\xBB\xBF"; 
     105    } 
     106 
    101107    $output .= "$cb(" if $cb; 
    102108    $output .= $json; 
     
    204210the only alternative encoding driver. 
    205211 
     212=item no_x_json_header 
     213 
     214  no_x_json_header: 1 
     215 
     216By default this plugin sets X-JSON header if the requested client is a 
     217Prototype.js with X-JSON support. By setting 1, you can opt-out this 
     218behavior so that you can do eval() by your own. Defaults to 0. 
     219 
    206220=back 
    207221 
     
    290304recommened approach is to use Catalyst::View::JSON which will JSON 
    291305format all the response data and return it in the response body. 
    292 In at least prototype 1.5.0 rc0 and above, prototype.js will send 
    293 the X-Prototype-Version header. If this is encountered, a JavaScript 
    294 eval will be returned in the X-JSON resonse header to automatically 
    295 eval the response body. If your version of prototype does not send 
    296 this header, you can manually eval the response body using the 
    297 following JavaScript: 
     306 
     307In at least prototype 1.5.0 rc0 and above, prototype.js will send the 
     308X-Prototype-Version header. If this is encountered, a JavaScript eval 
     309will be returned in the X-JSON resonse header to automatically eval 
     310the response body, unless you set I<no_x_json_header> to 1. If your 
     311version of prototype does not send this header, you can manually eval 
     312the response body using the following JavaScript: 
    298313 
    299314  evalJSON: function(request) { 
     
    320335kazeburo 
    321336Daisuke Murase 
     337Jun Kuriyama 
    322338 
    323339=head1 SEE ALSO