From 3f3f0312fa0ce30d572b87926e73e178251f857d Mon Sep 17 00:00:00 2001 From: c-bata Date: Wed, 11 Sep 2024 16:41:50 +0900 Subject: [PATCH 1/2] Fix content-encoding and content-type headers in Bottle 0.13+ --- optuna_dashboard/_app.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/optuna_dashboard/_app.py b/optuna_dashboard/_app.py index a983d320..e1c040ac 100644 --- a/optuna_dashboard/_app.py +++ b/optuna_dashboard/_app.py @@ -6,12 +6,10 @@ import importlib import io from itertools import chain import logging +import mimetypes import os import re import typing -from typing import Any -from typing import Optional -from typing import Union import warnings from bottle import Bottle @@ -57,6 +55,11 @@ from .preferential._system_attrs import report_skip if typing.TYPE_CHECKING: + from typing import Any + from typing import Literal + from typing import Optional + from typing import Union + from _typeshed.wsgi import WSGIApplication from optuna.artifacts._protocol import ArtifactStore from optuna_dashboard.artifact.protocol import ArtifactBackend @@ -557,11 +560,18 @@ def create_app( @app.get("/static/") def send_static(filename: str) -> BottleViewReturn: + mimetype: str | Literal[True] = True + headers: dict[str, str] | None = None if not debug and "gzip" in request.headers["Accept-Encoding"]: gz_filename = filename.strip("/\\") + ".gz" if cached_path_exists(os.path.join(STATIC_DIR, gz_filename)): filename = gz_filename - return static_file(filename, root=STATIC_DIR) + headers = {"Content-Encoding": "gzip"} + + mimetype_, _ = mimetypes.guess_type(filename) + if mimetype_ is not None: + mimetype = mimetype_ + return static_file(filename, root=STATIC_DIR, mimetype=mimetype, headers=headers) register_rdb_migration_route(app, storage) register_artifact_route(app, storage, artifact_store) From 95756e957ada8f7964310555d108a10a479f3166 Mon Sep 17 00:00:00 2001 From: c-bata Date: Wed, 11 Sep 2024 16:58:18 +0900 Subject: [PATCH 2/2] Set version constraints on bottle --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index fa3da28a..9b475fc1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,7 @@ classifiers = [ "Intended Audience :: Science/Research", ] dependencies = [ - "bottle", + "bottle>=0.13.0", "optuna>=3.1.0", "packaging", "scikit-learn",