__init__.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. # This file is part of Radicale Server - Calendar Server
  2. # Copyright © 2008 Nicolas Kandel
  3. # Copyright © 2008 Pascal Halter
  4. # Copyright © 2008-2016 Guillaume Ayoub
  5. #
  6. # This library is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This library is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Radicale. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. Radicale Server module.
  20. This module offers a WSGI application class.
  21. To use this module, you should take a look at the file ``radicale.py`` that
  22. should have been included in this package.
  23. """
  24. import base64
  25. import contextlib
  26. import itertools
  27. import os
  28. import posixpath
  29. import pprint
  30. import shlex
  31. import socket
  32. import socketserver
  33. import ssl
  34. import subprocess
  35. import threading
  36. import urllib
  37. import wsgiref.simple_server
  38. import zlib
  39. from contextlib import contextmanager
  40. from http import client
  41. from urllib.parse import unquote, urlparse
  42. import vobject
  43. from . import auth, rights, storage, xmlutils
  44. VERSION = "2.0.0rc0"
  45. NOT_ALLOWED = (client.FORBIDDEN, {}, None)
  46. DAV_HEADERS = "1, 2, 3, calendar-access, addressbook, extended-mkcol"
  47. class HTTPServer(wsgiref.simple_server.WSGIServer):
  48. """HTTP server."""
  49. # These class attributes must be set before creating instance
  50. client_timeout = None
  51. max_connections = None
  52. def __init__(self, address, handler, bind_and_activate=True):
  53. """Create server."""
  54. ipv6 = ":" in address[0]
  55. if ipv6:
  56. self.address_family = socket.AF_INET6
  57. # Do not bind and activate, as we might change socket options
  58. super().__init__(address, handler, False)
  59. if ipv6:
  60. # Only allow IPv6 connections to the IPv6 socket
  61. self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
  62. if bind_and_activate:
  63. self.server_bind()
  64. self.server_activate()
  65. if self.max_connections:
  66. self.connections_guard = threading.BoundedSemaphore(
  67. self.max_connections)
  68. else:
  69. # use dummy context manager
  70. self.connections_guard = contextlib.suppress()
  71. def get_request(self):
  72. # Set timeout for client
  73. _socket, address = super().get_request()
  74. if self.client_timeout:
  75. _socket.settimeout(self.client_timeout)
  76. return _socket, address
  77. class HTTPSServer(HTTPServer):
  78. """HTTPS server."""
  79. # These class attributes must be set before creating instance
  80. certificate = None
  81. key = None
  82. protocol = None
  83. cyphers = None
  84. def __init__(self, address, handler):
  85. """Create server by wrapping HTTP socket in an SSL socket."""
  86. super().__init__(address, handler, bind_and_activate=False)
  87. self.socket = ssl.wrap_socket(
  88. self.socket, self.key, self.certificate, server_side=True,
  89. ssl_version=self.protocol, cyphers=self.cyphers)
  90. self.server_bind()
  91. self.server_activate()
  92. class ThreadedHTTPServer(socketserver.ThreadingMixIn, HTTPServer):
  93. def process_request_thread(self, request, client_address):
  94. with self.connections_guard:
  95. return super().process_request_thread(request, client_address)
  96. class ThreadedHTTPSServer(socketserver.ThreadingMixIn, HTTPSServer):
  97. def process_request_thread(self, request, client_address):
  98. with self.connections_guard:
  99. return super().process_request_thread(request, client_address)
  100. class RequestHandler(wsgiref.simple_server.WSGIRequestHandler):
  101. """HTTP requests handler."""
  102. def log_message(self, *args, **kwargs):
  103. """Disable inner logging management."""
  104. def get_environ(self):
  105. env = super().get_environ()
  106. # Parent class only tries latin1 encoding
  107. env["PATH_INFO"] = urllib.parse.unquote(self.path.split("?", 1)[0])
  108. return env
  109. class Application:
  110. """WSGI application managing collections."""
  111. def __init__(self, configuration, logger):
  112. """Initialize application."""
  113. super().__init__()
  114. self.configuration = configuration
  115. self.logger = logger
  116. self.is_authenticated = auth.load(configuration, logger)
  117. self.Collection = storage.load(configuration, logger)
  118. self.authorized = rights.load(configuration, logger)
  119. self.encoding = configuration.get("encoding", "request")
  120. def headers_log(self, environ):
  121. """Sanitize headers for logging."""
  122. request_environ = dict(environ)
  123. # Remove environment variables
  124. if not self.configuration.getboolean("logging", "full_environment"):
  125. for shell_variable in os.environ:
  126. request_environ.pop(shell_variable, None)
  127. # Mask passwords
  128. mask_passwords = self.configuration.getboolean(
  129. "logging", "mask_passwords")
  130. authorization = request_environ.get(
  131. "HTTP_AUTHORIZATION", "").startswith("Basic")
  132. if mask_passwords and authorization:
  133. request_environ["HTTP_AUTHORIZATION"] = "Basic **masked**"
  134. return request_environ
  135. def decode(self, text, environ):
  136. """Try to magically decode ``text`` according to given ``environ``."""
  137. # List of charsets to try
  138. charsets = []
  139. # First append content charset given in the request
  140. content_type = environ.get("CONTENT_TYPE")
  141. if content_type and "charset=" in content_type:
  142. charsets.append(
  143. content_type.split("charset=")[1].split(";")[0].strip())
  144. # Then append default Radicale charset
  145. charsets.append(self.encoding)
  146. # Then append various fallbacks
  147. charsets.append("utf-8")
  148. charsets.append("iso8859-1")
  149. # Try to decode
  150. for charset in charsets:
  151. try:
  152. return text.decode(charset)
  153. except UnicodeDecodeError:
  154. pass
  155. raise UnicodeDecodeError
  156. def collect_allowed_items(self, items, user):
  157. """Get items from request that user is allowed to access."""
  158. read_allowed_items = []
  159. write_allowed_items = []
  160. for item in items:
  161. if isinstance(item, self.Collection):
  162. path = item.path
  163. else:
  164. path = item.collection.path
  165. if self.authorized(user, path, "r"):
  166. self.logger.debug(
  167. "%s has read access to collection %s",
  168. user or "Anonymous", path or "/")
  169. read_allowed_items.append(item)
  170. else:
  171. self.logger.debug(
  172. "%s has NO read access to collection %s",
  173. user or "Anonymous", path or "/")
  174. if self.authorized(user, path, "w"):
  175. self.logger.debug(
  176. "%s has write access to collection %s",
  177. user or "Anonymous", path or "/")
  178. write_allowed_items.append(item)
  179. else:
  180. self.logger.debug(
  181. "%s has NO write access to collection %s",
  182. user or "Anonymous", path or "/")
  183. return read_allowed_items, write_allowed_items
  184. def __call__(self, environ, start_response):
  185. """Manage a request."""
  186. def response(status, headers={}, answer=None):
  187. # Start response
  188. status = "%i %s" % (
  189. status, client.responses.get(status, "Unknown"))
  190. self.logger.debug("Answer status: %s", status)
  191. start_response(status, list(headers.items()))
  192. # Return response content
  193. return [answer] if answer else []
  194. self.logger.debug("\n") # Add empty lines between requests in debug
  195. self.logger.info("%s request at %s received",
  196. environ["REQUEST_METHOD"], environ["PATH_INFO"])
  197. headers = pprint.pformat(self.headers_log(environ))
  198. self.logger.debug("Request headers:\n%s", headers)
  199. # Strip base_prefix from request URI
  200. base_prefix = self.configuration.get("server", "base_prefix")
  201. if environ["PATH_INFO"].startswith(base_prefix):
  202. environ["PATH_INFO"] = environ["PATH_INFO"][len(base_prefix):]
  203. elif self.configuration.get("server", "can_skip_base_prefix"):
  204. self.logger.debug(
  205. "Prefix already stripped from path: %s", environ["PATH_INFO"])
  206. else:
  207. # Request path not starting with base_prefix, not allowed
  208. self.logger.debug(
  209. "Path not starting with prefix: %s", environ["PATH_INFO"])
  210. return response(*NOT_ALLOWED)
  211. # Sanitize request URI
  212. environ["PATH_INFO"] = storage.sanitize_path(
  213. unquote(environ["PATH_INFO"]))
  214. self.logger.debug("Sanitized path: %s", environ["PATH_INFO"])
  215. path = environ["PATH_INFO"]
  216. # Get function corresponding to method
  217. function = getattr(self, "do_%s" % environ["REQUEST_METHOD"].upper())
  218. # Ask authentication backend to check rights
  219. authorization = environ.get("HTTP_AUTHORIZATION", None)
  220. if authorization and authorization.startswith("Basic"):
  221. authorization = authorization[len("Basic"):].strip()
  222. user, password = self.decode(base64.b64decode(
  223. authorization.encode("ascii")), environ).split(":", 1)
  224. else:
  225. user = environ.get("REMOTE_USER")
  226. password = None
  227. # If "/.well-known" is not available, clients query "/"
  228. if path == "/.well-known" or path.startswith("/.well-known/"):
  229. return response(client.NOT_FOUND, {})
  230. if user and not storage.is_safe_path_component(user):
  231. # Prevent usernames like "user/calendar.ics"
  232. self.logger.info("Refused unsafe username: %s", user)
  233. is_authenticated = False
  234. else:
  235. is_authenticated = self.is_authenticated(user, password)
  236. is_valid_user = is_authenticated or not user
  237. # Create principal collection
  238. if user and is_authenticated:
  239. principal_path = "/%s/" % user
  240. if self.authorized(user, principal_path, "w"):
  241. with self._lock_collection("r", user):
  242. principal = next(
  243. self.Collection.discover(principal_path, depth="1"),
  244. None)
  245. if not principal:
  246. with self._lock_collection("w", user):
  247. self.Collection.create_collection(principal_path)
  248. # Verify content length
  249. content_length = int(environ.get("CONTENT_LENGTH") or 0)
  250. if content_length:
  251. max_content_length = self.configuration.getint(
  252. "server", "max_content_length")
  253. if max_content_length and content_length > max_content_length:
  254. self.logger.debug(
  255. "Request body too large: %d", content_length)
  256. return response(client.REQUEST_ENTITY_TOO_LARGE)
  257. if is_valid_user:
  258. try:
  259. status, headers, answer = function(environ, path, user)
  260. except socket.timeout:
  261. return response(client.REQUEST_TIMEOUT)
  262. else:
  263. status, headers, answer = NOT_ALLOWED
  264. if (status, headers, answer) == NOT_ALLOWED and not (
  265. user and is_authenticated):
  266. # Unknown or unauthorized user
  267. self.logger.info("%s refused" % (user or "Anonymous user"))
  268. status = client.UNAUTHORIZED
  269. realm = self.configuration.get("server", "realm")
  270. headers = {
  271. "WWW-Authenticate":
  272. "Basic realm=\"%s\"" % realm}
  273. answer = None
  274. # Set content length
  275. if answer:
  276. self.logger.debug("Response content:\n%s", answer)
  277. answer = answer.encode(self.encoding)
  278. accept_encoding = [
  279. encoding.strip() for encoding in
  280. environ.get("HTTP_ACCEPT_ENCODING", "").split(",")
  281. if encoding.strip()]
  282. if "gzip" in accept_encoding:
  283. zcomp = zlib.compressobj(wbits=16 + zlib.MAX_WBITS)
  284. answer = zcomp.compress(answer) + zcomp.flush()
  285. headers["Content-Encoding"] = "gzip"
  286. headers["Content-Length"] = str(len(answer))
  287. # Add extra headers set in configuration
  288. if self.configuration.has_section("headers"):
  289. for key in self.configuration.options("headers"):
  290. headers[key] = self.configuration.get("headers", key)
  291. return response(status, headers, answer)
  292. def _access(self, user, path, permission, item=None):
  293. """Check if ``user`` can access ``path`` or the parent collection.
  294. ``permission`` must either be "r" or "w".
  295. If ``item`` is given, only access to that class of item is checked.
  296. """
  297. path = storage.sanitize_path(path)
  298. parent_path = storage.sanitize_path(
  299. "/%s/" % posixpath.dirname(path.strip("/")))
  300. allowed = False
  301. if not item or isinstance(item, self.Collection):
  302. allowed |= self.authorized(user, path, permission)
  303. if not item or not isinstance(item, self.Collection):
  304. allowed |= self.authorized(user, parent_path, permission)
  305. return allowed
  306. @contextmanager
  307. def _lock_collection(self, lock_mode, user):
  308. """Lock the collection with ``permission`` and execute hook."""
  309. with self.Collection.acquire_lock(lock_mode) as value:
  310. yield value
  311. hook = self.configuration.get("storage", "hook")
  312. if lock_mode == "w" and hook:
  313. self.logger.debug("Running hook")
  314. folder = os.path.expanduser(self.configuration.get(
  315. "storage", "filesystem_folder"))
  316. subprocess.check_call(
  317. hook % {"user": shlex.quote(user or "Anonymous")},
  318. shell=True, cwd=folder)
  319. def _read_content(self, environ):
  320. content_length = int(environ.get("CONTENT_LENGTH") or 0)
  321. if content_length > 0:
  322. content = self.decode(
  323. environ["wsgi.input"].read(content_length), environ)
  324. self.logger.debug("Request content:\n%s", content.strip())
  325. else:
  326. content = None
  327. return content
  328. def do_DELETE(self, environ, path, user):
  329. """Manage DELETE request."""
  330. if not self._access(user, path, "w"):
  331. return NOT_ALLOWED
  332. with self._lock_collection("w", user):
  333. item = next(self.Collection.discover(path), None)
  334. if not self._access(user, path, "w", item):
  335. return NOT_ALLOWED
  336. if not item:
  337. return client.GONE, {}, None
  338. if_match = environ.get("HTTP_IF_MATCH", "*")
  339. if if_match not in ("*", item.etag):
  340. # ETag precondition not verified, do not delete item
  341. return client.PRECONDITION_FAILED, {}, None
  342. if isinstance(item, self.Collection):
  343. answer = xmlutils.delete(path, item)
  344. else:
  345. answer = xmlutils.delete(path, item.collection, item.href)
  346. return client.OK, {}, answer
  347. def do_GET(self, environ, path, user):
  348. """Manage GET request."""
  349. # Display a "Radicale works!" message if the root URL is requested
  350. if not path.strip("/"):
  351. headers = {"Content-type": "text/html"}
  352. answer = "<!DOCTYPE html>\n<title>Radicale</title>Radicale works!"
  353. return client.OK, headers, answer
  354. if not self._access(user, path, "r"):
  355. return NOT_ALLOWED
  356. with self._lock_collection("r", user):
  357. item = next(self.Collection.discover(path), None)
  358. if not self._access(user, path, "r", item):
  359. return NOT_ALLOWED
  360. if not item:
  361. return client.NOT_FOUND, {}, None
  362. if isinstance(item, self.Collection):
  363. collection = item
  364. else:
  365. collection = item.collection
  366. content_type = xmlutils.MIMETYPES.get(
  367. collection.get_meta("tag"), "text/plain")
  368. headers = {
  369. "Content-Type": content_type,
  370. "Last-Modified": collection.last_modified,
  371. "ETag": item.etag}
  372. answer = item.serialize()
  373. return client.OK, headers, answer
  374. def do_HEAD(self, environ, path, user):
  375. """Manage HEAD request."""
  376. status, headers, answer = self.do_GET(environ, path, user)
  377. return status, headers, None
  378. def do_MKCALENDAR(self, environ, path, user):
  379. """Manage MKCALENDAR request."""
  380. if not self.authorized(user, path, "w"):
  381. return NOT_ALLOWED
  382. content = self._read_content(environ)
  383. with self._lock_collection("w", user):
  384. item = next(self.Collection.discover(path), None)
  385. if item:
  386. return client.CONFLICT, {}, None
  387. props = xmlutils.props_from_request(content)
  388. props["tag"] = "VCALENDAR"
  389. # TODO: use this?
  390. # timezone = props.get("C:calendar-timezone")
  391. self.Collection.create_collection(path, props=props)
  392. return client.CREATED, {}, None
  393. def do_MKCOL(self, environ, path, user):
  394. """Manage MKCOL request."""
  395. if not self.authorized(user, path, "w"):
  396. return NOT_ALLOWED
  397. content = self._read_content(environ)
  398. with self._lock_collection("w", user):
  399. item = next(self.Collection.discover(path), None)
  400. if item:
  401. return client.CONFLICT, {}, None
  402. props = xmlutils.props_from_request(content)
  403. self.Collection.create_collection(path, props=props)
  404. return client.CREATED, {}, None
  405. def do_MOVE(self, environ, path, user):
  406. """Manage MOVE request."""
  407. to_url = urlparse(environ["HTTP_DESTINATION"])
  408. if to_url.netloc != environ["HTTP_HOST"]:
  409. # Remote destination server, not supported
  410. return client.BAD_GATEWAY, {}, None
  411. if not self._access(user, path, "w"):
  412. return NOT_ALLOWED
  413. to_path = storage.sanitize_path(to_url.path)
  414. if not self._access(user, to_path, "w"):
  415. return NOT_ALLOWED
  416. with self._lock_collection("w", user):
  417. item = next(self.Collection.discover(path), None)
  418. if not self._access(user, path, "w", item):
  419. return NOT_ALLOWED
  420. if not self._access(user, to_path, "w", item):
  421. return NOT_ALLOWED
  422. if not item:
  423. return client.GONE, {}, None
  424. if isinstance(item, self.Collection):
  425. return client.CONFLICT, {}, None
  426. to_item = next(self.Collection.discover(to_path), None)
  427. if (isinstance(to_item, self.Collection) or
  428. to_item and environ.get("HTTP_OVERWRITE", "F") != "T"):
  429. return client.CONFLICT, {}, None
  430. to_parent_path = storage.sanitize_path(
  431. "/%s/" % posixpath.dirname(to_path.strip("/")))
  432. to_collection = next(
  433. self.Collection.discover(to_parent_path), None)
  434. if not to_collection:
  435. return client.CONFLICT, {}, None
  436. to_href = posixpath.basename(to_path.strip("/"))
  437. self.Collection.move(item, to_collection, to_href)
  438. return client.CREATED, {}, None
  439. def do_OPTIONS(self, environ, path, user):
  440. """Manage OPTIONS request."""
  441. headers = {
  442. "Allow": ", ".join(
  443. name[3:] for name in dir(self) if name.startswith("do_")),
  444. "DAV": DAV_HEADERS}
  445. return client.OK, headers, None
  446. def do_PROPFIND(self, environ, path, user):
  447. """Manage PROPFIND request."""
  448. if not self._access(user, path, "r"):
  449. return NOT_ALLOWED
  450. content = self._read_content(environ)
  451. with self._lock_collection("r", user):
  452. items = self.Collection.discover(
  453. path, environ.get("HTTP_DEPTH", "0"))
  454. # take root item for rights checking
  455. item = next(items, None)
  456. if not self._access(user, path, "r", item):
  457. return NOT_ALLOWED
  458. if not item:
  459. return client.NOT_FOUND, {}, None
  460. # put item back
  461. items = itertools.chain([item], items)
  462. read_items, write_items = self.collect_allowed_items(items, user)
  463. headers = {"DAV": DAV_HEADERS, "Content-Type": "text/xml"}
  464. status, answer = xmlutils.propfind(
  465. path, content, read_items, write_items, user)
  466. if status == client.FORBIDDEN:
  467. return NOT_ALLOWED
  468. else:
  469. return status, headers, answer
  470. def do_PROPPATCH(self, environ, path, user):
  471. """Manage PROPPATCH request."""
  472. if not self.authorized(user, path, "w"):
  473. return NOT_ALLOWED
  474. content = self._read_content(environ)
  475. with self._lock_collection("w", user):
  476. item = next(self.Collection.discover(path), None)
  477. if not isinstance(item, self.Collection):
  478. return client.CONFLICT, {}, None
  479. headers = {"DAV": DAV_HEADERS, "Content-Type": "text/xml"}
  480. answer = xmlutils.proppatch(path, content, item)
  481. return client.MULTI_STATUS, headers, answer
  482. def do_PUT(self, environ, path, user):
  483. """Manage PUT request."""
  484. if not self._access(user, path, "w"):
  485. return NOT_ALLOWED
  486. content = self._read_content(environ)
  487. with self._lock_collection("w", user):
  488. parent_path = storage.sanitize_path(
  489. "/%s/" % posixpath.dirname(path.strip("/")))
  490. item = next(self.Collection.discover(path), None)
  491. parent_item = next(self.Collection.discover(parent_path), None)
  492. write_whole_collection = (
  493. isinstance(item, self.Collection) or
  494. not parent_item or (
  495. not next(parent_item.list(), None) and
  496. parent_item.get_meta("tag") not in (
  497. "VADDRESSBOOK", "VCALENDAR")))
  498. if write_whole_collection:
  499. if not self.authorized(user, path, "w"):
  500. return NOT_ALLOWED
  501. elif not self.authorized(user, parent_path, "w"):
  502. return NOT_ALLOWED
  503. etag = environ.get("HTTP_IF_MATCH", "")
  504. if not item and etag:
  505. # Etag asked but no item found: item has been removed
  506. return client.PRECONDITION_FAILED, {}, None
  507. if item and etag and item.etag != etag:
  508. # Etag asked but item not matching: item has changed
  509. return client.PRECONDITION_FAILED, {}, None
  510. match = environ.get("HTTP_IF_NONE_MATCH", "") == "*"
  511. if item and match:
  512. # Creation asked but item found: item can't be replaced
  513. return client.PRECONDITION_FAILED, {}, None
  514. items = list(vobject.readComponents(content or ""))
  515. content_type = environ.get("CONTENT_TYPE", "").split(";")[0]
  516. tags = {value: key for key, value in xmlutils.MIMETYPES.items()}
  517. tag = tags.get(content_type)
  518. if write_whole_collection:
  519. new_item = self.Collection.create_collection(
  520. path, items, {"tag": tag})
  521. else:
  522. if tag:
  523. parent_item.set_meta({"tag": tag})
  524. href = posixpath.basename(path.strip("/"))
  525. if item:
  526. new_item = parent_item.update(href, items[0])
  527. else:
  528. new_item = parent_item.upload(href, items[0])
  529. headers = {"ETag": new_item.etag}
  530. return client.CREATED, headers, None
  531. def do_REPORT(self, environ, path, user):
  532. """Manage REPORT request."""
  533. if not self._access(user, path, "w"):
  534. return NOT_ALLOWED
  535. content = self._read_content(environ)
  536. with self._lock_collection("r", user):
  537. item = next(self.Collection.discover(path), None)
  538. if not self._access(user, path, "w", item):
  539. return NOT_ALLOWED
  540. if not item:
  541. return client.NOT_FOUND, {}, None
  542. if isinstance(item, self.Collection):
  543. collection = item
  544. else:
  545. collection = item.collection
  546. headers = {"Content-Type": "text/xml"}
  547. answer = xmlutils.report(path, content, collection)
  548. return client.MULTI_STATUS, headers, answer