| 1 | # | ||
| 2 | # This file is part of CatalystX-ExtJS-Direct | ||
| 3 | # | ||
| 4 | # This software is Copyright (c) 2014 by Moritz Onken. | ||
| 5 | # | ||
| 6 | # This is free software, licensed under: | ||
| 7 | # | ||
| 8 | # The (three-clause) BSD License | ||
| 9 | # | ||
| 10 | package CatalystX::TraitFor::Request::ExtJS; | ||
| 11 | $CatalystX::TraitFor::Request::ExtJS::VERSION = '2.1.5'; | ||
| 12 | # ABSTRACT: Sets the request method via a query parameter | ||
| 13 | use Moose::Role; | ||
| 14 | |||
| 15 | use namespace::autoclean; | ||
| 16 | use JSON::XS; | ||
| 17 | |||
| 18 | #has 'is_ext_upload' => ( isa => 'Bool', is => 'rw', lazy_build => 1 ); | ||
| 19 | |||
| 20 | sub is_ext_upload { | ||
| 21 | my ($self) = @_; | ||
| 22 | return $self->header('Content-Type') | ||
| 23 | && $self->header('Content-Type') =~ /^multipart\/form-data/ | ||
| 24 | && ( !$self->{content_type} || $self->{content_type} ne 'application/json'); | ||
| 25 | } | ||
| 26 | |||
| 27 | around 'method' => sub { | ||
| 28 | my ( $orig, $self, $method ) = @_; | ||
| 29 | return $self->$orig($method) if($method); | ||
| 30 | return $self->query_params->{'x-tunneled-method'} || $self->$orig(); | ||
| 31 | |||
| 32 | |||
| 33 | }; | ||
| 34 | |||
| 35 | 1; | ||
| 36 | |||
| 37 | __END__ |