Skip to content

Commit

Permalink
V0.10.0 (#76)
Browse files Browse the repository at this point in the history
* Fix mimetype for compressed files

* Escape meta component in jetforce logs

* Bumping version

* Fix test
  • Loading branch information
michael-lazar authored Oct 16, 2023
1 parent e08aa4b commit 6ea8198
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 5 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Unreleased

### v0.10.0 (2023-10-15)

#### Features

- Added support for the HAProxy "PROXY" protocol via the
Expand All @@ -11,6 +13,15 @@
- Added support for running a server without TLS via the `--no-tls`
flag.

#### Fixes

- Fixed incorrect mimetype/charset in responses for compressed files
ending in ``.gz`` and ``.bz2``.
- The "meta" component in jetforce's request logs is now surrounded
by double quotation marks, to allow for unambiguous log parsing.
Any quotation marks inside of the meta string itself will be escaped
with a single backslash, (e.g. ``\"``).

#### Changes

- Updated required twisted version to >= 21.7.0.
Expand Down
2 changes: 1 addition & 1 deletion jetforce/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.9.1"
__version__ = "0.10.0"
13 changes: 12 additions & 1 deletion jetforce/app/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,18 @@ def __init__(
if os.path.isfile(fn):
self.mimetypes.read(fn)

# This is a valid method but the type stubs are incorrect
# The mimetype library will try to split out the compression algorithm
# from the underlying filetype, e.g. "./file.mbox.gz" will be parsed as
# mimetype="application/mbox",encoding="gzip". This is useful for
# HTTP because you can then set the encoding using the Content-Encoding
# header. However, for gemini there is no way to specify the encoding
# of a response, so we need to disable this behavior and stick to
# straight mimetypes for compressed files.
self.mimetypes.encodings_map = {}
self.mimetypes.add_type("application/gzip", ".gz") # type: ignore
self.mimetypes.add_type("application/x-bzip2", ".bz2") # type: ignore

# Add some non-standard mimetypes
self.mimetypes.add_type("text/gemini", ".gmi") # type: ignore
self.mimetypes.add_type("text/gemini", ".gemini") # type: ignore

Expand Down
4 changes: 2 additions & 2 deletions jetforce/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,12 @@ def log_request(self) -> None:
Log a gemini request using a format derived from the Common Log Format.
"""
try:
message = '{} [{}] "{}" {} {} {}'.format(
message = '{} [{}] "{}" {} "{}" {}'.format(
self.client_addr.host,
time.strftime(self.TIMESTAMP_FORMAT, self.connected_timestamp),
self.url,
self.status,
self.meta,
self.meta.replace('"', '\\"'),
self.response_size,
)
except AttributeError:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def long_description() -> str:

setuptools.setup(
name="Jetforce",
version="0.9.1",
version="0.10.0",
url="https://github.com/michael-lazar/jetforce",
license="Other/Proprietary License",
author="Michael Lazar",
Expand Down
Binary file added tests/data/files/test.txt.gz
Binary file not shown.
4 changes: 4 additions & 0 deletions tests/test_jetforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ def test_file_trailing_slash(self):
resp = self.request("gemini://localhost/files/test.txt/\r\n")
assert resp == "20 text/plain\r\nthis is a file\n"

def test_file_gzip_mimetype(self):
resp = self.request("gemini://localhost/files/test.txt.gz\r\n")
assert resp.startswith("20 application/gzip\r\n")

def test_non_utf8(self):
resp = self.request("gemini://localhost/%AE\r\n")
assert resp == "51 Not Found\r\n"
Expand Down

0 comments on commit 6ea8198

Please sign in to comment.