Skip to content

Commit

Permalink
Hotfix PUT request without content-length (#282)
Browse files Browse the repository at this point in the history
* Hotfix PUT request without content-length

MacOS Ventura behaviour is now similar to MS Windows

* tox -e format

* New option hotfixes. accept_put_without_content_length

* Squashed commit of the following:

commit aa6d498
Author: Martin Wendt <github@wwwendt.de>
Date:   Tue Apr 11 22:09:58 2023 +0200

    Fix: Requesting range off end of file does not return 416 status code

    Close #281

commit 1fdb68f
Author: Martin Wendt <github@wwwendt.de>
Date:   Mon Apr 10 19:16:06 2023 +0200

    Snake-cased some vars

commit 5f259c2
Author: Martin Wendt <github@wwwendt.de>
Date:   Mon Apr 10 17:59:26 2023 +0200

    Install pam_dc dependencies using extra syntax: `pip install wsgidav[pam]`

---------

Co-authored-by: Martin Wendt <github@wwwendt.de>
  • Loading branch information
JonasPertschy and mar10 committed Apr 13, 2023
1 parent aa6d498 commit 53092f2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 4.2.1 / Unreleased
- Install pam_dc dependencies using extra syntax: `pip install wsgidav[pam]`
- #281 Requesting range off end of file does not return 416 status code
- #282 Hotfix PUT request without content-length (fix for Finder on MacOS Ventura)

## 4.2.0 / 2023-02-18

Expand Down
4 changes: 4 additions & 0 deletions sample_wsgidav.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ block_size: 8192
add_header_MS_Author_Via: true

hotfixes:
#: Some clients send PUT requests without a body and omit the
#: `Content-Length` header ("Microsoft-WebDAV-MiniRedir", "gvfs/", "Darwin").
#: See issues #10, #282. This option assumes "0" for missing headers:
accept_put_without_content_length: true
#: Handle Microsoft's Win32LastModifiedTime property.
#: This is useful only in the case when you copy files from a Windows
#: client into a WebDAV share. Windows sends the "last modified" time of
Expand Down
1 change: 1 addition & 0 deletions wsgidav/default_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"emulate_win32_lastmod": False, # True: support Win32LastModifiedTime
"re_encode_path_info": True, # (See issue #73)
"unquote_path_info": False, # (See issue #8, #228)
"accept_put_without_content_length": True, # (See issue #10, #282)
# "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
16 changes: 11 additions & 5 deletions wsgidav/request_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,22 +790,28 @@ def do_PUT(self, environ, start_response):

# Start Content Processing
# Content-Length may be 0 or greater. (Set to -1 if missing or invalid.)
# WORKAROUND_BAD_LENGTH = True
try:
content_length = max(-1, int(environ.get("CONTENT_LENGTH", -1)))
except ValueError:
content_length = -1

# if content_length < 0 and not WORKAROUND_BAD_LENGTH:
if (content_length < 0) and (
environ.get("HTTP_TRANSFER_ENCODING", "").lower() != "chunked"
):
# HOTFIX: not fully understood, but MS sends PUT without content-length,
# when creating new files
agent = environ.get("HTTP_USER_AGENT", "")
if "Microsoft-WebDAV-MiniRedir" in agent or "gvfs/" in agent: # issue #10

config = environ["wsgidav.config"]
hotfixes = util.get_dict_value(config, "hotfixes", as_dict=True)
accept_put_without_content_length = hotfixes.get(
"accept_put_without_content_length", True
)

# if ( "Microsoft-WebDAV-MiniRedir" in agent or "gvfs/" in agent):
if accept_put_without_content_length: # issue #10, #282
agent = environ.get("HTTP_USER_AGENT", "")
_logger.warning(
"Setting misssing Content-Length to 0 for MS / gvfs client"
f"Set misssing Content-Length to 0 for PUT, agent={agent!r}"
)
content_length = 0
else:
Expand Down

0 comments on commit 53092f2

Please sign in to comment.