lua-users home
lua-l archive

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


Hi,

>   I have a little problem here. I am trying to download the following
>   file:
>
>   http://bessems.biz/girder/expgr.php?dwn=5
>
>   To do this I am using the following code:
>
> http = require("socket.http")
> print(http.request( { url="http://bessems.biz/girder/expgr.php?dwn=5"; }))
>
>   The library is LuaSocket 2.0 beta 3 on lua 5.0.2. The error that I
>   get is:
>
> socket/url.lua:128: bad argument #1 to `gsub' (string expected, got table)
>
>   Now if I remove the question mark the library doesn't complain
>   (of course the download fails but that is besides the point). How
>   should this work?

This is an unlucky combination of bad server, a
not-as-robust-as-I-believed client *and* wrong use. :)

Let's deal with each of them in turn:

1) Your server is sending a 302 Redirect but is providing a blank
Location header... It SHOULD not do that, and I had never seen it
before, so I was not protecting against it. This my be your PHP script's
fault. Are you requesting it to redirect and did you forget to set the
appropriate Location?

2) This caused my URL parsing code to fail, and it should instead have
reported the real cause of the problem. My bad...

3) Once these two problems are sorted, it still won't work. And this is
because of wrong use.

If you are not providing an LTN12 sink for the body of the reply, you
shouldn't be using the fancy version of the request function. Call

    print(http.request"http://bessems.biz/girder/expgr.php?dwn=5";)

instead. Notice the lack of request table. Use the string directly.

Regards and thanks for the report,
Diego.