RFC 4918 sections 9.8.5 and 9.9.4 say the server should return 403 when
the source and destination are the same. Overwriting the destination
deletes the source, so LocalFileSystem lost the file.
Check this in the shared handler so every backend gets it.
The previous code failed to properly handle PROPFIND with an empty request body
(RFC 4918 section 9.1) for XML content type requests.
Refactor the logic to always consider PROPFIND requests with empty request
bodies as "allprop" requests, regardless of content type.
There is no need to worry about the request's content type if the request body
is empty anyway, so only parse if we know it is not.
NewPropFindResponse uses callbacks to lazily build the response.
However, some props are static: they don't require any processing
to generate. Add a small helper to reduce boilerplate a bit.
Backends will need some way to signal that a precondition error occurred
(and specifying which one) without causing the server to return a 500.
This commit adds an exported function to create a specific error for
this. The existing error handling routine is slightly adapted to handle
this error in such a way that it returns the desired result.
Usage would be something like:
```
return "", carddav.NewPreconditionError(carddav.PreconditionNoUIDConflict)
```
which triggers the following HTTP response:
```
HTTP/1.1 409 Conflict.
Content-Type: text/xml; charset=utf-8.
Date: Thu, 10 Mar 2022 10:28:56 GMT.
Content-Length: 141.
Connection: close.
<?xml version="1.0" encoding="UTF-8"?>
<error xmlns="DAV:"><no-uid-conflict
xmlns="urn:ietf:params:xml:ns:carddav"></no-uid-conflict></error>
```
This response gets correctly recognized by e.g. Evolution (though it's
handling is not great).
The added error type is generic enough to be used for other stuff also.
As it is not exported (internal package), new functions for creating
such errors would have to be added.