package RSApache::Response::XML;

use strict;
use warnings;

use Apache2::Const qw(OK);

use lib '/app/tools/common/lib';
use Common::WriteXML;
use Common::Assert;

use RSApache::Response;
use base 'RSApache::Response';

sub _init {
    my ( $self, $output ) = @_;
    assert( defined $output );

    # Assume that if I am passed a hash ref, this contains XML.
    # Otherwise, just pass it along.
    #
    if ( ref($output) ) {
        $self->{output} = Common::WriteXML::GetXMLString($output);
    } else {
        $self->{output} = $output;
    }
}

sub respond {
    my ( $self, $apache ) = @_;

    $apache->content_type("application/xml");

    # Instruct the browser (specifically, Internet Explorer) to NOT CACHE this response
    #
    $apache->header_out( 'Cache-Control' => 'no-cache' );
    $apache->header_out( 'Pragma'        => 'no-cache' );
    $apache->header_out( 'Expires'       => '-1' );

    $apache->send_http_header();
    binmode( STDOUT, ":utf8" );
    print $self->{output};

    return OK;
}

sub respondRaw {
    my ( $self, $apache ) = @_;

    $apache->content_type("text/plain");
    $apache->send_http_header();
    binmode( STDOUT, ":utf8" );
    print $self->{output};

    return OK;
}

###
1;    # Play nicely.
###

