[Catalyst] Conditional GET with Catalyst::Controller::REST

J. Shirley jshirley at gmail.com
Fri Sep 26 03:45:13 BST 2008


On Thu, Sep 25, 2008 at 4:02 AM, Gavin Carr <gavin at openfusion.com.au> wrote:
> I'm seeing a weird problem trying to get conditional GETs
> working under Catalyst::Controller::REST (0.66).
>
> Short version is that everything works beautifully when
> doing a HEAD, and my 304 is happily returned, but the same
> code on a GET causes a 500, with nothing helpful logged.
>
> Code snippet is:
>
>  sub index_GET {
>    my ($self, $c) = @_;
>
>    my $sset = $c->stash->{sset} or return;
>
>    my $ifmod_ts = $c->request->headers->if_modified_since;
>    my $sset_ts = $sset->modify_ts->epoch;
>    if ($ifmod_ts && $ifmod_ts == $sset_ts) {
>      $c->log->debug("not modified: ifmod_ts == sset_ts ($sset_ts)");
>      $c->response->status(304);
>      $c->log->debug('Status: ' . $c->response->status);
>      return 1;
>    }
>
>    # Rest of GET
>    # ...
>  }
>
> In the logs I see the two debug lines, and then nothing else:
>
>  [debug] not modified: ifmod_ts == sset_ts (1222241031)
>  [debug] Status: 304
>
> Any cluesticks as to what might be going on here? If I change the
> status to almost anything else but 304 it all works fine. And it
> doesn't seem to be the serialisation code either, as that explicitly
> checks for 3xx status codes and exits.
>
> Baffled. Anyone have conditional GETs working with C::C::REST?
>
> Cheers,
> Gavin
>
>

What is the full output from something like GET -e -d -s {path}?

I added a simple test to t/catalyst-action-rest.t that returns a 304
status and it passed as expected.  I'm guessing something somewhere
else is breaking things.  Do you have a begin/end and can you post a
simplified controller exhibiting the behaviors and a complete request
cycle?

Patch below, if you want to test:
=== t/catalyst-action-rest.t
==================================================================
--- t/catalyst-action-rest.t	(revision 5986)
+++ t/catalyst-action-rest.t	(local)
@@ -81,6 +81,15 @@
     $c->forward('ok');
 }

+sub not_modified : Local : ActionClass('REST') { }
+
+sub not_modified_GET {
+    my ( $self, $c ) = @_;
+    $c->res->status(304);
+    return 1;
+}
+
+
 sub ok : Private {
     my ( $self, $c ) = @_;

@@ -135,6 +144,9 @@
 is( $options_res->header('allow'),
     "GET", "OPTIONS request allow header properly set." );

+my $modified_res = request( $t->get( url => '/not_modified' ) );
+is( $modified_res->code, 304, "Not Modified request handler succeeded" );
+
 my $ni_res = request( $t->delete( url => '/not_implemented' ) );
 is( $ni_res->code, 200, "Custom not_implemented handler succeeded" );
 is(



More information about the Catalyst mailing list