diff --git a/lualib-src/ltls.c b/lualib-src/ltls.c index efac8bbc..3fd4a0a4 100644 --- a/lualib-src/ltls.c +++ b/lualib-src/ltls.c @@ -267,6 +267,15 @@ _ltls_context_write(lua_State* L) { return 1; } +static int +_lset_ext_host_name(lua_State* L) { + struct tls_context* tls_p = _check_context(L, 1); + size_t slen = 0; + char* host = (char*)lua_tolstring(L, 2, &slen); + int ret = SSL_set_tlsext_host_name(tls_p->ssl, host); + lua_pushinteger(L, ret); + return 1; +} static int _lctx_gc(lua_State* L) { @@ -378,6 +387,7 @@ lnew_tls(lua_State* L) { {"handshake", _ltls_context_handshake}, {"read", _ltls_context_read}, {"write", _ltls_context_write}, + {"set_ext_host_name", _lset_ext_host_name}, {NULL, NULL}, }; luaL_newlib(L, l); diff --git a/lualib/http/httpc.lua b/lualib/http/httpc.lua index 54595648..e9cb775c 100644 --- a/lualib/http/httpc.lua +++ b/lualib/http/httpc.lua @@ -95,7 +95,7 @@ local function connect(host, timeout) end) end if interface.init then - interface.init() + interface.init((header and header.Host) or host) end return fd, interface, host end diff --git a/lualib/http/tlshelper.lua b/lualib/http/tlshelper.lua index 359c423a..a81405ca 100644 --- a/lualib/http/tlshelper.lua +++ b/lualib/http/tlshelper.lua @@ -6,7 +6,8 @@ local tlshelper = {} function tlshelper.init_requestfunc(fd, tls_ctx) local readfunc = socket.readfunc(fd) local writefunc = socket.writefunc(fd) - return function () + return function (hostname) + tls_ctx:set_ext_host_name(hostname) local ds1 = tls_ctx:handshake() writefunc(ds1) while not tls_ctx:finished() do