Skip to content

Commit

Permalink
Add favicon support
Browse files Browse the repository at this point in the history
  • Loading branch information
zwimer committed Oct 14, 2024
1 parent cede472 commit 512ecea
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion rpipe/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__: str = "9.0.1" # Must be "<major>.<minor>.<patch>", all numbers
__version__: str = "9.0.2" # Must be "<major>.<minor>.<patch>", all numbers
15 changes: 12 additions & 3 deletions rpipe/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pathlib import Path
import atexit

from flask import Response, Flask, request
from flask import Response, Flask, send_file, request
import waitress

from ..shared import restrict_umask, log, __version__
Expand Down Expand Up @@ -42,6 +42,7 @@ class ServerConfig:
debug: bool
state_file: Path | None
key_files: list[Path]
favicon: Path | None


#
Expand All @@ -50,10 +51,10 @@ class ServerConfig:


@app.errorhandler(404)
def page_not_found(_) -> Response:
def _page_not_found(_, *, quiet=False) -> Response:
lg = getLogger(_LOG)
lg.warning("404: Request from %s for %s", request.host_url, request.url)
lg.info("Headers: %s", request.headers)
(lg.debug if quiet else lg.info)("Headers: %s", request.headers)
return Response("404: Not found", status=404)


Expand All @@ -75,6 +76,12 @@ def _help() -> Response:
return plaintext(msg)


def _mk_favicon(file: Path | None) -> None:
@app.route("/favicon.ico")
def _favicon() -> Response:
return _page_not_found(404, quiet=True) if file is None else send_file(file)


@app.route("/version")
def _show_version() -> Response:
getLogger(_LOG).info("Request for /version")
Expand Down Expand Up @@ -186,6 +193,8 @@ def _log_config(conf: LogConfig) -> Path:
def serve(conf: ServerConfig, log_conf: LogConfig) -> None:
log_file = _log_config(log_conf)
lg = getLogger(_LOG)
lg.debug("Constructing favicon route given favicon.ico=%s", conf.favicon)
_mk_favicon(conf.favicon)
lg.info("Setting max packet size: %s", log.LFS(MAX_SIZE_HARD))
app.config["MAX_CONTENT_LENGTH"] = MAX_SIZE_HARD
app.url_map.strict_slashes = False
Expand Down
1 change: 1 addition & 0 deletions rpipe/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def cli() -> None:
default=[],
help="SSH ed25519 public keys to accept for admin access",
)
parser.add_argument("-F", "--favicon", type=Path, help="The favicon file, if desired")
log_group = parser.add_argument_group("Logging")
log_group.add_argument(
"-l", "--log-file", type=Path, default=None, help="The log file to append to, if desired"
Expand Down

0 comments on commit 512ecea

Please sign in to comment.