Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
https: add https module
  • Loading branch information
Ryan Phillips committed Jun 23, 2012
1 parent 224f8ca commit f6c757e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
66 changes: 66 additions & 0 deletions lib/luvit/https.lua
@@ -0,0 +1,66 @@
--[[
Copyright 2012 The Luvit Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS-IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--]]
local fmt = require('string').format
local http = require('http')
local tls = require('tls')
local url = require('url')
function createConnection(...)
local args = {...}
local options = {}
local callback
if type(args[1]) == 'table' then
options = args[1]
elseif type(args[2]) == 'table' then
options = args[2]
options.port = args[1]
elseif type(args[3]) == 'table' then
options = args[3]
options.port = args[2]
options.host = args[1]
else
if type(args[1]) == 'number' then
options.port = args[1]
end
if type(args[2]) == 'string' then
options.host = args[2]
end
end
if type(args[#args]) == 'function' then
callback = args[#args]
end
return tls.connect(options, callback)
end
function request2(options, callback)
if type(options) == 'string' then
options = url.parse(options)
end
if options.protocol and options.protocol ~= 'https' then
error(fmt('Protocol %s not supported', options.protocol))
end
options.createConnection = createConnection
options.port = options.port or 443
return http.request2(options, callback)
end
local https = {}
https.request2 = request2
return https
1 change: 1 addition & 0 deletions luvit.gyp
Expand Up @@ -70,6 +70,7 @@
'lib/luvit/fiber.lua',
'lib/luvit/fs.lua',
'lib/luvit/http.lua',
'lib/luvit/https.lua',
'lib/luvit/json.lua',
'lib/luvit/luvit.lua',
'lib/luvit/mime.lua',
Expand Down
2 changes: 2 additions & 0 deletions src/luvit_exports.c
Expand Up @@ -11,6 +11,7 @@ extern const char *luaJIT_BC_dns[];
extern const char *luaJIT_BC_fiber[];
extern const char *luaJIT_BC_fs[];
extern const char *luaJIT_BC_http[];
extern const char *luaJIT_BC_https[];
extern const char *luaJIT_BC_json[];
extern const char *luaJIT_BC_luvit[];
extern const char *luaJIT_BC_mime[];
Expand Down Expand Up @@ -41,6 +42,7 @@ const void *luvit__suck_in_symbols(void)
(size_t)(const char *)luaJIT_BC_fiber +
(size_t)(const char *)luaJIT_BC_fs +
(size_t)(const char *)luaJIT_BC_http +
(size_t)(const char *)luaJIT_BC_https +
(size_t)(const char *)luaJIT_BC_json +
(size_t)(const char *)luaJIT_BC_luvit +
(size_t)(const char *)luaJIT_BC_mime +
Expand Down

0 comments on commit f6c757e

Please sign in to comment.