Luasocket bug with Lua 5.4.3
Ref: https://github.com/diegonehab/luasocket/issues/331
Short Description
HTTP calls do not work with Luasocket 5.4.3 and luasocket.
System Info
Lua: 5.4.3 Luasocket: LuaSocket 3.0-rc1 Distro Archlinux
Test code:
Requires lua-socket
and lua-sec
to be installed.
If testing using lua5.3, then lua53-socket
lua53-sec
need to be installed.
local http = require "socket.http"
print("---")
print("Testing https")
print(http.request("https://ffl.shoeb.pw"))
print("---")
print("Testing http")
print(http.request("http://ffl.shoeb.pw"))
print("---")
print("End http")
Expected output:
$ lua5.3 t2.lua
---
Testing https
Welcome to ffl.shoeb.pw. We shall be serving you soon!!! 200 table: 0x55a7c9e0f4d0 HTTP/1.1 200 OK
---
Testing http
Welcome to ffl.shoeb.pw. We shall be serving you soon!!! 200 table: 0x55a7c9e06510 HTTP/1.1 200 OK
---
End http
Observed output:
$ lua t2.lua
---
Testing https
Welcome to ffl.shoeb.pw. We shall be serving you soon!!! 200 table: 0x5639643d1800 HTTP/1.1 200 OK
---
Testing http
lua: /usr/share/lua/5.4/socket/http.lua:54: bad argument #1 to 'receive' (string expected, got light userdata)
stack traceback:
[C]: in function 'socket.http.request'
t2.lua:12: in main chunk
[C]: in ?
Explanation
HTTP call does not work. Diving into the source code to see what might be the cause yields the line:
50 local function receiveheaders(sock, headers)
51 local line, name, value, err
52 headers = headers or {}
53 -- get first line
54 line, err = sock:receive()
55 if err then return nil, err end
56 -- headers go until a blank line is found
57 while line ~= "" do
As you can see in the above code block, line 54 does not pass any arguments, so the argument the is passed will be self
because of the :
used in the function call.
I can confirm that this was working before my recent update to lua 5.4.3 So, mostly the recent update is what broke it as luasocket has not been updated for quite some time now.