__init__.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  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 io
  27. import itertools
  28. import os
  29. import posixpath
  30. import pprint
  31. import socket
  32. import socketserver
  33. import ssl
  34. import threading
  35. import urllib
  36. import wsgiref.simple_server
  37. import zlib
  38. from http import client
  39. from urllib.parse import unquote, urlparse
  40. import vobject
  41. from . import auth, rights, storage, xmlutils
  42. VERSION = "2.0.0rc0"
  43. NOT_ALLOWED = (client.FORBIDDEN, {}, None)
  44. DAV_HEADERS = "1, 2, 3, calendar-access, addressbook, extended-mkcol"
  45. class HTTPServer(wsgiref.simple_server.WSGIServer):
  46. """HTTP server."""
  47. # These class attributes must be set before creating instance
  48. client_timeout = None
  49. max_connections = None
  50. def __init__(self, address, handler, bind_and_activate=True):
  51. """Create server."""
  52. ipv6 = ":" in address[0]
  53. if ipv6:
  54. self.address_family = socket.AF_INET6
  55. # Do not bind and activate, as we might change socket options
  56. super().__init__(address, handler, False)
  57. if ipv6:
  58. # Only allow IPv6 connections to the IPv6 socket
  59. self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
  60. if bind_and_activate:
  61. self.server_bind()
  62. self.server_activate()
  63. if self.max_connections:
  64. self.connections_guard = threading.BoundedSemaphore(
  65. self.max_connections)
  66. else:
  67. # use dummy context manager
  68. self.connections_guard = contextlib.suppress()
  69. def get_request(self):
  70. # Set timeout for client
  71. _socket, address = super().get_request()
  72. if self.client_timeout:
  73. _socket.settimeout(self.client_timeout)
  74. return _socket, address
  75. class HTTPSServer(HTTPServer):
  76. """HTTPS server."""
  77. # These class attributes must be set before creating instance
  78. certificate = None
  79. key = None
  80. protocol = None
  81. ciphers = None
  82. def __init__(self, address, handler):
  83. """Create server by wrapping HTTP socket in an SSL socket."""
  84. super().__init__(address, handler, bind_and_activate=False)
  85. self.socket = ssl.wrap_socket(
  86. self.socket, self.key, self.certificate, server_side=True,
  87. ssl_version=self.protocol, ciphers=self.ciphers)
  88. self.server_bind()
  89. self.server_activate()
  90. class ThreadedHTTPServer(socketserver.ThreadingMixIn, HTTPServer):
  91. def process_request_thread(self, request, client_address):
  92. with self.connections_guard:
  93. return super().process_request_thread(request, client_address)
  94. class ThreadedHTTPSServer(socketserver.ThreadingMixIn, HTTPSServer):
  95. def process_request_thread(self, request, client_address):
  96. with self.connections_guard:
  97. return super().process_request_thread(request, client_address)
  98. class RequestHandler(wsgiref.simple_server.WSGIRequestHandler):
  99. """HTTP requests handler."""
  100. # These class attributes must be set before creating instance
  101. logger = None
  102. def __init__(self, *args, **kwargs):
  103. # Store exception for logging
  104. self.error_stream = io.StringIO()
  105. super().__init__(*args, **kwargs)
  106. def get_stderr(self):
  107. return self.error_stream
  108. def log_message(self, *args, **kwargs):
  109. """Disable inner logging management."""
  110. def get_environ(self):
  111. env = super().get_environ()
  112. # Parent class only tries latin1 encoding
  113. env["PATH_INFO"] = urllib.parse.unquote(self.path.split("?", 1)[0])
  114. return env
  115. def handle(self):
  116. super().handle()
  117. # Log exception
  118. error = self.error_stream.getvalue().strip("\n")
  119. if error:
  120. self.logger.error(
  121. "An exception occurred during request:\n%s" % error)
  122. class Application:
  123. """WSGI application managing collections."""
  124. def __init__(self, configuration, logger):
  125. """Initialize application."""
  126. super().__init__()
  127. self.configuration = configuration
  128. self.logger = logger
  129. self.is_authenticated = auth.load(configuration, logger)
  130. self.Collection = storage.load(configuration, logger)
  131. self.authorized = rights.load(configuration, logger)
  132. self.encoding = configuration.get("encoding", "request")
  133. def headers_log(self, environ):
  134. """Sanitize headers for logging."""
  135. request_environ = dict(environ)
  136. # Remove environment variables
  137. if not self.configuration.getboolean("logging", "full_environment"):
  138. for shell_variable in os.environ:
  139. request_environ.pop(shell_variable, None)
  140. # Mask passwords
  141. mask_passwords = self.configuration.getboolean(
  142. "logging", "mask_passwords")
  143. authorization = request_environ.get(
  144. "HTTP_AUTHORIZATION", "").startswith("Basic")
  145. if mask_passwords and authorization:
  146. request_environ["HTTP_AUTHORIZATION"] = "Basic **masked**"
  147. return request_environ
  148. def decode(self, text, environ):
  149. """Try to magically decode ``text`` according to given ``environ``."""
  150. # List of charsets to try
  151. charsets = []
  152. # First append content charset given in the request
  153. content_type = environ.get("CONTENT_TYPE")
  154. if content_type and "charset=" in content_type:
  155. charsets.append(
  156. content_type.split("charset=")[1].split(";")[0].strip())
  157. # Then append default Radicale charset
  158. charsets.append(self.encoding)
  159. # Then append various fallbacks
  160. charsets.append("utf-8")
  161. charsets.append("iso8859-1")
  162. # Try to decode
  163. for charset in charsets:
  164. try:
  165. return text.decode(charset)
  166. except UnicodeDecodeError:
  167. pass
  168. raise UnicodeDecodeError
  169. def collect_allowed_items(self, items, user):
  170. """Get items from request that user is allowed to access."""
  171. read_allowed_items = []
  172. write_allowed_items = []
  173. for item in items:
  174. if isinstance(item, self.Collection):
  175. path = item.path
  176. else:
  177. path = item.collection.path
  178. if self.authorized(user, path, "r"):
  179. self.logger.debug(
  180. "%s has read access to collection %s",
  181. user or "Anonymous", path or "/")
  182. read_allowed_items.append(item)
  183. else:
  184. self.logger.debug(
  185. "%s has NO read access to collection %s",
  186. user or "Anonymous", path or "/")
  187. if self.authorized(user, path, "w"):
  188. self.logger.debug(
  189. "%s has write access to collection %s",
  190. user or "Anonymous", path or "/")
  191. write_allowed_items.append(item)
  192. else:
  193. self.logger.debug(
  194. "%s has NO write access to collection %s",
  195. user or "Anonymous", path or "/")
  196. return read_allowed_items, write_allowed_items
  197. def __call__(self, environ, start_response):
  198. """Manage a request."""
  199. def response(status, headers={}, answer=None):
  200. # Start response
  201. status = "%i %s" % (
  202. status, client.responses.get(status, "Unknown"))
  203. self.logger.debug("Answer status: %s", status)
  204. start_response(status, list(headers.items()))
  205. # Return response content
  206. return [answer] if answer else []
  207. self.logger.debug("\n") # Add empty lines between requests in debug
  208. self.logger.info("%s request at %s received",
  209. environ["REQUEST_METHOD"], environ["PATH_INFO"])
  210. headers = pprint.pformat(self.headers_log(environ))
  211. self.logger.debug("Request headers:\n%s", headers)
  212. # Strip base_prefix from request URI
  213. base_prefix = self.configuration.get("server", "base_prefix")
  214. if environ["PATH_INFO"].startswith(base_prefix):
  215. environ["PATH_INFO"] = environ["PATH_INFO"][len(base_prefix):]
  216. elif self.configuration.get("server", "can_skip_base_prefix"):
  217. self.logger.debug(
  218. "Prefix already stripped from path: %s", environ["PATH_INFO"])
  219. else:
  220. # Request path not starting with base_prefix, not allowed
  221. self.logger.debug(
  222. "Path not starting with prefix: %s", environ["PATH_INFO"])
  223. return response(*NOT_ALLOWED)
  224. # Sanitize request URI
  225. environ["PATH_INFO"] = storage.sanitize_path(
  226. unquote(environ["PATH_INFO"]))
  227. self.logger.debug("Sanitized path: %s", environ["PATH_INFO"])
  228. path = environ["PATH_INFO"]
  229. # Get function corresponding to method
  230. function = getattr(self, "do_%s" % environ["REQUEST_METHOD"].upper())
  231. # Ask authentication backend to check rights
  232. authorization = environ.get("HTTP_AUTHORIZATION", None)
  233. if authorization and authorization.startswith("Basic"):
  234. authorization = authorization[len("Basic"):].strip()
  235. user, password = self.decode(base64.b64decode(
  236. authorization.encode("ascii")), environ).split(":", 1)
  237. else:
  238. user = environ.get("REMOTE_USER")
  239. password = None
  240. # If "/.well-known" is not available, clients query "/"
  241. if path == "/.well-known" or path.startswith("/.well-known/"):
  242. return response(client.NOT_FOUND, {})
  243. if user and not storage.is_safe_path_component(user):
  244. # Prevent usernames like "user/calendar.ics"
  245. self.logger.info("Refused unsafe username: %s", user)
  246. is_authenticated = False
  247. else:
  248. is_authenticated = self.is_authenticated(user, password)
  249. is_valid_user = is_authenticated or not user
  250. # Create principal collection
  251. if user and is_authenticated:
  252. principal_path = "/%s/" % user
  253. if self.authorized(user, principal_path, "w"):
  254. with self.Collection.acquire_lock("r", user):
  255. principal = next(
  256. self.Collection.discover(principal_path, depth="1"),
  257. None)
  258. if not principal:
  259. with self.Collection.acquire_lock("w", user):
  260. self.Collection.create_collection(principal_path)
  261. # Verify content length
  262. content_length = int(environ.get("CONTENT_LENGTH") or 0)
  263. if content_length:
  264. max_content_length = self.configuration.getint(
  265. "server", "max_content_length")
  266. if max_content_length and content_length > max_content_length:
  267. self.logger.debug(
  268. "Request body too large: %d", content_length)
  269. return response(client.REQUEST_ENTITY_TOO_LARGE)
  270. if is_valid_user:
  271. try:
  272. status, headers, answer = function(environ, path, user)
  273. except socket.timeout:
  274. return response(client.REQUEST_TIMEOUT)
  275. else:
  276. status, headers, answer = NOT_ALLOWED
  277. if (status, headers, answer) == NOT_ALLOWED and not (
  278. user and is_authenticated):
  279. # Unknown or unauthorized user
  280. self.logger.info("%s refused" % (user or "Anonymous user"))
  281. status = client.UNAUTHORIZED
  282. realm = self.configuration.get("server", "realm")
  283. headers = {
  284. "WWW-Authenticate":
  285. "Basic realm=\"%s\"" % realm}
  286. answer = None
  287. # Set content length
  288. if answer:
  289. self.logger.debug("Response content:\n%s", answer)
  290. answer = answer.encode(self.encoding)
  291. accept_encoding = [
  292. encoding.strip() for encoding in
  293. environ.get("HTTP_ACCEPT_ENCODING", "").split(",")
  294. if encoding.strip()]
  295. if "gzip" in accept_encoding:
  296. zcomp = zlib.compressobj(wbits=16 + zlib.MAX_WBITS)
  297. answer = zcomp.compress(answer) + zcomp.flush()
  298. headers["Content-Encoding"] = "gzip"
  299. headers["Content-Length"] = str(len(answer))
  300. # Add extra headers set in configuration
  301. if self.configuration.has_section("headers"):
  302. for key in self.configuration.options("headers"):
  303. headers[key] = self.configuration.get("headers", key)
  304. return response(status, headers, answer)
  305. def _access(self, user, path, permission, item=None):
  306. """Check if ``user`` can access ``path`` or the parent collection.
  307. ``permission`` must either be "r" or "w".
  308. If ``item`` is given, only access to that class of item is checked.
  309. """
  310. path = storage.sanitize_path(path)
  311. parent_path = storage.sanitize_path(
  312. "/%s/" % posixpath.dirname(path.strip("/")))
  313. allowed = False
  314. if not item or isinstance(item, self.Collection):
  315. allowed |= self.authorized(user, path, permission)
  316. if not item or not isinstance(item, self.Collection):
  317. allowed |= self.authorized(user, parent_path, permission)
  318. return allowed
  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.Collection.acquire_lock("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.Collection.acquire_lock("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.Collection.acquire_lock("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.Collection.acquire_lock("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.Collection.acquire_lock("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.Collection.acquire_lock("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.Collection.acquire_lock("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.Collection.acquire_lock("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. new_item = parent_item.upload(href, items[0])
  526. headers = {"ETag": new_item.etag}
  527. return client.CREATED, headers, None
  528. def do_REPORT(self, environ, path, user):
  529. """Manage REPORT request."""
  530. if not self._access(user, path, "w"):
  531. return NOT_ALLOWED
  532. content = self._read_content(environ)
  533. with self.Collection.acquire_lock("r", user):
  534. item = next(self.Collection.discover(path), None)
  535. if not self._access(user, path, "w", item):
  536. return NOT_ALLOWED
  537. if not item:
  538. return client.NOT_FOUND, {}, None
  539. if isinstance(item, self.Collection):
  540. collection = item
  541. else:
  542. collection = item.collection
  543. headers = {"Content-Type": "text/xml"}
  544. answer = xmlutils.report(path, content, collection)
  545. return client.MULTI_STATUS, headers, answer