This repository was archived by the owner on Mar 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
This repository was archived by the owner on Mar 30, 2022. It is now read-only.
propFind method with empty properties returns 400 #17
Copy link
Copy link
Open
Labels
Description
Hi, I'm using DAV Client as adapter with Gaufrette and when I make a PROPFIND request with no properties the server send a 400 response. This happens with functions like this one:
private function isDir($directory) {
if ('/' === $directory) {
return true;
}
$data = $this->getClient()->propFind($directory, [], 0);
return !empty($data) && $data['{DAV:}resourcetype']->is('{DAV:}collection');
}
I've been testing the resulting request and because the prop tags are empty the server returns a 400 response. In the other hand if we replace the prop tag with allprop tag it goes as expected. I make a work around and patch the code in the mean time like this:
public function propFind($url, array $properties, $depth = 0) {
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = true;
$root = $dom->createElementNS('DAV:', 'd:propfind');
// My code
// -----------
if (count($properties) > 0) {
$prop = $dom->createElement('d:prop');
foreach($properties as $property) {
list(
$namespace,
$elementName
) = XMLUtil::parseClarkNotation($property);
if ($namespace === 'DAV:') {
$element = $dom->createElement('d:'.$elementName);
} else {
$element = $dom->createElementNS($namespace, 'x:'.$elementName);
}
$prop->appendChild( $element );
}
} else {
$prop = $dom->createElement('d:allprop');
}
// -------
$dom->appendChild($root)->appendChild( $prop );
$body = $dom->saveXML();
$url = $this->getAbsoluteUrl($url);
$request = new HTTP\Request('PROPFIND', $url, [
'Depth' => $depth,
'Content-Type' => 'application/xml'
], $body);
$response = $this->send($request);
if ((int)$response->getStatus() >= 400) {
throw new Exception('HTTP error: ' . $response->getStatus());
}
$result = $this->parseMultiStatus($response->getBodyAsString());
// If depth was 0, we only return the top item
if ($depth===0) {
reset($result);
$result = current($result);
return isset($result[200])?$result[200]:[];
}
$newResult = [];
foreach($result as $href => $statusList) {
$newResult[$href] = isset($statusList[200])?$statusList[200]:[];
}
return $newResult;
}
I don't like this solution and looking a way round to solve this issue.
Thanks!