Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Handling XML content with HTTP::Daemon

by Matts (Deacon)
on Jul 09, 2002 at 12:31 UTC ( [id://180458] : note . print w/replies, xml ) Need Help??

in reply to Handling XML content with HTTP::Daemon

Looks like you're forgetting to send headers. Try:
$c->send_response( "Content-type: text/xml+svg\r\n\r\n". $svg->xmlify() );

Replies are listed 'Best First'.
Re: Re: Handling XML content with HTTP::Daemon
by hackmare (Pilgrim) on Jul 09, 2002 at 14:10 UTC

    Thanks a lot for pointing out what should have been obvious!, that got me a long way towards my goal. Now I just need to cleanly get rid of the following footer which seems to get appended to my file each time, confusing the XML parsers:

    ...the response... <!-- my comments... followed by two offending lines. --> Date: Tue, 09 Jul 2002 13:17:37 GMT Server: libwww-perl-daemon/1.21

    When I go into HTTP::Daemon and comment out these two lines:

    #(from HTTP::Daemon line 563) sub send_basic_header { my $self = shift; return if $self->antique_client; $self->send_status_line(@_); #taken out print $self "Date: ", time2str(time), $CRLF; my $product = $self->daemon->product_tokens; #taken out print $self "Server: $product$CRLF" if $product; }

    then the offending footers dissapear. Do you know what these two footer lines do, and should they not be in the header rather than in the footer? I can't find any way to override them other than by removing them from the module.

    ps. you had the wrong mime type in your solution (just to be clear about that). The SVG mimetype is image/svg+xml

    $c->send_response( "Content-type: image/svg+xml\r\n\r\n". $svg->xmlify());

      Ah, HTTP::Daemon expects a result code too. So you need:
      $c->send_response( 200, "Content-type: image/svg+xml\r\n\r\n". $svg->xmlify() );

        Here was the problem...

        I needed to create an HTTP::Response object explicitly and assign it a return code, content, and header information.

        #new response object with default error values my $response = new HTTP::Response( 404,undef,undef,"404 - Not found." +); #assign values using obvious methods $response->header(Content_Length => $len); $response->header(Content_Type => "image/svg+xml"); $response->content($out); $response->code(200); $c->send_response($response);

        This works now.

        Thanks you all for the help.