lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

     I have a NAS device Western Digital My Book live which is UPnP enabled. Its UPnP service description XML Is at an address like:

When I try to get that file using the http module it gives me the error: invalid chunk size

- The file can be viewed easily on the same computer using a web browser
- The python url library is able to retrieve it as well

When I print what it received before that error message it is the 1st line of the XML file. The function generating the error is this in http.lua:

socket.sourcet["http-chunked"] = function(sock, headers)
    return base.setmetatable({
        getfd = function() return sock:getfd() end,
        dirty = function() return sock:dirty() end
    }, {
        __call = function()
            -- get chunk size, skip extention
            local line, err = sock:receive()
            if err then return nil, err end
            local size = base.tonumber(string.gsub(line, ";.*", ""), 16)
            if not size then return nil, "invalid chunk size" end
            -- was it the last chunk?
            if size > 0 then
                -- if not, get chunk and skip terminating CRLF
                local chunk, err, part = sock:receive(size)
                if chunk then sock:receive() end
                return chunk, err
                -- if it was, read trailers into headers table
                headers, err = receiveheaders(sock, headers)
                if not headers then return nil, err end
If I print line just before the tonumber conversion then the 1st line of the xml is printed out but from the code it seems it was expecting a chunk size number.

For the same device I am able to retrieve another UPnP XML description file without any problem which resides on the address:

This does not give the invalid chunk size error.

Both files are easily viewable from the web browser on the same computer.

The command I use to retrieve the files are:

h = require("socket.http")
hdrs = {
   ["CONTENT-TYPE"] = [[text/xml; charset="utf-8"]]

Is this server also not complying with the standard somehow? What would be the correct way to retrieve the xml file?