Skip to content

Commit a4a23a9

Browse files
committed
Add easy mode (no SSL)
1 parent 2492aeb commit a4a23a9

5 files changed

Lines changed: 62 additions & 27 deletions

File tree

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
## [1.0.2] - 2022-02-01
10+
### Added
11+
- Easy mode (no SSL)
12+
913
## [1.0.0] - 2022-02-01
1014
The first version has been implemented

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ git clone https://github.com/a1div0/https.git
2525
```
2626
* install the `https` module using `tarantoolctl`:
2727
```shell
28-
tarantoolctl rocks install https://raw.githubusercontent.com/a1div0/https/main/https-1.0.0-1.rockspec
28+
tarantoolctl rocks install https://raw.githubusercontent.com/a1div0/https/main/https-1.0.2-1.rockspec
2929
```
3030

3131
## API
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package = 'https'
2-
version = '1.0.0-1'
2+
version = '1.0.2-1'
33
source = {
44
url = 'git+https://github.com/a1div0/https.git';
55
branch = 'main';
6-
tag = '1.0.0'
6+
tag = '1.0.2'
77
}
88
description = {
99
summary = "Lua module HTTPS-server for Tarantool";

https/server.lua

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,24 @@ local function ssl_listen(host, port, options)
5050
end
5151

5252
local function start_ssl(self)
53-
self.server = http_server_lib.new(self.options.host, self.options.port443)
54-
self.server.cert_full_name = self.cert_full_name
53+
if (self.ssl_enable) then
54+
self.redirect = https_redirect_lib.new()
55+
self.redirect:start(self.options.host, self.options.port80)
56+
57+
self.server = http_server_lib.new(self.options.host, self.options.port443)
58+
self.server.tcp_server_f = ssl_listen
59+
self.server.cert_full_name = self.cert_full_name
60+
61+
self.ssl_active = true
62+
else
63+
self.server = http_server_lib.new(self.options.host, self.options.port80)
64+
end
5565

5666
for _, tuple in ipairs(self.route_table) do
5767
self.server:route(tuple.options, tuple.proc)
5868
end
5969

60-
self.server.tcp_server_f = ssl_listen
6170
self.server:start()
62-
self.redirect = https_redirect_lib.new()
63-
self.redirect:start(self.options.host, self.options.port80)
64-
self.ssl_active = true
6571
end
6672

6773
local function stop_ssl(self)
@@ -89,16 +95,19 @@ local function setup_challenge_proc(self)
8995
end
9096

9197
local function start(self)
92-
update_valid_to(self)
9398

94-
if self.cert_need_reissue then
95-
self.server = http_server_lib.new(self.options.host, self.options.port80)
96-
self.server:start()
97-
local proc = setup_challenge_proc(self)
98-
local acme_client = acme_lib.new(self.options, proc)
99-
acme_client:getCert()
100-
self.server:stop()
99+
if self.ssl_enable then
101100
update_valid_to(self)
101+
102+
if self.cert_need_reissue then
103+
self.server = http_server_lib.new(self.options.host, self.options.port80)
104+
self.server:start()
105+
local proc = setup_challenge_proc(self)
106+
local acme_client = acme_lib.new(self.options, proc)
107+
acme_client:getCert()
108+
self.server:stop()
109+
update_valid_to(self)
110+
end
102111
end
103112

104113
start_ssl(self)
@@ -130,6 +139,7 @@ local exports = {
130139
start = start,
131140
stop = stop,
132141
schedule = schedule,
142+
ssl_enable = options.ssl ~= false
133143
}
134144

135145
self.options.internalIP4 = options.host or options.internalIP4

test/server.test.lua

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,47 @@ local acme_lib = require("acme-client")
66
local test = tap.test('https.redirect tests')
77

88
local function test_main(test)
9-
test:plan(10)
9+
10+
test:plan(12)
11+
12+
local function echo_proc(request)
13+
local body = request:read()
14+
local response = request:render{ text = body }
15+
response.headers['x-test-header'] = request.method..' '..request.path;
16+
response.status = 200
17+
return response
18+
end
1019

1120
local options = {
12-
host = '0.0.0.0',
13-
port80 = 80,
21+
host = '127.0.0.1',
22+
port80 = 8080,
1423
port443 = 443,
1524
dns_name = 'vpoint.me',
1625
cert_path = '/srv/sftp/sftp-user/https/test/cert/',
1726
cert_name = 'ssl-test.pem',
27+
ssl = false,
1828
}
1929
local cert_full_name = options.cert_path..options.cert_name
2030
local echo_path = '/echo'
2131
local echo_url = ''
32+
local server = nil
33+
34+
if options.port80 == 80 then
35+
echo_url = 'http://'..options.host..echo_path
36+
else
37+
echo_url = string.format('http://%s:%d%s', options.host, options.port80, echo_path)
38+
end
39+
40+
server = https_lib.new(options)
41+
server:route({ path = echo_path }, echo_proc)
42+
server:start()
43+
44+
local r = http_client.post(echo_url, 'TEST0', {timeout=3})
45+
test:is(r.status, 200, 'Check easy mode (no SSL) - status 200')
46+
test:is(r.body, 'TEST0', 'Check easy mode (no SSL) - body echo')
47+
48+
server:stop()
49+
2250
if options.port443 == 443 then
2351
echo_url = 'https://'..options.dns_name..echo_path
2452
else
@@ -29,13 +57,6 @@ local function test_main(test)
2957
local server = https_lib.new(options)
3058
test:isnt(server, nil, 'HTTPS-server create without cert-file')
3159

32-
local function echo_proc(request)
33-
local response = request:render{ text = request.body }
34-
response.headers['x-test-header'] = request.method..' '..request.path;
35-
response.status = 200
36-
return response
37-
end
38-
3960
server:route({ path = echo_path }, echo_proc)
4061
server:start()
4162

0 commit comments

Comments
 (0)