Skip to content

Instantly share code, notes, and snippets.

@kernelp4nic
Created July 21, 2014 19:29
Show Gist options
  • Save kernelp4nic/3e06ff71de3f0e74cd42 to your computer and use it in GitHub Desktop.
Save kernelp4nic/3e06ff71de3f0e74cd42 to your computer and use it in GitHub Desktop.
luanode http/https connection (luanode http_test.lua secure)
local net = require "luanode.net"
local host = "userstream.twitter.com"
local secure = process.argv[1] == "secure"
if secure then
console.log("Using secure connection (HTTPS)")
local c = net.createConnection(443, host)
c:on("connect", function()
console.log("connected")
c:setSecure()
end)
c:on("secure", function()
c:write("GET / HTTP/1.1\r\nHost: "..host .. "\r\n\r\n")
end)
c:on("data", function(_, data)
console.log("got", data)
end)
else
console.log("Using unsecure connection (HTTP)")
local c = net.createConnection(80, host)
c:on("connect", function()
console.log("connected")
c:write("GET / HTTP/1.1\r\nHost: "..host .. "\r\n\r\n")
end)
c:on("data", function(_, data)
console.log("got", data)
end)
end
process:loop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment