FAQ
[resent to correct address]

Hi,

We recently upgraded from 5.33 to 5.66. There has been very little
breakage, but we do have something that I can't figure out.

# from test script

my $post = HTTP::Request->new(
POST => 'http://localhost/import/'
);
$post->header( name => $name );
$post->content( $some_xml );

request( $post )

# from controller

my $name = $c->req->header('name'); # ok
my $content = $c->req->body; # empty


I'm not sure how this code should be upgraded. As far as I can see
->body is not expected to work with POST, but I can't see what the
alternative is supposed to be.

Thanks,

Richard

Search Discussions

  • Matt S Trout at Mar 19, 2006 at 10:33 pm

    Richard Jolly wrote:
    [resent to correct address]

    Hi,

    We recently upgraded from 5.33 to 5.66. There has been very little
    breakage, but we do have something that I can't figure out.

    # from test script

    my $post = HTTP::Request->new(
    POST => 'http://localhost/import/'
    );
    $post->header( name => $name );
    $post->content( $some_xml );

    request( $post )

    # from controller

    my $name = $c->req->header('name'); # ok
    my $content = $c->req->body; # empty


    I'm not sure how this code should be upgraded. As far as I can see
    ->body is not expected to work with POST, but I can't see what the
    alternative is supposed to be.
    I suspect you need to specify the content-type on the request so it doesn't
    get submitted as x-form/url-encoded (or whatever the usual form type is)

    --
    Matt S Trout Offering custom development, consultancy and support
    Technical Director contracts for Catalyst, DBIx::Class and BAST. Contact
    Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information

    + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
  • Richard Jolly at Mar 20, 2006 at 11:42 am

    Matt S Trout wrote:
    Richard Jolly wrote:
    We recently upgraded from 5.33 to 5.66. There has been very little
    breakage, but we do have something that I can't figure out.

    # from test script

    my $post = HTTP::Request->new(
    POST => 'http://localhost/import/'
    );
    $post->header( name => $name );
    $post->content( $some_xml );

    request( $post )

    # from controller

    my $name = $c->req->header('name'); # ok my $content =
    $c->req->body;
    # empty


    I'm not sure how this code should be upgraded. As far as I can see
    ->body is not expected to work with POST, but I can't see what the
    alternative is supposed to be.
    I suspect you need to specify the content-type on the request
    so it doesn't get submitted as x-form/url-encoded (or
    whatever the usual form type is)
    Changing the content-type of the post to 'text/xml' gets me part of the
    way there. However then $c->req->body returns a File::Temp object, and
    $c->req->{_body} isa HTTP::Body::OctetStream.

    If I read from the File::Temp object I can get the data back, but this
    seems somewhat counter-intuitive.

    Tracing this through the code somewhat I find that HTTP::Body has
    subclasses for various content-types, and falls back to OctetStream if
    it cannot match one.

    Defining a HTTP::Body::TextXML package, and adjusting the lookup in
    $HTTP::Body::TYPES basically works (or will when I get the
    content-length correct).

    package HTTP::Body::TextXML;

    use strict;
    use base 'HTTP::Body';
    use bytes;

    sub spin {
    my $self = shift;
    $self->body( $self->{buffer} );
    $self->{buffer} = '';
    $self->{state} = 'done';
    }

    1;
    __END__

    Am I barking up the wrong tree here?

    Thanks,

    Richard

    http://www.bbc.co.uk/

    This e-mail (and any attachments) is confidential and may contain
    personal views which are not the views of the BBC unless specifically
    stated.
    If you have received it in error, please delete it from your system.
    Do not use, copy or disclose the information in any way nor act in
    reliance on it and notify the sender immediately. Please note that the
    BBC monitors e-mails sent or received.
    Further communication will signify your consent to this.
  • Aristotle Pagaltzis at Mar 20, 2006 at 12:02 pm
    * Richard Jolly [2006-03-20 12:50]:
    Changing the content-type of the post to 'text/xml' gets me part
    of the way there.
    Note that `text/xml` is a bad idea for a number of esoteric
    reasons that have to do with encodings and interactions between
    the HTTP and XML specs. Best practice is to use `application/xml`
    and avoid specifying a charset in the HTTP header.

    Regards,
    --
    Aristotle Pagaltzis // <http://plasmasturm.org/>

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedMar 19, '06 at 10:11p
activeMar 20, '06 at 12:02p
posts4
users4
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2021 Grokbase