smdb-web-server 2.0.4__tar.gz → 2.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {smdb_web_server-2.0.4/smdb_web_server.egg-info → smdb_web_server-2.1.0}/PKG-INFO +3 -1
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/README.md +2 -0
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/setup.cfg +1 -1
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/smdb_web_server/HTMLServer.py +4 -2
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/smdb_web_server/HTTPRequestHandler.py +16 -7
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0/smdb_web_server.egg-info}/PKG-INFO +3 -1
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/LICENSE +0 -0
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/pyproject.toml +0 -0
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/smdb_web_server/__init__.py +0 -0
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/smdb_web_server/data/Base.py +0 -0
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/smdb_web_server/data/Constants.py +0 -0
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/smdb_web_server/data/Protocol.py +0 -0
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/smdb_web_server/data/ResponseCode.py +0 -0
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/smdb_web_server/data/Timer.py +0 -0
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/smdb_web_server/data/UrlData.py +0 -0
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/smdb_web_server/data/__init__.py +0 -0
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/smdb_web_server/data/wrappers.py +0 -0
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/smdb_web_server/errors/CloseException.py +0 -0
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/smdb_web_server/errors/KnownError.py +0 -0
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/smdb_web_server/errors/RequestException.py +0 -0
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/smdb_web_server/errors/__init__.py +0 -0
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/smdb_web_server.egg-info/SOURCES.txt +0 -0
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/smdb_web_server.egg-info/dependency_links.txt +0 -0
- {smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/smdb_web_server.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: smdb_web_server
|
|
3
|
-
Version: 2.0
|
|
3
|
+
Version: 2.1.0
|
|
4
4
|
Summary: A really basic, not so safe web server.
|
|
5
5
|
Home-page: https://github.com/NightKey/smdb-server
|
|
6
6
|
Author: Janthó Dávid
|
|
@@ -36,6 +36,8 @@ from smdb_web_server import HTMLServer, UrlData
|
|
|
36
36
|
server = HTMLServer("127.0.0.1", 8080, title="Example server")
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
There is a possibility to send the exception messages (other than [KnownError](#knownerror)) by setting the `forward_exception_message` to true.
|
|
40
|
+
|
|
39
41
|
If the plaintext or JSON responses will use any specific encodings you can set the `response_charset` property when creating the HTMLServer. The default value is 'UTF-8'.
|
|
40
42
|
|
|
41
43
|
IP restrictions can be enforced by a function passed in to `address_filter`. For example, a local IP restriction could look like the following:
|
|
@@ -19,6 +19,8 @@ from smdb_web_server import HTMLServer, UrlData
|
|
|
19
19
|
server = HTMLServer("127.0.0.1", 8080, title="Example server")
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
+
There is a possibility to send the exception messages (other than [KnownError](#knownerror)) by setting the `forward_exception_message` to true.
|
|
23
|
+
|
|
22
24
|
If the plaintext or JSON responses will use any specific encodings you can set the `response_charset` property when creating the HTMLServer. The default value is 'UTF-8'.
|
|
23
25
|
|
|
24
26
|
IP restrictions can be enforced by a function passed in to `address_filter`. For example, a local IP restriction could look like the following:
|
|
@@ -21,7 +21,8 @@ class HTMLServer(Base):
|
|
|
21
21
|
title: str = "HTML Server",
|
|
22
22
|
disable_cache: bool = False,
|
|
23
23
|
response_charset: str = "UTF-8",
|
|
24
|
-
address_filter: Callable[[str], bool] = lambda _: True
|
|
24
|
+
address_filter: Callable[[str], bool] = lambda _: True,
|
|
25
|
+
forward_exception_message: bool = False,
|
|
25
26
|
):
|
|
26
27
|
super().__init__(
|
|
27
28
|
logger=logger,
|
|
@@ -36,6 +37,7 @@ class HTMLServer(Base):
|
|
|
36
37
|
self.disable_cache = disable_cache
|
|
37
38
|
self.address_filter = address_filter
|
|
38
39
|
self.server_task: Union[asyncio.Task, None] = None
|
|
40
|
+
self.forward_exception_message = forward_exception_message
|
|
39
41
|
|
|
40
42
|
@wrapped
|
|
41
43
|
def render_template_file(self, name: str, **kwargs) -> str:
|
|
@@ -103,7 +105,7 @@ class HTMLServer(Base):
|
|
|
103
105
|
writer.close()
|
|
104
106
|
return
|
|
105
107
|
self.try_log(message=f'Accepted connection from {addr[0]}:{addr[1]}')
|
|
106
|
-
handler = HTTPRequestHandler(reader=reader, writer=writer, page_title=self.pageTitle, cwd=self.cwd, charset=self.charset, logger=self.logger, disable_cache=self.disable_cache)
|
|
108
|
+
handler = HTTPRequestHandler(reader=reader, writer=writer, page_title=self.pageTitle, cwd=self.cwd, charset=self.charset, logger=self.logger, disable_cache=self.disable_cache, forward_exception_message=self.forward_exception_message)
|
|
107
109
|
await handler.handle_request()
|
|
108
110
|
|
|
109
111
|
@async_wrapped
|
|
@@ -25,7 +25,8 @@ class HTTPRequestHandler(Base):
|
|
|
25
25
|
logger: Union[Logger, None] = None,
|
|
26
26
|
disable_cache: bool = False,
|
|
27
27
|
source_address: str = "",
|
|
28
|
-
source_filter: Callable[[str], bool] = lambda _: True
|
|
28
|
+
source_filter: Callable[[str], bool] = lambda _: True,
|
|
29
|
+
forward_exception_message: bool = False,
|
|
29
30
|
) -> None:
|
|
30
31
|
super().__init__(
|
|
31
32
|
logger=logger,
|
|
@@ -42,6 +43,7 @@ class HTTPRequestHandler(Base):
|
|
|
42
43
|
self.disable_cache = disable_cache
|
|
43
44
|
self.source_address = source_address
|
|
44
45
|
self.source_filter = source_filter
|
|
46
|
+
self.forward_exception_message = forward_exception_message
|
|
45
47
|
|
|
46
48
|
@async_wrapped
|
|
47
49
|
async def handle_request(self):
|
|
@@ -78,7 +80,7 @@ class HTTPRequestHandler(Base):
|
|
|
78
80
|
await self.cleanup()
|
|
79
81
|
except Exception as ex:
|
|
80
82
|
self.try_log(message=f"Exception during handling request a request", exception=ex, level=LEVEL.ERROR)
|
|
81
|
-
html_file = HTTPRequestHandler.html_template.format(title=self.page_title, content=ex)
|
|
83
|
+
html_file = HTTPRequestHandler.html_template.format(title=self.page_title, content=ex) if self.forward_exception_message else ""
|
|
82
84
|
response_code = Constants.InternalServerError
|
|
83
85
|
self.send_message(response_code, html_file)
|
|
84
86
|
finally:
|
|
@@ -174,17 +176,18 @@ class HTTPRequestHandler(Base):
|
|
|
174
176
|
response_code = Constants.Ok
|
|
175
177
|
self.disable_cache = get_rules[self.path][1] or self.disable_cache
|
|
176
178
|
except KnownError as ke:
|
|
177
|
-
html_file = self.html_template.format(title=self.page_title, content=ke.response.name)
|
|
178
179
|
response_code = ke.response
|
|
179
180
|
self.try_log(message=f"Known Exception: {ke}", level=LEVEL.WARNING)
|
|
180
181
|
except CloseException:
|
|
181
182
|
await self.cleanup()
|
|
182
183
|
except RequestException as rex:
|
|
183
|
-
|
|
184
|
+
if self.forward_exception_message:
|
|
185
|
+
html_file = self.html_template.format(title=self.page_title, content=rex)
|
|
184
186
|
response_code = Constants.BadRequest
|
|
185
187
|
self.try_log(message=f"Request Exception: {rex}", level=LEVEL.WARNING)
|
|
186
188
|
except Exception as ex:
|
|
187
|
-
|
|
189
|
+
if self.forward_exception_message:
|
|
190
|
+
html_file = self.html_template.format(title=self.page_title, content=ex)
|
|
188
191
|
self.try_log(message=f"Exception during handling a GET request for {self.path}", exception=ex, level=LEVEL.ERROR)
|
|
189
192
|
finally:
|
|
190
193
|
if not self.close_event.is_set():
|
|
@@ -234,11 +237,14 @@ class HTTPRequestHandler(Base):
|
|
|
234
237
|
except CloseException:
|
|
235
238
|
await self.cleanup()
|
|
236
239
|
except RequestException as rex:
|
|
237
|
-
|
|
240
|
+
if self.forward_exception_message:
|
|
241
|
+
result = self.html_template.format(title=self.page_title, content=rex)
|
|
238
242
|
message_return = Constants.BadRequest
|
|
239
243
|
self.try_log(message=f"Request Exception: {rex}", level=LEVEL.WARNING)
|
|
240
244
|
except Exception as ex:
|
|
241
245
|
message_return = Constants.InternalServerError
|
|
246
|
+
if self.forward_exception_message:
|
|
247
|
+
result = self.html_template.format(title=self.page_title, content=ex)
|
|
242
248
|
self.try_log(message=f"Exception during handling a PUT request for {self.path}", exception=ex, level=LEVEL.ERROR)
|
|
243
249
|
finally:
|
|
244
250
|
if not self.close_event.is_set():
|
|
@@ -273,11 +279,14 @@ class HTTPRequestHandler(Base):
|
|
|
273
279
|
except CloseException:
|
|
274
280
|
await self.cleanup()
|
|
275
281
|
except RequestException as rex:
|
|
276
|
-
result = self.html_template.format(title=self.page_title, content=rex)
|
|
277
282
|
message_return = Constants.BadRequest
|
|
283
|
+
if self.forward_exception_message:
|
|
284
|
+
result = self.html_template.format(title=self.page_title, content=rex)
|
|
278
285
|
self.try_log(message=f"Request Exception: {rex}", level=LEVEL.WARNING)
|
|
279
286
|
except Exception as ex:
|
|
280
287
|
message_return = Constants.InternalServerError
|
|
288
|
+
if self.forward_exception_message:
|
|
289
|
+
result = self.html_template.format(title=self.page_title, content=ex)
|
|
281
290
|
self.try_log(message=f"Exception during handling a POST request for {self.path}", exception=ex, level=LEVEL.ERROR)
|
|
282
291
|
finally:
|
|
283
292
|
if not self.close_event.is_set():
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: smdb_web_server
|
|
3
|
-
Version: 2.0
|
|
3
|
+
Version: 2.1.0
|
|
4
4
|
Summary: A really basic, not so safe web server.
|
|
5
5
|
Home-page: https://github.com/NightKey/smdb-server
|
|
6
6
|
Author: Janthó Dávid
|
|
@@ -36,6 +36,8 @@ from smdb_web_server import HTMLServer, UrlData
|
|
|
36
36
|
server = HTMLServer("127.0.0.1", 8080, title="Example server")
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
There is a possibility to send the exception messages (other than [KnownError](#knownerror)) by setting the `forward_exception_message` to true.
|
|
40
|
+
|
|
39
41
|
If the plaintext or JSON responses will use any specific encodings you can set the `response_charset` property when creating the HTMLServer. The default value is 'UTF-8'.
|
|
40
42
|
|
|
41
43
|
IP restrictions can be enforced by a function passed in to `address_filter`. For example, a local IP restriction could look like the following:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{smdb_web_server-2.0.4 → smdb_web_server-2.1.0}/smdb_web_server.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|