Skip to content

Commit d06f4f7

Browse files
committed
version 20260520.0: modernize codebase, fix protocol bugs, expand test suite
rocket3/__init__.py: - Drop Python 2 / Jython compatibility (IS_JYTHON, _read_request_line_jython, FileLikeSocket, has_ssl fallback, optparse). - Switch to super() calls, context-managed locks, OSError, callable(), and lazy %-args logging throughout. - Fix RESPONSE template to use CRLF (was bare LF, violating HTTP spec). - Fix inverted status-code check that incorrectly added Content-Length to 1xx/204/205/304 responses. - Fix typo: ssl context verify_model -> verify_mode. - Reorder SSL exception handlers so SSLCertVerificationError (subclass) is caught before SSLError. - Make stop() idempotent (RLock + _stopping flag) and install an explicit SIGINT handler so Ctrl-C shuts the server down cleanly. - ThreadPool.stop() now actually joins workers with a bounded deadline (was previously commented-out dead code, causing hangs). - Harden demo_app against path traversal via _safe_join; replace optparse with argparse. - Rename shadowed in threadpool section to . Build: - Makefile reworked around uv (uv build / uv tool run ruff) with check, format, test, build, publish targets; add uv.lock. Tests: - Rewrite test_http / test_https around pytest fixtures with ephemeral ports and a shared make_server / dual_server harness (tests/conftest.py). - Add coverage for keep-alive, HEAD, malformed request lines, CRLF header framing, and HTTP/HTTPS port-mismatch behavior. - Add tests/test_units.py for unit-level coverage.
1 parent 4154030 commit d06f4f7

9 files changed

Lines changed: 920 additions & 529 deletions

File tree

Makefile

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
.PHONY: venv test build deploy
2-
venv:
3-
python3 -m venv venv
4-
tests: venv
5-
venv/bin/pip install -U requests
6-
venv/bin/pip install -U pytest
7-
venv/bin/python -m pytest
8-
build:
9-
python3 -m pip install --upgrade build
10-
python3 -m pip install --upgrade twine
11-
python3 -m build
12-
deploy: build
13-
python3 -m twine upload dist/*
1+
.PHONY: uv check format test lock build publish
2+
3+
uv:
4+
which uv || curl -LsSf https://astral.sh/uv/install.sh | sh
5+
check: uv
6+
uv tool run ruff check
7+
format: uv
8+
uv tool run ruff format
9+
test: check
10+
uv run --with pytest --with requests -m pytest
11+
build: test
12+
rm -rf dist/* build/*
13+
uv build
14+
publish: build
15+
uv run --with twine -m twine upload dist/*

README.md

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,63 @@
11
# Rocket3
22

3-
Rocket3 is the multi-threaded web server used by web2py and py4web, stripped of all the Python2 logic and dependencies. It now only supports Python3 and can be used without web2py or py4web.
3+
Rocket3 is the multi-threaded WSGI web server used by web2py and py4web, stripped of all the Python 2 logic and dependencies. It supports Python 3.9+ and can be used without web2py or py4web.
44

5-
Rocket was originally developed by Massimo Di Pierro, then rewritten much better by Timoty Ferrell, and then has minor refactorings made by Massimo and other web2py contributors.
5+
Rocket was originally developed by Massimo Di Pierro, then rewritten much better by Timothy Farrell, and then has had refactorings made by Massimo and other web2py contributors.
66

7-
## Example
7+
## Installation
88

99
```
10+
pip install rocket3
11+
```
12+
13+
## Example
14+
15+
```python
1016
from rocket3 import Rocket3 as Rocket
1117

1218
def demo_app(environ, start_response):
13-
"""simple exmaple WSGI app"""
19+
"""simple example WSGI app"""
1420
start_response("200 OK", [("Content-Type", "text/html")])
15-
data = "<html><body><h1>Hello from Rocket Web Server</h1></body></html>"
16-
return [data]
21+
return [b"<html><body><h1>Hello from Rocket Web Server</h1></body></html>"]
22+
23+
24+
server = Rocket(("0.0.0.0", 8080), "wsgi", {"wsgi_app": demo_app})
25+
server.start()
26+
```
27+
28+
## HTTPS
1729

30+
Pass a 4-tuple `(host, port, key_file, cert_file)` to serve over TLS, or a 5-tuple `(host, port, key_file, cert_file, ca_cert_file)` to also request a client certificate:
1831

19-
server = Rocket(('0.0.0.0', 8080), "wsgi", {"wsgi_app": demo_app})
32+
```python
33+
server = Rocket(
34+
("0.0.0.0", 8443, "key.pem", "cert.pem"),
35+
"wsgi",
36+
{"wsgi_app": demo_app},
37+
)
2038
server.start()
2139
```
2240

41+
## Built-in demo
42+
43+
A trivial server that serves static files (or a hello page if no static folder is given) is bundled as `rocket3.demo`:
44+
45+
```
46+
python -c "from rocket3 import demo; demo()" -i 127.0.0.1 -p 8000 -s ./static
47+
```
48+
49+
## Development
50+
51+
The project uses [uv](https://docs.astral.sh/uv/) and [ruff](https://docs.astral.sh/ruff/). Common targets:
52+
53+
```
54+
make check # ruff check
55+
make format # ruff format
56+
make test # run the test suite
57+
make build # build sdist + wheel
58+
make publish # upload to PyPI
59+
```
60+
2361
## License
2462

2563
BSDv3

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[project]
22
name = "rocket3"
3-
version = "20241225.1"
3+
version = "20260520.0"
44
authors = [{ name="Massimo Di Pierro", email="massimo.dipierro@gmail.com" },]
55
description = "A multi-threaded WSGI compiliant and secure web server"
66
readme = "README.md"
7-
requires-python = ">=3.7"
7+
requires-python = ">=3.9"
88
classifiers = [
99
"Programming Language :: Python :: 3",
1010
"License :: OSI Approved :: BSD License",

0 commit comments

Comments
 (0)