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

View File

@ -132,6 +132,10 @@ public class WebDavResource {
client = parent.client; 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) { public WebDavResource(WebDavResource parent, String member, String ETag) {
this(parent, member); this(parent, member);
properties.put(Property.ETAG, ETag); properties.put(Property.ETAG, ETag);

View File

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

View File

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