]> bicyclesonthemoon.info Git - ott/bsta/blobdiff - attach.1.pl
improve HTTP headers; can't post with GET request
[ott/bsta] / attach.1.pl
index f2a124a0ca12ce92434d4d918f2e63630ea7d912..151dddcf5dcd8104a3873153e286a71531105de8 100644 (file)
@@ -27,18 +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',
-       'open_encoded', 'stat_encoded'
+       '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     = /
@@ -89,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);
@@ -150,7 +153,7 @@ else {
                                {'path' => CGI_PATH()},
                                {'path' => $file_name}
                        );
-                       exit redirect ($method, $file_path, 303);
+                       exit redirect ($method, $file_path, HTTP_STATUS->{'see_other'});
                }
        }
        unless ($r) {
@@ -165,14 +168,14 @@ else {
                exit fail_500("Can't switch file to binary mode.");
        }
        if (my @file_info = stat_encoded($file_path)) {
-               print 'Content-length: '.$file_info[7]."\n";
+               print http_header_content_length($file_info[7]);
        }
 }
 if ($file_data{'content-type'} ne '') {
-       print 'Content-type: '.$file_data{'content-type'}."\n";
+       print http_header_line('content-type', $file_data{'content-type'});
 }
 if ($file_name ne '') {
-       print 'Content-disposition: inline; filename="'.$file_name.'"'."\n";
+       print http_header_content_disposition('inline', $file_name);
 }
 unless ($direct) {
        unless (binmode STDOUT) {