mod_zip icon indicating copy to clipboard operation
mod_zip copied to clipboard

No Content-Length in headers via ngx_lua

Open qiaoba opened this issue 10 years ago • 0 comments

Hi, headers are different between nginx+php and ngx_lua when I'm trying to zip files by mod_zip. Is there anything wrong in my code? Is anybody know the reason why dosen't 'content-length' exist in response headers by ngx_lua ? @evanmiller

code by nginx + php

header('X-Accel-Chareset: utf-8');
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename=test.zip');
header('X-Archive-Files: zip');

$crc32 = "-";
$downloadPath1 = 'http://fileserver/file1';
$downloadPath2 = 'http://fileserver/file2';

$fileSize1 = 32704424;
$fileSize2 = 4849469;

$str1 = sprintf("%s %d %s %s\n", $crc32, $fileSize1, $downloadPath1, 'file1');
$str2 = sprintf("%s %d %s %s\n", $crc32, $fileSize2, $downloadPath2, 'file2');
echo $str1;
echo $str2;

http response headers:

HTTP/1.1 200 OK
Server: nginx/1.2.9
Date: Fri, 14 Nov 2014 03:24:05 GMT
Content-Type: application/zip
Content-Length: 37554209
Connection: keep-alive
X-Accel-Chareset: utf-8
Content-Disposition: attachment; filename=test.zip
X-Archive-Files: zip

code by ngx_lua

ngx.header['X-Accel-Chareset'] = 'utf-8'
ngx.header['Content-Type'] = 'application/zip'
ngx.header['Content-Disposition'] = 'attachment; filename=test.zip'
ngx.header['X-Archive-Files'] = 'zip'

local crc32 = '-' 
local downloadPath1 = 'http://fileserver/file1'
local downloadPath2 = 'http://fileserver/file2'
local fileSize1 = 32704424
local fileSize2 = 4849469

ngx.print(crc32 .. ' ' .. fileSize1 .. ' ' .. downloadPath1 .. ' ' .. 'file1' .. '\r\n')
ngx.print(crc32 .. ' ' .. fileSize2 .. ' ' .. downloadPath2 .. ' ' .. 'file2' .. '\r\n')

http response headers

HTTP/1.1 200 OK
Server: nginx/1.2.9
Date: Fri, 14 Nov 2014 03:25:51 GMT
Content-Type: application/zip
Transfer-Encoding: chunked
Connection: keep-alive
X-Accel-Chareset: utf-8
Content-Disposition: attachment; filename=test.zip
Content-Encoding: none
X-Archive-Files: zip

qiaoba avatar Nov 14 '14 04:11 qiaoba