SweetNGX
SweetNGX

Reputation: 163

NGINX LUA Content-Length +1 Byte Lost

I am having an interesting bug and method issue
Lua mentions that the js_content variable has a length of 80 bytes.
But when I don't use the "Content-Length" header, firefox mentions that 81 bytes of data are transferred.
I don't know where the +1 byte excess comes from I will be glad if you can help, an application I wrote with VBNet gives an error when I noticed that the "Content-Length" header is 80 bytes while parsing json data from my remote server, but it works fine when I add +1.

local ref_array = {1, 2, 3}

local sArray = {}
sArray["1"] = "One"
sArray["2"] = "Two"
sArray["3"] = "Tree"

local ctable = {}

for index, data in ipairs(ref_array) do

    if sArray[tostring(data)] ~= nil then
        local cinfo = {}
        cinfo["X"] = tostring(data)
        cinfo["Y"] = sArray[tostring(data)]
        cinfo["Z"] = 0
        table.insert(ctable, cinfo)
    end 
end     

local js_content = cjson.encode(ctable)

ngx.header['Content-Type'] = 'application/json'
ngx.header['Content-Length'] = #js_content -- 80 byte

ngx.say(js_content)

ngx.exit(200)

Upvotes: 2

Views: 731

Answers (1)

SweetNGX
SweetNGX

Reputation: 163

0a

I guess the problem is the Line Feed Character character at the end.

ngx.say always adds linefeed
ngx.print is just output

problem solved

Linefeed Character

Upvotes: 2

Related Questions