]> bicyclesonthemoon.info Git - ott/bsta/blobdiff - attach.1.pl
hyperlinks to static previous/next page
[ott/bsta] / attach.1.pl
index d680f7676cf4debcdd7c847278823c9adea33835..151dddcf5dcd8104a3873153e286a71531105de8 100644 (file)
@@ -27,17 +27,21 @@ use Encode ('encode', 'decode');
 
 ###PERL_LIB: use lib /botm/lib/bsta
 use botm_common (
+       'HTTP_STATUS',
        'read_header_env',
        'url_query_decode',
        'read_data_file',
        'join_path',
-       'merge_url'
+       'merge_url',
+       'open_encoded', 'stat_encoded',
+       'http_header_line', 'http_header_content_length', 'http_header_content_disposition'
 );
 use bsta_lib (
        'STATE',
        'merge_settings',
        'get_id', 'get_password',
-       'fail_attachment', 'fail_500', 'redirect'
+       'fail_method', 'fail_content_type', 'fail_attachment', 'fail_500',
+       'redirect'
 );
 
 ###PERL_PATH_SEPARATOR:     PATH_SEPARATOR     = /
@@ -88,7 +92,7 @@ if ($ENV{'REQUEST_METHOD'} =~ /^(HEAD|GET|POST)$/) {
        $method = $1;
 }
 else{
-       exit fail_method($ENV{'REQUEST_METHOD'}, 'GET, POST, HEAD');
+       exit fail_method($ENV{'REQUEST_METHOD'}, ['GET', 'POST', 'HEAD']);
 }
 
 %http = read_header_env(\%ENV);
@@ -105,8 +109,6 @@ if ($method eq 'POST') {
        }
 }
 
-# print "content-type: text/plain\n\n";
-
 $ID       = get_id(      \%cgi);
 $password = get_password(\%cgi);
 
@@ -144,19 +146,19 @@ else {
        );
        if ($try_onged) {
                $file_path = join_path(PATH_SEPARATOR(), WWW_PATH(), $file_name);
-               $r = open($fh, '<' , encode('locale_fs', $file_path));
+               $r = open_encoded($fh, '<' , $file_path);
                if ($r) {
                        close($r);
                        $file_path = merge_url(
                                {'path' => CGI_PATH()},
                                {'path' => $file_name}
                        );
-                       exit redirect ($method, $file_path, 303);
+                       exit redirect ($method, $file_path, HTTP_STATUS->{'see_other'});
                }
        }
        unless ($r) {
                $file_path = join_path(PATH_SEPARATOR(), DATA_PATH(), $file_name);
-               $r = open($fh,'<', encode('locale_fs', $file_path));
+               $r = open_encoded($fh,'<', $file_path);
                unless ($r) {
                        exit fail_attachment($method, $ID);
                }
@@ -165,12 +167,16 @@ else {
                close($fh);
                exit fail_500("Can't switch file to binary mode.");
        }
-       if (my @file_info = stat($file_path)) {
-               print 'Content-length: '.$file_info[7]."\n";
+       if (my @file_info = stat_encoded($file_path)) {
+               print http_header_content_length($file_info[7]);
        }
 }
-print 'Content-type: '.$file_data{'content-type'}."\n";
-print 'Content-disposition: attachment; filename="'.$file_name.'"'."\n";
+if ($file_data{'content-type'} ne '') {
+       print http_header_line('content-type', $file_data{'content-type'});
+}
+if ($file_name ne '') {
+       print http_header_content_disposition('inline', $file_name);
+}
 unless ($direct) {
        unless (binmode STDOUT) {
                close($fh);