@@ -7,20 +7,13 @@ import .status
7
7
8
8
import socket as so
9
9
import iters
10
- import ssl
11
10
12
11
/**
13
12
* HTTP server
14
13
* @printable
15
14
*/
16
15
class HttpServer {
17
16
18
- /**
19
- * A boolean value indicating if the server should/will be TLS/SSL secured or not.
20
- * @default false
21
- */
22
- var is_secure = false
23
-
24
17
/**
25
18
* The host address to which this server will be bound
26
19
* @default socket.IP_LOCAL (127.0.0.1)
@@ -62,20 +55,6 @@ class HttpServer {
62
55
*/
63
56
var write_timeout = 2000
64
57
65
- /**
66
- * The SSL/TLS ceritificate file that will be used be used by a secured server for
67
- * serving requests.
68
- * @note do not set a value to it directly. Use `load_certs()` instead.
69
- */
70
- var cert_file
71
-
72
- /**
73
- * The SSL/TLS private key file that will be used be used by a secured server for
74
- * serving requests.
75
- * @note do not set a value to it directly. Use `load_certs()` instead.
76
- */
77
- var private_key_file
78
-
79
58
/**
80
59
* This value controls whether the client certificate should be verified
81
60
* or not.
@@ -96,10 +75,10 @@ class HttpServer {
96
75
var _error_listeners = []
97
76
98
77
/**
99
- * HttpServer(port: int [, host: string [, is_secure: bool] ])
78
+ * HttpServer(port: int [, host: string])
100
79
* @constructor
101
80
*/
102
- HttpServer(port, host, is_secure ) {
81
+ HttpServer(port, host) {
103
82
104
83
if !is_int(port) or port <= 0
105
84
die HttpException('invalid port number')
@@ -109,39 +88,7 @@ class HttpServer {
109
88
die HttpException('invalid host')
110
89
else if host != nil self.host = host
111
90
112
- if is_secure != nil and !is_bool(is_secure)
113
- die Exception('is_secure must be boolean')
114
- if !is_secure is_secure = false
115
-
116
- self.socket = !is_secure ? so.Socket() : ssl.TLSSocket()
117
- # self.socket = so.Socket()
118
- self.is_secure = is_secure
119
- }
120
-
121
- /**
122
- * load_certs(cert_file: string | file [, private_key_file: string | file])
123
- *
124
- * loads the given SSL/TLS certificate pairs for the given SSL/TLS context.
125
- * @note certificates can only be loaded for secure servers.
126
- * @return bool
127
- */
128
- load_certs(cert_file, private_key_file) {
129
- if !self.is_secure
130
- die HttpException('certificates can only be loaded for secure servers')
131
-
132
- if !private_key_file private_key_file = cert_file
133
-
134
- self.socket.get_context().set_verify(self.verify_certs ? ssl.SSL_VERIFY_PEER : ssl.SSL_VERIFY_NONE)
135
-
136
- if self.socket.get_context().load_certs(cert_file, private_key_file) {
137
- self.cert_file = cert_file
138
- self.private_key_file = private_key_file
139
-
140
- return self.socket.get_context().set_ciphers(self._ciphers)
141
- } else {
142
- # die Exception('could not load certificate(s)')
143
- return false
144
- }
91
+ self.socket = so.Socket()
145
92
}
146
93
147
94
/**
@@ -153,8 +100,6 @@ class HttpServer {
153
100
self._is_listening = false
154
101
if !self.socket.is_closed
155
102
self.socket.close()
156
- if self.is_secure
157
- self.socket.get_context().free() # close the TLS socket context.
158
103
}
159
104
160
105
/**
@@ -291,13 +236,6 @@ class HttpServer {
291
236
* connection from HTTP clients.
292
237
*/
293
238
listen() {
294
- if self.is_secure {
295
- if !self.cert_file
296
- die HttpException('no certificate loaded for secure server')
297
- if !self.private_key_file
298
- die HttpException('no private key loaded for secure server')
299
- }
300
-
301
239
if !self.socket.is_listening {
302
240
self.socket.set_option(so.SO_REUSEADDR, is_bool(self.resuse_address) ? self.resuse_address : true)
303
241
self.socket.bind(self.port, self.host)
0 commit comments