Skip to content

Commit

Permalink
Configurable hotfixes.treat_root_options_as_asterisk
Browse files Browse the repository at this point in the history
  • Loading branch information
mar10 committed Dec 5, 2021
1 parent 7d1abb7 commit 7f94f84
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
3 changes: 3 additions & 0 deletions sample_wsgidav.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ hotfixes:
#: Framework, so this setting should only be used to fix unexpected problems
#: there (false fixes issue #8, true fixes issue #228).
unquote_path_info: false
#: Hotfix for WinXP / Vista: accept 'OPTIONS /' for a 'OPTIONS *'
#: (default: false)
treat_root_options_as_asterisk: false


# ----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions wsgidav/default_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"emulate_win32_lastmod": False, # True: support Win32LastModifiedTime
"re_encode_path_info": True, # (See issue #73)
"unquote_path_info": False, # (See issue #8, #228)
# "treat_root_options_as_asterisk": False, # Hotfix for WinXP / Vista: accept 'OPTIONS /' for a 'OPTIONS *'
# "win_accept_anonymous_options": False,
# "winxp_accept_root_share_login": False,
},
Expand Down
20 changes: 16 additions & 4 deletions wsgidav/request_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@

__docformat__ = "reStructuredText"

_logger = util.get_module_logger(__name__)

# NOTE (Martin Wendt, 2009-05):
# The following remarks were made by Ian Bicking when reviewing PyFileServer in 2005.
# I leave them here after my refactoring for reference.
Expand Down Expand Up @@ -164,9 +166,19 @@ def __call__(self, environ, start_response):
# the top-level realm (e.g. required to map drive letters).

provider = environ["wsgidav.provider"]

# Hotfix for WinXP / Vista: accept '/' for a '*'
if environ["REQUEST_METHOD"] == "OPTIONS" and path in ("/", "*"):
config = environ["wsgidav.config"]
hotfixes = config.get("hotfixes", {})

is_asterisk_options = environ["REQUEST_METHOD"] == "OPTIONS" and path == "*"
if path == "/":
# Hotfix for WinXP / Vista: accept '/' for a '*'
treat_as_asterisk = hotfixes.get("treat_root_options_as_asterisk")
if treat_as_asterisk:
is_asterisk_options = True
else:
_logger.info("Got OPTIONS '/' request")

if is_asterisk_options:
# Answer HTTP 'OPTIONS' method on server-level.
# From RFC 2616:
# If the Request-URI is an asterisk ("*"), the OPTIONS request is
Expand Down Expand Up @@ -202,7 +214,7 @@ def __call__(self, environ, start_response):

if provider is None:
raise DAVError(
HTTP_NOT_FOUND, "Could not find resource provider for '{}'".format(path)
HTTP_NOT_FOUND, f"Could not find resource provider for '{path}'"
)

# Let the appropriate resource provider for the realm handle the
Expand Down
13 changes: 11 additions & 2 deletions wsgidav/request_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,9 @@ def do_OPTIONS(self, environ, start_response):
"""
path = environ["PATH_INFO"]
provider = self._davProvider
config = environ["wsgidav.config"]
hotfixes = config.get("hotfixes", {})

res = provider.get_resource_inst(path, environ)

dav_compliance_level = "1,2"
Expand All @@ -1471,10 +1474,16 @@ def do_OPTIONS(self, environ, start_response):
("Date", util.get_rfc1123_time()),
]

is_asterisk_options = path == "*"
if path == "/":
path = "*" # Hotfix for WinXP
# Hotfix for WinXP / Vista: accept '/' for a '*'
treat_as_asterisk = hotfixes.get("treat_root_options_as_asterisk")
if treat_as_asterisk:
is_asterisk_options = True # Hotfix for WinXP
else:
_logger.info("Got OPTIONS '/' request")

if path == "*":
if is_asterisk_options:
# Answer HTTP 'OPTIONS' method on server-level.
# From RFC 2616
# If the Request-URI is an asterisk ("*"), the OPTIONS request is
Expand Down

0 comments on commit 7f94f84

Please sign in to comment.