lua-users home
lua-l archive

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


Here are some outputs:

    > h=require("socket.http")
    > print(h.request("http://192.168.0.197:2869/dms_descr.xml"))
    nil     invalid chunk size
    > hdrs = {["USER-AGENT"]="uPNP/1.0"}
    > print(h.request{url="" href="http://192.168.0.197:2869/dms_descr.xml]">http://192.168.0.197:2869/dms_descr.xml]],sink=ltn12.sink.file(io.stdout),headers = hdrs})
    nil     invalid chunk size

So that gives the same error for that file. For the other file:

    > print(h.request("http://192.168.0.197:49153/nasdevice.xml"))
    nil     closed
    > hdrs = {["USER-AGENT"]="uPNP/1.0"}
    > print(h.request{url="" href="http://192.168.0.197:49153/nasdevice.xml]">http://192.168.0.197:49153/nasdevice.xml]],sink=ltn12.sink.file(io.stdout),headers = hdrs})
    <?xml version="1.0"?>............
    ...............................
    </root>
    nil     closed

So the header USER-AGENT is required to get the xml file.

I added print after every :receive() statement in http.lua to print (7 in all) what was received and here is the output:

    > h=require("socket.http")
    > hdrs = {["USER-AGENT"]="uPNP/1.0"}
    > print(h.request("http://192.168.0.197:2869/dms_descr.xml"))
    HTTP/
    HTTP/1.1 200 OK
    Content-Type: text/xml; charset=utf-8   nil
    Transfer-Encoding: chunked      nil
    Last-Modified: Mon, 28 Apr 2014 13:21:44 GMT    nil
    Date: Thu, 17 Jul 2014 06:48:28 GMT     nil
    Server: NFLC/2.3 UPnP/1.0 DLNADOC/1.50  nil
    Content-Length: 3422    nil
    Location: http://192.168.0.197:2869     nil
            nil
    <?xml version="1.0" encoding="utf-8"?><root xmlns="urn:schemas-upnp-org:device-1-0" xmlns:dlna="urn:schemas-dlna-org:device-1-0" xmlns:pnpx="http://schemas.microsoft.com/windows/pnpx/2005/11" xmlns:df="http://schemas.microsoft.com/windows/2008/09/devicefoundation" xmlns:microsoft="urn:schemas-microsoft-com:WMPNSS-1-0">
            nil
    nil     invalid chunk size





On Thu, Jul 17, 2014 at 9:10 AM, Milind Gupta <milind.gupta@gmail.com> wrote:
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%5D" target="_blank">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:


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:


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