Adding headers to ssl/https GET request

I found this strang behavior with ssl/https. Not sure what to make of it.

This works:

os.execute("curl -H 'HeaderName:HeaderValue' https://192.168.0.1")

… and the header added is passed with the request as expected.

This should do the exact same thing (right?):

local socket = require("socket")
local ltn12 = require('ltn12')
local https = require("ssl.https")

https.METHOD = "GET"
https.headers =
   {
    ["HeaderName"] = "HeaderValue",
   }
local  result, status = https.request("https://192.168.0.1")

… except that it doesn’t. For some reason the header is not added to the GET request and I don’t understand why.

I could just go with first of the above, but now I’m getting subborn :slight_smile:

Am I doing something wrong in the 2nd. Lua code example?

Please notice that this is a ssl/https request.

I’ve never seen LuaSocket code that sets headers in the class object like that. I’ve always included the headers as part of the request function itself, an seen here on the Luasocket reference: LuaSocket: HTTP support

Hi jasperhb,

Take a look here : http://forum.micasaverde.com/index.php?topic=13081.0. Maybe this will help.

Best Regards,

  • Andrei -