diff --git a/calendar/inc/class.calendar_groupdav.inc.php b/calendar/inc/class.calendar_groupdav.inc.php index 8106c36e04..1cd8849707 100644 --- a/calendar/inc/class.calendar_groupdav.inc.php +++ b/calendar/inc/class.calendar_groupdav.inc.php @@ -774,6 +774,8 @@ class calendar_groupdav extends groupdav_handler if ($schedule_tag_match !== $schedule_tag) { if ($this->debug) error_log(__METHOD__."(,,$user) schedule_tag missmatch: given '$schedule_tag_match' != '$schedule_tag'"); + // honor Prefer: return=representation for 412 too (no need for client to explicitly reload) + $this->check_return_representation($options, $id, $user); return '412 Precondition Failed'; } } @@ -891,6 +893,8 @@ class calendar_groupdav extends groupdav_handler } elseif ($cal_id === 0) // etag failure { + // honor Prefer: return=representation for 412 too (no need for client to explicitly reload) + $this->check_return_representation($options, $id, $user); return '412 Precondition Failed'; } else diff --git a/phpgwapi/inc/class.groupdav_handler.inc.php b/phpgwapi/inc/class.groupdav_handler.inc.php index 1688453c67..d3f15cdea8 100644 --- a/phpgwapi/inc/class.groupdav_handler.inc.php +++ b/phpgwapi/inc/class.groupdav_handler.inc.php @@ -309,6 +309,8 @@ abstract class groupdav_handler if ($this->http_if_match !== $etag) { if ($this->debug) error_log(__METHOD__."($method,path=$options[path],$id) HTTP_IF_MATCH='$_SERVER[HTTP_IF_MATCH]', etag='$etag': 412 Precondition failed".array2string($entry)); + // honor Prefer: return=representation for 412 too (no need for client to explicitly reload) + $this->check_return_representation($options, $id); return '412 Precondition Failed'; } } @@ -327,6 +329,8 @@ abstract class groupdav_handler if ($method == 'PUT' && ($if_none_match == '*' || $if_none_match == $etag)) { if ($this->debug) error_log(__METHOD__."($method,,$id) HTTP_IF_NONE_MATCH='$_SERVER[HTTP_IF_NONE_MATCH]', etag='$etag': 412 Precondition failed"); + // honor Prefer: return=representation for 412 too (no need for client to explicitly reload) + $this->check_return_representation($options, $id); return '412 Precondition Failed'; } } @@ -344,7 +348,8 @@ abstract class groupdav_handler */ public function check_return_representation($options, $id, $user=null) { - if (isset($_SERVER['HTTP_PREFER']) && in_array('return=representation', explode(',', $_SERVER['HTTP_PREFER']))) + //error_log(__METHOD__."(, $id, $user) start ".function_backtrace()); + if (isset($_SERVER['HTTP_PREFER']) && in_array('return=representation', preg_split('/, ?/', $_SERVER['HTTP_PREFER']))) { if ($_SERVER['REQUEST_METHOD'] == 'POST') { @@ -355,6 +360,11 @@ abstract class groupdav_handler } header('Content-Location: '.$location); } + + // remove If-Match or If-None-Match headers, otherwise HTTP status 412 goes into endless loop! + unset($_SERVER['HTTP_IF_MATCH']); + unset($_SERVER['HTTP_IF_NONE_MATCH']); + if (($ret = $this->get($options, $id ? $id : $this->new_id, $user)) && !empty($options['data'])) { header('Content-Length: '.$this->groupdav->bytes($options['data'])); @@ -362,6 +372,7 @@ abstract class groupdav_handler echo $options['data']; } } + //error_log(__METHOD__."(, $id, $user) returning ".array2string($ret)); return $ret; }