1
0
mirror of https://github.com/etesync/android synced 2024-11-22 16:08:13 +00:00

Always append trailing slash to address-book/calendar home set to avoid redirections

This commit is contained in:
rfc2822 2013-11-09 01:36:09 +01:00
parent c753dcaa8e
commit ab517bd87d
4 changed files with 17 additions and 9 deletions

View File

@ -153,7 +153,7 @@ public class QueryServerDialogFragment extends DialogFragment implements LoaderC
// (4/5) get address books
if (serverInfo.isCardDAV()) {
WebDavResource homeSetAddressBooks = new WebDavResource(principal, pathAddressBooks);
WebDavResource homeSetAddressBooks = new WebDavResource(principal, pathAddressBooks, true);
homeSetAddressBooks.propfind(Mode.MEMBERS_COLLECTIONS);
List<ServerInfo.ResourceInfo> addressBooks = new LinkedList<ServerInfo.ResourceInfo>();
@ -175,7 +175,7 @@ public class QueryServerDialogFragment extends DialogFragment implements LoaderC
// (5/5) get calendars
if (serverInfo.isCalDAV()) {
WebDavResource homeSetCalendars = new WebDavResource(principal, pathCalendars);
WebDavResource homeSetCalendars = new WebDavResource(principal, pathCalendars, true);
homeSetCalendars.propfind(Mode.MEMBERS_COLLECTIONS);
List<ServerInfo.ResourceInfo> calendars = new LinkedList<ServerInfo.ResourceInfo>();

View File

@ -132,6 +132,10 @@ public class WebDavResource {
client = parent.client;
}
public WebDavResource(WebDavResource parent, String member, boolean trailingSlash) {
this(parent, (trailingSlash && !member.endsWith("/")) ? (member + "/") : member);
}
public WebDavResource(WebDavResource parent, String member, String ETag) {
this(parent, member);
properties.put(Property.ETAG, ETag);

View File

@ -22,7 +22,7 @@ exports.getBodyParts = function(conf) {
<propstat>\
<prop>\
<CARD:addressbook-home-set xmlns:CARD="urn:ietf:params:xml:ns:carddav">\
<href>/dav/addressbooks/test/</href>\
<href>/dav/addressbooks/test</href>\
</CARD:addressbook-home-set>\
<CAL:calendar-home-set xmlns:CAL="urn:ietf:params:xml:ns:caldav">\
<href>/dav/calendars/test/</href>\
@ -39,9 +39,13 @@ exports.getBodyParts = function(conf) {
/* address-book home set */
new RoboHydraHeadDAV({
path: "/dav/addressbooks/test",
path: "/dav/addressbooks/test/",
handler: function(req,res,next) {
if (req.method == "PROPFIND" && req.rawBody.toString().match(/addressbook-description/)) {
if (!req.url.match(/\/$/)) {
res.statusCode = 302;
res.headers['location'] = "/dav/addressbooks/test/";
}
else if (req.method == "PROPFIND" && req.rawBody.toString().match(/addressbook-description/)) {
res.statusCode = 207;
res.write('\<?xml version="1.0" encoding="utf-8" ?>\
<multistatus xmlns="DAV:">\
@ -77,7 +81,7 @@ exports.getBodyParts = function(conf) {
/* calendar home set */
new RoboHydraHeadDAV({
path: "/dav/calendars/test",
path: "/dav/calendars/test/",
handler: function(req,res,next) {
if (req.method == "PROPFIND" && req.rawBody.toString().match(/addressbook-description/)) {
res.statusCode = 207;

View File

@ -90,12 +90,12 @@ public class WebDavResourceTest extends InstrumentationTestCase {
public void testPropfindHomeSets() throws IOException, HttpException {
WebDavResource dav = new WebDavResource(davCollection, "principals/users/test");
dav.propfind(HttpPropfind.Mode.HOME_SETS);
assertEquals("/dav/addressbooks/test/", dav.getAddressbookHomeSet());
assertEquals("/dav/addressbooks/test", dav.getAddressbookHomeSet());
assertEquals("/dav/calendars/test/", dav.getCalendarHomeSet());
}
public void testPropfindAddressBooks() throws IOException, HttpException {
WebDavResource dav = new WebDavResource(davCollection, "addressbooks/test");
WebDavResource dav = new WebDavResource(davCollection, "addressbooks/test", true);
dav.propfind(HttpPropfind.Mode.MEMBERS_COLLECTIONS);
assertEquals(2, dav.getMembers().size());
for (WebDavResource member : dav.getMembers()) {
@ -108,7 +108,7 @@ public class WebDavResourceTest extends InstrumentationTestCase {
}
public void testPropfindCalendars() throws IOException, HttpException {
WebDavResource dav = new WebDavResource(davCollection, "calendars/test");
WebDavResource dav = new WebDavResource(davCollection, "calendars/test", true);
dav.propfind(HttpPropfind.Mode.MEMBERS_COLLECTIONS);
assertEquals(3, dav.getMembers().size());
for (WebDavResource member : dav.getMembers()) {