Code Repositories xandikos / server-info
Support replying to server info token request. Jelmer Vernooń≥ 2 years ago
1 changed file(s) with 31 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
3535 from defusedxml.ElementTree import fromstring as xmlparse
3636 # Hmm, defusedxml doesn't have XML generation functions? :(
3737 from xml.etree import ElementTree as ET
38
39 from .server_info import ServerInfo
40
3841
3942 DEFAULT_ENCODING = 'utf-8'
4043 COLLECTION_RESOURCE_TYPE = '{DAV:}collection'
16831686 GetMethod(),
16841687 HeadMethod(),
16851688 ])
1689 self.server_info = ServerInfo()
1690 self.server_info.add_feature('{DAV:}class-1')
1691 self.server_info.add_feature('{DAV:}class-2')
1692 self.server_info.add_feature('{DAV:}class-3')
1693 self.server_info.add_feature('{DAV:}access-control')
1694 self.server_info.add_feature(
1695 '{urn:ietf:params:xml:ns:caldav}calendar-access')
1696 self.server_info.add_feature('{DAV:}extended-mkcol')
1697 self.server_info.add_feature('{DAV:}quota')
1698 self.server_info.add_feature('{DAV:}sync-collection')
1699 self.server_info.add_feature('{DAV:}add-member')
16861700
16871701 def _get_resource_from_environ(self, environ):
16881702 path = path_from_environ(environ, 'PATH_INFO')
17041718
17051719 def _get_dav_features(self, resource):
17061720 # TODO(jelmer): Support access-control
1707 return ['1', '2', '3', 'calendar-access', 'addressbook',
1721 return ['1', '2', '3', 'calendar-access', 'addressbook', 'server-info',
17081722 'extended-mkcol', 'add-member', 'sync-collection', 'quota']
17091723
17101724 def _get_allowed_methods(self, environ):
17191733 if environ.get('HTTP_EXPECT', '') != '':
17201734 start_response('417 Expectation Failed', [])
17211735 return []
1736
1737 # Server options. See
1738 # https://www.ietf.org/archive/id/draft-douglass-server-info-03.txt,
1739 # section 3.1.2.2
1740 if (environ['REQUEST_METHOD'] == 'OPTIONS' or
1741 environ.get('HTTP_SERVER_INFO_TOKEN', '')
1742 != self._server_info.token):
1743 def wrap_start_response(status, headers):
1744 # Just serve server-info at $SCRIPT_NAME location, and check
1745 # Accept header.
1746 server_info_hdr = "<%s>; rel=\"server-info\"; token=\"%s\"" % (
1747 environ['SCRIPT_NAME'], self._server_info.token)
1748 return start_response(
1749 status, headers + [('Link', server_info_hdr)])
1750 start_response = wrap_start_response
1751
17221752 method = environ['REQUEST_METHOD']
17231753 try:
17241754 do = self.methods[method]