--- loncom/cgi/loncgi.pm 2008/12/25 01:51:03 1.11 +++ loncom/cgi/loncgi.pm 2011/10/21 20:00:30 1.12 @@ -1,7 +1,7 @@ # # LON-CAPA helpers for cgi-bin scripts # -# $Id: loncgi.pm,v 1.11 2008/12/25 01:51:03 raeburn Exp $ +# $Id: loncgi.pm,v 1.12 2011/10/21 20:00:30 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -54,8 +54,9 @@ use warnings FATAL=>'all'; no warnings 'uninitialized'; use lib '/home/httpd/lib/perl/'; -use CGI(); +use CGI qw(:standard); use CGI::Cookie(); +use MIME::Types(); use Fcntl qw(:flock); use LONCAPA; use LONCAPA::Configuration(); @@ -222,6 +223,39 @@ sub cgi_getitems { } return; } + +############################################# +############################################# + +=pod + +=cgi_header() + +Inputs: $contenttype - Content Type (e.g., text/html or text/plain) + $nocache - Boolean 1 = nocache +Returns: HTTP Response headers constructed using CGI.pm + +=cut + +############################################# +############################################# +sub cgi_header { + my ($contenttype,$nocache) = @_; + my $mimetypes = MIME::Types->new; + my %headers; + if ($contenttype ne '') { + if ($mimetypes->type($contenttype) ne '') { + $headers{'-type'} = $contenttype; + } + } + if ($nocache) { + $headers{'-expires'} = 'now'; + } + if (%headers) { + return CGI::header(%headers); + } + return; +} =pod