[Catalyst] Please Help: Aborting a Catalyst request in auto method

Rajesh Kumar Mallah mallah at redgrape.tech
Mon Apr 17 10:11:13 GMT 2017



Thanks for the Response.,

by default end is defined as:

sub end : ActionClass('RenderView') {}

It helped me to split it in 2 parts:


sub end : Private {
        my ($self, $c) = @_;
        $c->forward('render') unless $c->res->output ;
}

sub render : ActionClass('RenderView') { }


=========================

so forwarding to default rendering action was skipped
if any previous actions had set an output.

If was the default RenderView that was leading to
other actions.

Checking for output is only one of the way , I think based
on need other criteria can also be used.


Regds
mallah.


> It looks okay actually, documentation:
>
> "If an |auto| action returns 0, any remaining actions will be skipped,
> except for |end|".
>
> It goes directly to end. You should restructure your code probably, so
> that the main handling doesn't happen in end. You can also use detach if
> you want. Also you may want to use the existing plugins for
> Authentication.
>
>
> Best
>
> On 2017-04-16 08:15, Rajesh Kumar Mallah wrote:
>>
>> Hi ,
>>
>> I want to return HTTP Status 401 along with a body indicating
>> the friendly description from my auto method.
>>
>>
>> so i have below in my auto:
>> =====================================================
>> sub auto :Private {
>>          my ( $self, $c ) = @_;
>>          my $path = $c->request->path ;
>>
>>          if ($path !~ /login.html/ && ! $c->session->{username}) {
>>                   $c->log->warn('*** Not logged in Authorized ****');
>>                   $c->response->status(401);
>>                   $c->response->body(qq{Sorry please login to access
>> this
>> resource});
>>                   return 0;
>>          }
>>          return 1;
>> }
>>
>> ======================================================
>>
>>
>> However the request proceeds to other part of the chain
>> and does things which are not required.
>>
>>
>> ===========================================================
>>
>>
>>
>> [info] *** Request 1 (0.003/s) [839042] [Sun Apr 16 05:23:25 2017] ***
>> [debug] Path is "/api/rest/articlearticle/list_objects"
>> [debug] "GET" request for "api/rest/zingyhomes/article_article/" from
>> "127.0.0.1"
>> [debug] Query Parameters are:
>>
 .-------------------------------------+--------------------------------------.
>> | Parameter                           | Value
>>    |
>>
 +-------------------------------------+--------------------------------------+
>> | _                                   | 1492317689850
>>    |
>> | callback                            |
>> jQuery31001955130972547411_14923176- |
>> |                                     | 89849
>>    |
>> | list_count                          | 5
>>    |
>> | list_offset                         | 0
>>    |
>>
 '-------------------------------------+--------------------------------------'
>> [debug] Created session "37077cb431fb8502ac220d4c624b1db2b1217de7"
>> [warn] *** Not logged in Authorized ****
>> [debug] end subroutine.
>> [debug] Response Code: 401; Content-Type: unknown; Content-Length:
>> unknown
>> [info] Request took 0.069336s (14.423/s)
>>
 .------------------------------------------------------------+-----------.
>> | Action                                                     | Time
>> |
>>
 +------------------------------------------------------------+-----------+
>> | /api/rest/articlearticle/begin                             | 0.057763s
>> |
>> | /auto                                                      | 0.005666s
>> |
>> <---- I want to break
>> | /api/rest/articlearticle/end                               | 0.000543s
>> |
>>        here :-(
>> |  -> /api/rest/articlearticle/serialize                     | 0.000162s
>> |
>>
 '------------------------------------------------------------+-----------'
>>
>>
 =================================================================================
>>
>>
>> Previous discussions has been there
>> but it did not help me:
>>
>>
 http://grokbase.com/t/sc/catalyst/055r77h11s/returning-false-in-auto-action
>>
 http://grokbase.com/t/sc/catalyst/083ev978bd/again-die-in-an-action-chain-does-not-break-the-chain
>>
>>
>> is there anything to halt the request after the appropriate
>> HTTP Status  and
>> Headers      and
>> Body
>>
>> as been setup.
>>
>>
>> Regds
>> Rajesh Kumar Mallah.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> List: Catalyst at lists.scsys.co.uk
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive:
>> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>> Dev site: http://dev.catalyst.perl.org/
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>







More information about the Catalyst mailing list