lua-users home
lua-l archive

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


Sorry the last http.request call had a typo. It is supposed to be: 

print(h.request{url="" href="http://192.168.0.197:49154/nasdevice.xml]">http://192.168.0.197:49154/nasdevice.xml]],sink=ltn12.sink.file(io.stdout),headers=hdrs})




On Tue, Jul 15, 2014 at 2:01 PM, Milind Gupta <milind.gupta@gmail.com> wrote:
Hi,
     I have a NAS device Western Digital My Book live which is UPnP enabled. Its UPnP service description XML Is at an address like:

http://192.168.0.197:2869/dms_descr.xml

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
            else
                -- if it was, read trailers into headers table
                headers, err = receiveheaders(sock, headers)
                if not headers then return nil, err end
            end
        end
    })
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:

http://192.168.0.197:49154/nasdevice.xml

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 = {
   ["USER-AGENT"]="uPNP/1.0",
   ["CONTENT-TYPE"] = [[text/xml; charset="utf-8"]]
}
print(h.request{[[http://192.168.0.197:49154/nasdevice.xml]],sink=ltn12.sink.file(io.stdout),headers=hdrs})

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

Thanks,
Milind