var roboHydraHeadDAV = require("../headdav");
exports.getBodyParts = function(conf) {
return {
heads: [
/* base URL, provide default DAV here */
new RoboHydraHeadDAV({ path: "/dav/" }),
/* principal URL */
new RoboHydraHeadDAV({
path: "/dav/principals/users/test",
handler: function(req,res,next) {
if (req.method == "PROPFIND" && req.rawBody.toString().match(/home-set/)) {
res.statusCode = 207;
res.write('\\
\
\
' + req.url + ' \
\
\
\
/dav/addressbooks/test\
\
\
/dav/calendars/test/\
\
\
HTTP/1.1 200 OK\
\
\
\
');
}
}
}),
/* address-book home set */
new RoboHydraHeadDAV({
path: "/dav/addressbooks/test/",
handler: function(req,res,next) {
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('\\
\
\
/dav/addressbooks/test/useless-member\
\
\
\
\
HTTP/1.1 200 OK\
\
\
\
/dav/addressbooks/test/default.vcf/\
\
\
\
\
\
\
Default Address Book\
\
HTTP/1.1 200 OK\
\
\
\
');
}
}
}),
/* calendar home set */
new RoboHydraHeadDAV({
path: "/dav/calendars/test/",
handler: function(req,res,next) {
if (req.method == "PROPFIND" && req.rawBody.toString().match(/addressbook-description/)) {
res.statusCode = 207;
res.write('\\
\
\
/dav/calendars/test/shared.forbidden\
\
\
\
\
HTTP/1.1 403 Forbidden\
\
\
\
/dav/calendars/test/private.ics\
\
\
\
\
\
\
Private Calendar\
This is my private calendar.\
\
HTTP/1.1 200 OK\
\
\
\
/dav/calendars/test/work.ics\
\
\
\
\
\
\
\
\
\
Work Calendar\
0xFF00FF\
\
HTTP/1.1 200 OK\
\
\
\
');
}
}
}),
/* non-existing file */
new RoboHydraHeadDAV({
path: "/dav/collection/new.file",
handler: function(req,res,next) {
if (req.method == "PUT") {
if (req.headers['if-match']) /* can't overwrite new file */
res.statusCode = 412;
else {
res.statusCode = 201;
res.headers["ETag"] = "has-just-been-created";
}
} else if (req.method == "DELETE")
res.statusCode = 404;
}
}),
/* existing file */
new RoboHydraHeadDAV({
path: "/dav/collection/existing.file",
handler: function(req,res,next) {
if (req.method == "PUT") {
if (req.headers['if-none-match']) /* requested "don't overwrite", but this file exists */
res.statusCode = 412;
else {
res.statusCode = 204;
res.headers["ETag"] = "has-just-been-updated";
}
} else if (req.method == "DELETE")
res.statusCode = 204;
}
}),
/* address-book multiget */
new RoboHydraHeadDAV({
path: "/dav/addressbooks/default.vcf/",
handler: function(req,res,next) {
if (req.method == "REPORT" && req.rawBody.toString().match(/addressbook-multiget[\s\S]+[\s\S]+/m)) {
res.statusCode = 207;
res.write('\\
\
\
/dav/addressbooks/default.vcf/1.vcf\
\
\
\
BEGIN:VCARD\
VERSION:3.0\
NICKNAME:MULTIGET1\
UID:1\
END:VCARD\
\
\
HTTP/1.1 200 OK\
\
\
\
/dav/addressbooks/default.vcf/2.vcf\
\
\
\
BEGIN:VCARD\
VERSION:3.0\
NICKNAME:MULTIGET2\
UID:2\
END:VCARD\
\
\
HTTP/1.1 200 OK\
\
\
\
');
}
}
}),
]
};
};