我开始看PSGI,我知道应用程序的响应应该是三个元素的数组引用,[code,headers,body]:
#!/usr/bin/perl
my $app = sub {
my $env = shift;
return [
200,
[ 'Content-type', 'text/plain' ],
[ 'Hello world' ],
]
};
Run Code Online (Sandbox Code Playgroud)
问题是如何发送文件例如zip或pdf以便下载到浏览器.
只需设置正确的标题和正文.
my $app = sub {
my $env = shift;
open my $zip_fh, '<', '/path/to/zip/file' or die $!;
return [
200,
[ 'Content-type', 'application/zip' ], # Correct content-type
$zip_fh, # Body can be a filehandle
]
};
Run Code Online (Sandbox Code Playgroud)
您可能想尝试添加其他标头(特别是"内容处置").
归档时间: |
|
查看次数: |
594 次 |
最近记录: |