Skip to content

Commit

Permalink
New option suppress_version_info
Browse files Browse the repository at this point in the history
New option `suppress_version_info` to suppress WsgiDAV's version info in  responses (default: false)
  • Loading branch information
mar10 committed Dec 2, 2023
1 parent 36fecad commit e63b69a
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## 4.3.1 / Unreleased

- New option `suppress_version_info` to suppress WsgiDAV's version info in
responses (default: false).
- #298: `--root` argument honors `fs_dav_provider` configuration.
- #301: `_DAVResource` should have `is_link()` method to avoid dir_browser issues.

## 4.3.0 / 2023-09-24

- BREAKING:
Expand Down
3 changes: 3 additions & 0 deletions sample_wsgidav.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ lock_storage: true
#: Set verbosity level (can be overridden by -v or -q arguments)
verbose: 3

#: Suppress version info in HTTP response headers and error responses
suppress_version_info: false

logging:
#: Enable logging when using wsgidav in library mode (always on, when running as CLI)
enable: null
Expand Down
7 changes: 4 additions & 3 deletions wsgidav/dav_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import datetime
from html import escape as html_escape

from wsgidav import __version__, util, xml_tools
from wsgidav import util, xml_tools
from wsgidav.xml_tools import etree

__docformat__ = "reStructuredText"
Expand Down Expand Up @@ -254,8 +254,9 @@ def get_response_page(self):
html.append(" <p>{}</p>".format(html_escape(self.get_user_info())))
html.append("<hr/>")
html.append(
"<a href='https://github.com/mar10/wsgidav/'>WsgiDAV/{}</a> - {}".format(
__version__, html_escape(str(datetime.datetime.now()), "utf-8")
"<a href='https://github.com/mar10/wsgidav/'>{}</a> - {}".format(
util.public_wsgidav_info,
html_escape(str(datetime.datetime.now()), "utf-8"),
)
)
html.append("</body></html>")
Expand Down
2 changes: 2 additions & 0 deletions wsgidav/default_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
#: 5 - show full request/response header info (HTTP Logging)
#: request body and GET response bodies not shown
"verbose": DEFAULT_VERBOSE,
#: Suppress version info in HTTP response headers and error responses
"suppress_version_info": False,
#: Log options
"logging": {
"enable": None, # True: activate 'wsgidav' logger (in library mode)
Expand Down
3 changes: 1 addition & 2 deletions wsgidav/dir_browser/_dir_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def __call__(self, environ, start_response):
and dav_res
and dav_res.is_collection
):

if util.get_content_length(environ) != 0:
self._fail(
HTTP_MEDIATYPE_NOT_SUPPORTED,
Expand Down Expand Up @@ -195,7 +194,7 @@ def _get_context(self, environ, dav_res):
if trailer:
trailer = trailer.replace(
"${version}",
f"<a href='https://github.com/mar10/wsgidav/'>WsgiDAV/{__version__}</a>",
f"<a href='https://github.com/mar10/wsgidav/'>{util.public_wsgidav_info}</a>",
)
trailer = trailer.replace("${time}", util.get_rfc1123_time())

Expand Down
7 changes: 3 additions & 4 deletions wsgidav/server/ext_wsgiutils_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
from io import StringIO
from urllib.parse import urlparse

from wsgidav import __version__, util
from wsgidav import util

_logger = util.get_module_logger(__name__)

Expand All @@ -88,7 +88,6 @@


class ExtHandler(BaseHTTPServer.BaseHTTPRequestHandler):

_SUPPORTED_METHODS = [
"HEAD",
"GET",
Expand All @@ -109,8 +108,8 @@ class ExtHandler(BaseHTTPServer.BaseHTTPRequestHandler):
# Enable automatic keep-alive:
protocol_version = "HTTP/1.1"

server_version = "WsgiDAV/{} ExtServer/{} {}".format(
__version__,
server_version = "{} ExtServer/{} {}".format(
util.public_wsgidav_info,
_version,
BaseHTTPServer.BaseHTTPRequestHandler.server_version,
)
Expand Down
15 changes: 9 additions & 6 deletions wsgidav/server/server_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ def _init_config():
# # import pydevd
# # pydevd.settrace()

if config["suppress_version_info"]:
util.public_wsgidav_info = "WsgiDAV"

return cli_opts, config


Expand All @@ -440,7 +443,7 @@ def _run_cheroot(app, config, _server):
return False

version = (
f"WsgiDAV/{__version__} {wsgi.Server.version} Python/{util.PYTHON_VERSION}"
f"{util.public_wsgidav_info} {wsgi.Server.version} Python/{util.PYTHON_VERSION}"
)
# wsgi.Server.version = version

Expand Down Expand Up @@ -532,7 +535,7 @@ def _run_gevent(app, config, server):

info = _get_common_info(config)
version = f"gevent/{gevent.__version__}"
version = f"WsgiDAV/{__version__} {version} Python {util.PYTHON_VERSION}"
version = f"{util.public_wsgidav_info} {version} Python {util.PYTHON_VERSION}"

# Override or add custom args
server_args = {
Expand Down Expand Up @@ -627,7 +630,7 @@ def load(self):
server_args.update(custom_args)

version = f"gunicorn/{gunicorn.__version__}"
version = f"WsgiDAV/{__version__} {version} Python {util.PYTHON_VERSION}"
version = f"{util.public_wsgidav_info} {version} Python {util.PYTHON_VERSION}"
_logger.info(f"Running {version} ...")

GunicornApplication(app, server_args).run()
Expand All @@ -650,7 +653,7 @@ def _run_paste(app, config, server):
info = _get_common_info(config)

version = httpserver.WSGIHandler.server_version
version = f"WsgiDAV/{__version__} {version} Python {util.PYTHON_VERSION}"
version = f"{util.public_wsgidav_info} {version} Python {util.PYTHON_VERSION}"

# See http://pythonpaste.org/modules/httpserver.html for more options
server = httpserver.serve(
Expand Down Expand Up @@ -724,7 +727,7 @@ def _run_uvicorn(app, config, server):
server_args.update(custom_args)

version = f"uvicorn/{uvicorn.__version__}"
version = f"WsgiDAV/{__version__} {version} Python {util.PYTHON_VERSION}"
version = f"{util.public_wsgidav_info} {version} Python {util.PYTHON_VERSION}"
_logger.info(f"Running {version} ...")

uvicorn.run(app, **server_args)
Expand All @@ -735,7 +738,7 @@ def _run_wsgiref(app, config, _server):
from wsgiref.simple_server import WSGIRequestHandler, make_server

version = WSGIRequestHandler.server_version
version = f"WsgiDAV/{__version__} {version}" # Python {util.PYTHON_VERSION}"
version = f"{util.public_wsgidav_info} {version}" # Python {util.PYTHON_VERSION}"
_logger.info(f"Running {version} ...")

_logger.warning(
Expand Down
4 changes: 2 additions & 2 deletions wsgidav/server/server_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
from cheroot import wsgi

from wsgidav import __version__, util
from wsgidav import util
from wsgidav.fs_dav_provider import FilesystemProvider
from wsgidav.wsgidav_app import WsgiDAVApp

Expand Down Expand Up @@ -36,7 +36,7 @@ def main():

# For an example, use cheroot:
version = (
f"WsgiDAV/{__version__} {wsgi.Server.version} Python/{util.PYTHON_VERSION}"
f"{util.public_wsgidav_info} {wsgi.Server.version} Python/{util.PYTHON_VERSION}"
)

server = wsgi.Server(
Expand Down
11 changes: 8 additions & 3 deletions wsgidav/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from typing import Iterable, Optional, Tuple
from urllib.parse import quote

from wsgidav import __version__
from wsgidav.dav_error import (
HTTP_BAD_REQUEST,
HTTP_CREATED,
Expand All @@ -45,12 +46,16 @@
BASE_LOGGER_NAME = "wsgidav"
_logger = logging.getLogger(BASE_LOGGER_NAME)

PYTHON_VERSION = "{}.{}.{}".format(
sys.version_info[0], sys.version_info[1], sys.version_info[2]
)
#: Currently used Python version as string
PYTHON_VERSION = ".".join([str(s) for s in sys.version_info[:3]])

filesystemencoding = sys.getfilesystemencoding()

#: Project name and version presented to the clients
#: This is reset to ``"WsgiDAV"`` if ``suppress_version_info`` is set in the
#: configuration.
public_wsgidav_info = f"WsgiDAV/{__version__}"


class NO_DEFAULT:
""""""
Expand Down
8 changes: 5 additions & 3 deletions wsgidav/wsgidav_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import time
from urllib.parse import unquote

from wsgidav import __version__, util
from wsgidav import util
from wsgidav.dav_provider import DAVProvider
from wsgidav.default_conf import DEFAULT_CONFIG
from wsgidav.fs_dav_provider import FilesystemProvider
Expand Down Expand Up @@ -278,8 +278,10 @@ def __init__(self, config):
_logger.error("Could not add middleware {}.".format(mw))

_logger.info(
"WsgiDAV/{} Python/{} {}".format(
__version__, util.PYTHON_VERSION, platform.platform(aliased=True)
"{} Python/{} {}".format(
util.public_wsgidav_info,
util.PYTHON_VERSION,
platform.platform(aliased=True),
)
)

Expand Down

0 comments on commit e63b69a

Please sign in to comment.