我们在send_protobuf中遇到了ngx["content-length"]值的问题,服务器端send函数的代码如下:
function send_protobuf(ngx, content)
ngx.header["Content-Type"] = "application/octet-stream"
ngx.header["Content-Length"] = string.len(content)
ngx.header["Server"] = "DSP"
ngx.say(content)
ngx.exit(ngx.HTTP_OK)
end
其中content是经过序列化的二进制流文件,我们用一个请求模拟器连续请求时会阻塞,但是我们将ngx["content-length"]=string.len(content)+1.,并在解析服务器返回信息时我们用python代码解析http响应,并舍弃最后一位时,即recv_response(data[:-1]) (注:这是python代码)能正确请求和解析返回数据.
我们的nginx版本为:
nginx version: nginx/1.4.7
lua版本为 Lua 5.1.4
序列化用的是google的protobuf.