Re: [Catalyst] Help with weird client: POST without Content-Type

2009-12-18 Thread Andrew Rodland
On Friday 18 December 2009 05:11:56 am Alex Povolotsky wrote:
 Hello!
 
 I'm (still) working with weird client-weird server-weird DB system, and
 I need some more help from community.
 
 Weird self-written client sends POST request without setting
 Content-Type at all.
 
 Client will be fixed, but until then I have to force Catalyst to parse
 that request as if it's type was application/x-www-form-urlencoded.
 
 How do I do that?
 
Here's a suggestion -- not sure if it's the best one, but it should work. In 
your app class (MyApp.pm or whatever) do:

before 'prepare_body' = sub {
my $c = shift;
if ($c-req-method eq 'POST'  !defined $c-req-content_type) {
$c-req-content_type('application/x-www-form-urlencoded');
}
};

The actual decision on how to parse the body is done by HTTP::Body, not by 
Catalyst, so it can't easily be overridden, but using this trick we hook into 
Catalyst after the headers are parsed but before HTTP::Body is invoked, and 
fool it into thinking that the Content-Type actually is what you want it to 
be.

Andrew

___
List: Catalyst@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/


Re: [Catalyst] Help with weird client: POST without Content-Type

2009-12-18 Thread Alex Povolotsky

Andrew Rodland wrote:

On Friday 18 December 2009 05:11:56 am Alex Povolotsky wrote:
  

Hello!

I'm (still) working with weird client-weird server-weird DB system, and
I need some more help from community.

Weird self-written client sends POST request without setting
Content-Type at all.

Client will be fixed, but until then I have to force Catalyst to parse
that request as if it's type was application/x-www-form-urlencoded.

How do I do that?


Here's a suggestion -- not sure if it's the best one, but it should work. In 
your app class (MyApp.pm or whatever) do:


before 'prepare_body' = sub {
my $c = shift;
if ($c-req-method eq 'POST'  !defined $c-req-content_type) {
$c-req-content_type('application/x-www-form-urlencoded');
}
};

The actual decision on how to parse the body is done by HTTP::Body, not by 
Catalyst, so it can't easily be overridden, but using this trick we hook into 
Catalyst after the headers are parsed but before HTTP::Body is invoked, and 
fool it into thinking that the Content-Type actually is what you want it to 
be.
  

Sounds reasonable; however, does not compile.

With Catalyst::Runtime 5.80, script-generated app class, fails with

String found where operator expected at 
/usr/home/tarkhil/work/GIMS/script/../lib/GIMS.pm line 37, near before 
'prepare_body'

   (Do you need to predeclare before?)


Alex.


___
List: Catalyst@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/


Re: [Catalyst] Help with weird client: POST without Content-Type

2009-12-18 Thread Nick Perez
On Fri, 18 Dec 2009 15:13:50 +0300
Alex Povolotsky tark...@over.ru wrote:


 String found where operator expected at 
 /usr/home/tarkhil/work/GIMS/script/../lib/GIMS.pm line 37, near
 before 'prepare_body'
 (Do you need to predeclare before?)

Need to use Moose; in the package to get 'before'

-- 

Nicholas Perez
XMPP/Email: n...@nickandperla.net
http://search.cpan.org/~nperez/
http://github.com/nperez

___
List: Catalyst@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/