XML error message for invalid sync-token

This commit is contained in:
Unrud 2017-06-07 14:16:18 +02:00
parent 13381fb829
commit 3753364fc8
2 changed files with 9 additions and 3 deletions

View File

@ -842,6 +842,4 @@ class Application:
headers = {"Content-Type": "text/xml; charset=%s" % self.encoding}
status, xml_answer = xmlutils.report(
base_prefix, path, xml_content, collection)
if status == client.PRECONDITION_FAILED:
return PRECONDITION_FAILED
return (status, headers, self._write_xml_content(xml_answer))

View File

@ -127,6 +127,13 @@ def _href(base_prefix, href):
return quote("%s%s" % (base_prefix, href))
def _webdav_error(namespace, name):
"""Generate XML error message."""
root = ET.Element(_tag("D", "error"))
root.append(ET.Element(_tag(namespace, name)))
return root
def _date_to_datetime(date_):
"""Transform a date to a UTC datetime.
@ -1041,7 +1048,8 @@ def report(base_prefix, path, xml_request, collection):
# Invalid sync token
collection.logger.warning("Client provided invalid sync token %r: "
"%s", old_sync_token, e, exc_info=True)
return client.PRECONDITION_FAILED, None
return (client.PRECONDITION_FAILED,
_webdav_error("D", "valid-sync-token"))
hreferences = ("/" + posixpath.join(collection.path, n) for n in names)
# Append current sync token to response
sync_token_element = ET.Element(_tag("D", "sync-token"))