2

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)
SweetNGX
  • 153
  • 1
  • 9
  • Can you please provide us with the first byte of the message when sent without the set Content-Length? – Mooshua Dec 30 '20 at 03:16
  • 80 Byte: `[{"Y":"One","X":"1","Z":0},{"Y":"Two","X":"2","Z":0},{"Y":"Tree","X":"3","Z":0}]` If I don't add the "Content-Length" header, firefox says 81 bytes are transferred. But my content is 80 Bytes :S – SweetNGX Dec 30 '20 at 03:26

1 Answers1

2

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

SweetNGX
  • 153
  • 1
  • 9