/
deliver.coretag
82 lines (76 loc) · 2.03 KB
/
deliver.coretag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Copyright 2002-2005 Interchange Development Group (http://www.icdevgroup.org/)
# Licensed under the GNU GPL v2. See file LICENSE for details.
# $Id: deliver.coretag,v 1.7 2005-11-08 18:14:35 jon Exp $
UserTag deliver Order type
UserTag deliver HasEndTag
UserTag deliver addAttr
UserTag deliver Version $Revision: 1.7 $
UserTag deliver Routine <<EOR
sub {
my ($type, $opt, $body) = @_;
my $out;
use vars qw/$Tag/;
$Tag ||= new Vend::Tags;
if($opt->{file}) {
$type ||= Vend::Util::mime_type($opt->{file});
return undef unless -f $opt->{file};
my $tmp = readfile($opt->{file});
$out = \$tmp;
}
elsif(ref $body) {
$out = $body;
}
elsif(length $body) {
$out = \$body;
}
## This is a bounce, returns
if($opt->{location}) {
$type and $Tag->tag( {
op => 'header',
name => 'Content-Type',
content => $type,
} );
$Tag->tag( { op => 'header',
name => 'Status',
content => $opt->{status} || '302 moved',
} );
$Tag->tag( { op => 'header',
name => 'Location',
content => $opt->{location},
} );
if(! $body) {
$body = qq{Redirecting to <A href="%s">%s</a>.};
$body = errmsg($body, $opt->{location}, $opt->{location});
}
::response($body);
$Vend::Sent = 1;
return 1;
}
$type ||= 'application/octet-stream';
$Tag->tag( { op => 'header', name => 'Status', content => $opt->{status} } )
if $opt->{status};
$Tag->tag( { op => 'header', name => 'Content-Type', content => $type } );
if($opt->{get_encrypted}) {
$opt->{get_encrypted} = 1 unless $opt->{get_encrypted} =~ /^\d+$/;
my $idx = $opt->{get_encrypted};
while ($idx--) {
$$out =~ s/.*?(---+BEGIN PGP MESSAGE--+)/$1/s;
}
$$out =~ s/(---+END PGP MESSAGE---+).*/$1\n/s;
}
if($opt->{extra_headers}) {
my @lines = grep /\S/, split /[\r\n]+/, $opt->{extra_headers};
for(@lines) {
my ($header, $val) = split /:/, $_;
$Tag->tag( { op => 'header',
name => $header,
content => $val,
} );
}
}
$::Pragma->{download} = 1;
::response($out);
$Vend::Sent = 1;
return 1;
}
EOR