Permalink
Browse files

Fix for empty sources

  • Loading branch information...
nichtich committed Nov 3, 2011
1 parent a44023e commit b4574535a8cd59f65f253d7ee7b53c6ae9f90751
Showing with 37 additions and 12 deletions.
  1. +3 −0 Changes
  2. +3 −2 README.md
  3. +1 −1 dist.ini
  4. +3 −2 lib/Plack/Middleware/RDF/Flow.pm
  5. +27 −7 t/10_app.t
View
@@ -1,5 +1,8 @@
# Change file for Plack::Middleware::RDF::Flow
+0.171 2011-11-03
+ Fix for empty sources
+
0.170 2011-09-02
First release at CPAN
View
@@ -4,7 +4,7 @@ Plack::Middleware::RDF::Flow - Serve RDF as Linked Data for RDF::Flow
# VERSION
-version 0.170
+version 0.171
# SYNOPSIS
@@ -81,7 +81,8 @@ Code reference to rewrite the request URI.
- pass_through
-Retrieve RDF data
+Retrieve RDF data also if no serialization format was determined. In this case
+RDF data is stored in `rdflow.data` and passed to the next layer.
- formats
View
@@ -1,5 +1,5 @@
name = Plack-Middleware-RDF-Flow
-version = 0.170
+version = 0.171
license = Perl_5
copyright_holder = Jakob Voß
author = Jakob Voß <voss@gbv.de>
@@ -100,7 +100,7 @@ sub call {
$rdf_data = $serializer->serialize_iterator_to_string( $rdf );
}
- if ( defined $rdf_data ) {
+ if ( $rdf_data ) {
$rdf_data = encode('utf8',$rdf_data);
return [ 200, [ 'Content-Type' => $type ], [ $rdf_data ] ];
}
@@ -282,7 +282,8 @@ Code reference to rewrite the request URI.
=item pass_through
-Retrieve RDF data
+Retrieve RDF data also if no serialization format was determined. In this case
+RDF data is stored in C<rdflow.data> and passed to the next layer.
=item formats
View
@@ -11,10 +11,11 @@ use Data::Dumper;
use Try::Tiny;
use Plack::Middleware::RDF::Flow;
+use RDF::Flow;
use RDF::Flow::Dummy;
my $dummy = RDF::Flow::Dummy->new;
-my $not_found = sub { [404,['Content-Type'=>'text/plain'],['Not found']] };
+my $not_found = sub { [404,['Content-Type'=>'text/html'],['Not found']] };
my $app = builder {
enable 'RDF::Flow', source => sub { $dummy->retrieve( @_ ) };
@@ -26,7 +27,7 @@ test_app
tests => [{
name => 'Nobody asked for RDF',
request => [ GET => '/example' ],
- headers => { 'Content-Type' => 'text/plain' },
+ headers => { 'Content-Type' => 'text/html' },
content => 'Not found',
code => 404,
},{
@@ -37,18 +38,23 @@ test_app
},
( map { {
name => "request accept: $_",
- request => [ GET => '/example', [ 'Accept' => "$_,text/plain" ] ],
+ request => [ GET => '/example', [ 'Accept' => "$_,text/html" ] ],
headers => { 'Content-Type' => $_ },
content => qr{example> a <http://www.w3.org/2000/01/rdf-schema#Resource>},
} } qw(text/turtle application/x-turtle application/turtle)
- )
+ ),{
+ name => "request accept with q= value",
+ request => [ GET => '/example', [ 'Accept' => 'text/html;q=0.01,text/turtle;q=0.5' ] ],
+ headers => { 'Content-Type' => 'text/turtle' },
+ content => qr{example> a <http://www.w3.org/2000/01/rdf-schema#Resource>},
# TODO mime-type=..., file extension
- ,{
+ },{
name => 'request accept: application/rdf+xml',
request => [ 'GET', '/', [ 'Accept' => 'application/rdf+xml' ] ],
headers => { 'Content-Type' => 'application/rdf+xml', },
}];
+
$app = builder {
enable 'RDF::Flow'; # empty_source
$not_found;
@@ -61,13 +67,27 @@ test_app
tests => [{
name => 'nobody asked for RDF',
request => [ GET => '/example' ],
- headers => { 'Content-Type' => 'text/plain' },
+ headers => { 'Content-Type' => 'text/html' },
content => 'Not found',
code => 404,
},{
name => 'request format=ttl',
request => [ GET => '/example?format=ttl' ],
- headers => { 'Content-Type' => 'text/plain' },
+ headers => { 'Content-Type' => 'text/html' },
+ content => 'Not found',
+ code => 404,
+ }];
+
+$app = builder {
+ enable 'RDF::Flow', source => rdflow( from => '/dev/null' );
+ $not_found;
+};
+
+test_app
+ app => $app,
+ tests => [{
+ name => 'reques format=ttl on empty source',
+ request => [ GET => '/example?format=ttl' ],
content => 'Not found',
code => 404,
}];

0 comments on commit b457453

Please sign in to comment.