Skip to content
Browse files

fixed JSONP bug

  • Loading branch information...
1 parent bcb21eb commit 54798392f7272fc371e7bd5468dfcdf0c3dc6f24 @nichtich committed Mar 1, 2012
Showing with 16 additions and 18 deletions.
  1. +4 −0 Changes
  2. +4 −17 lib/Plack/App/DAIA.pm
  3. +8 −1 t/basic.t
View
4 Changes
@@ -1,5 +1,9 @@
# Change file for Plack::App::DAIA
+0.50 2012-??-??
+ Fixed JSONP bug
+ Added content negotiation
+
0.45 2012-02-22
Added initalization hook and fixed a test suite bug
Added named capturing groups in idformat (requires Perl >= 5.10)
View
21 lib/Plack/App/DAIA.pm
@@ -98,6 +98,8 @@ sub as_psgi {
}
}
$content = $daia->xml( header => 1, xmlns => 1, ( $self->xslt ? (xslt => $self->xslt) : () ) );
+ } elsif ( $type =~ qr{^application/javascript} and ($callback || '') =~ /^[\w\.\[\]]+$/ ) {
+ $content = "$callback($content)";
}
return [ $status, [ "Content-Type" => $type ], [ encode('utf8',$content) ] ];
@@ -137,18 +139,7 @@ Then create an C<app.psgi> that returns an instance of your class:
use Your::App;
Your::App->new;
-You can mix this application with L<Plack> middleware, for instance
-L<Plack::Middleware::JSONP> for support of C<callback> parameter:
-
- use Plack:App::DAIA;
- use Plack::Builder;
-
- builder {
- enable 'JSONP';
- Plack::App::DAIA->new( code => sub {
- # ...
- } );
- };
+You can also mix this application with L<Plack> middleware.
It is highly recommended to test your services! Testing is made as easy as
possible with the L<provedaia> command line script.
@@ -253,12 +244,8 @@ can be triggered by setting C<initialized> to false.
Serializes a L<DAIA::Response> in some DAIA serialization format (C<xml> by
default) and returns a a PSGI response with given HTTP status code.
-=method call
-
-Core method of the L<Plack::Component>. You should not need to override this.
-
=head1 SEE ALSO
-L<Plack::App::DAIA::Validator>, L<Plack::DAIA::Test>.
+L<Plack::App::DAIA::Validator> and L<Plack::DAIA::Test>.
=cut
View
9 t/basic.t
@@ -23,7 +23,14 @@ test_psgi $app, sub {
$res = $cb->(GET "/?id=abc&format=json");
$daia = eval { DAIA::parse_json( $res->content ); };
isa_ok( $daia, 'DAIA::Response' );
-
+
+ $res = $cb->(GET "/?id=abc&format=json&callback=xyz");
+ my $jsonp = $res->content;
+ like( $jsonp, qr{xyz\(.+\)\s*$}ms, 'JSONP callback' );
+ $jsonp =~ s{xyz\((.+)\)\s*$}{$1}ms;
+ $daia = eval { DAIA::parse_json( $jsonp ); };
+ isa_ok( $daia, 'DAIA::Response' );
+
$res = $cb->(GET "/?id=x");
$daia = eval { DAIA::parse( $res->content ); };
like( $daia->json, qr{"please provide an explicit parameter format=xml"}m, "missing format" );

0 comments on commit 5479839

Please sign in to comment.
Something went wrong with that request. Please try again.