CGI-Utils

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

  getHeader(@args)
    Generates HTTP headers. Standard arguments are content_type, cookie,
    target, expires, and charset. These should be passed as name/value
    pairs. If only one argument is passed, it is assumed to be the
    'content_type' argument. If no values are passed, the content type is
    assumed to be 'text/html'. The charset defaults to ISO-8859-1. A hash
    reference can also be passed. E.g.,

     print $cgi_obj->getHeader({ content_type => 'text/html', expires => '+3d' });

    The names 'content-type', and 'type' are aliases for 'content_type'. The
    arguments may also be passed CGI.pm style with a '-' in front, e.g.

     print $cgi_obj->getHeader( -content_type => 'text/html', -expires => '+3d' );

    Cookies may be passed with the 'cookies' key either as a string, a hash
    ref, or as a CGI::Cookies object, e.g.

     my $cookie = { name => 'my_cookie', value => 'cookie_val' };
     print $cgi_obj->getHeader(cookies => $cookie);

lib/CGI/Utils.pm  view on Meta::CPAN


Generates HTTP headers.  Standard arguments are content_type,
cookie, target, expires, and charset.  These should be passed as
name/value pairs.  If only one argument is passed, it is assumed
to be the 'content_type' argument.  If no values are passed, the
content type is assumed to be 'text/html'.  The charset defaults
to ISO-8859-1.  A hash reference can also be passed.  E.g.,

 print $cgi_obj->getHeader({ content_type => 'text/html', expires => '+3d' });

The names 'content-type', and 'type' are aliases for
'content_type'.  The arguments may also be passed CGI.pm style
with a '-' in front, e.g.

 print $cgi_obj->getHeader( -content_type => 'text/html', -expires => '+3d' );

Cookies may be passed with the 'cookies' key either as a string,
a hash ref, or as a CGI::Cookies object, e.g.

 my $cookie = { name => 'my_cookie', value => 'cookie_val' };
 print $cgi_obj->getHeader(cookies => $cookie);

lib/CGI/Utils.pm  view on Meta::CPAN

Aliases: header(), get_header

=cut
    sub getHeader {
        my ($self, @args) = @_;
        my $arg_count = scalar(@args);
        if ($arg_count == 0) {
            return "Content-Type: text/html\r\n\r\n";
        }
        if ($arg_count == 1 and ref($args[0]) ne 'HASH') {
            # content-type provided
            return "Content-Type: $args[0]\r\n\r\n";
        }

        my $map_list = [ [ 'type', 'content-type', 'content_type' ],
                         'status',
                         [ 'cookie', 'cookies' ],
                         'target', 'expires', 'nph', 'charset', 'attachment',
                         'mod_perl',
                       ];
        my ($params, $extras) = $self->_parse_sub_params($map_list, \@args);
        
        my $charset = $$params{charset} || 'ISO-8859-1';
        my $content_type = $$params{type};
        $content_type ||= 'text/html' unless defined($content_type);

lib/CGI/Utils.pm  view on Meta::CPAN

        if ($arg_count == 0) {
            if ($mod_perl) {
                $r->err_header_out('Content-Type' => 'text/html');
            } else {
                print STDOUT "Content-Type: text/html\r\n\r\n";
            }
            return 1;
        }
        
        if ($arg_count == 1 and ref($args[0]) ne 'HASH') {
            # content-type provided
            if ($mod_perl) {
                $r->err_header_out('Content-Type' => $args[0]);
            } else {
                print STDOUT "Content-Type: $args[0]\r\n\r\n";
            }
            
            return 1;
        }

        unless ($mod_perl) {

lib/CGI/Utils.pm  view on Meta::CPAN

        my ($self, $boundary, $fh, $headers, $disposition_fields) = @_;

        my $amt_read = 0;
        my $body;
        my $eol = $self->_getEndOfLineSeq;
        my $end_char = substr($eol, -1, 1);
        my $buf = '';
        my $buf2 = '';

        my $file_name = $$disposition_fields{filename};
        my $info = { 'Content-Type' => $$headers{'content-type'} };
        $$self{_upload_info}{$file_name} = $info;

        my $out_fh = CGI::Utils::UploadFile->new_tmpfile($file_name);
        
        while (my $size = $self->_read($fh, $buf, 4096, 0, $end_char)) {
            $amt_read += $size;
            if (substr($buf, -1, 1) eq $end_char and $buf =~ /^--$boundary(?:--)?$eol$/
                and $buf2 =~ /$eol$/
               ) {
                $buf2 =~ s/$eol$//;



( run in 2.370 seconds using v1.01-cache-2.11-cpan-524268b4103 )