mirror of
https://gitlab.com/davical-project/davical.git
synced 2026-03-14 08:10:13 +00:00
Coerce the content-type on PUT.
It seems that failing to correctly set the content-type header on PUT is a common error.
This commit is contained in:
parent
f0f708ec38
commit
64f20edaab
@ -81,6 +81,7 @@ switch ( $request->method ) {
|
||||
case 'HEAD': include('caldav-GET.php'); break;
|
||||
case 'PROPPATCH': include('caldav-PROPPATCH.php'); break;
|
||||
case 'PUT':
|
||||
$request->CoerceContentType();
|
||||
switch( $request->content_type ) {
|
||||
case 'text/calendar':
|
||||
/** use original DAViCal 'PUT' code which will be rewritten */
|
||||
|
||||
@ -852,6 +852,41 @@ EOSQL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Coerces the Content-type of the request into something valid/appropriate
|
||||
*/
|
||||
function CoerceContentType() {
|
||||
if ( isset($this->content_type) ) {
|
||||
$type = explode( '/', $this->content_type, 2);
|
||||
if ( $type[0] == 'text' ) return;
|
||||
}
|
||||
|
||||
/** Null (or peculiar) content-type supplied so we have to try and work it out... */
|
||||
$first_word = trim(substr( $this->raw_post, 0, 30));
|
||||
$first_word = strtoupper( preg_replace( '/\s.*/s', '', $first_word ) );
|
||||
switch( $first_word ) {
|
||||
case '<?XML':
|
||||
dbg_error_log( 'LOG WARNING', 'Application sent content-type of "%s" instead of "text/xml"',
|
||||
(isset($this->content_type)?$this->content_type:'(null)') );
|
||||
$this->content_type = 'text/xml';
|
||||
break;
|
||||
case 'BEGIN:VCALENDAR':
|
||||
dbg_error_log( 'LOG WARNING', 'Application sent content-type of "%s" instead of "text/calendar"',
|
||||
(isset($this->content_type)?$this->content_type:'(null)') );
|
||||
$this->content_type = 'text/calendar';
|
||||
break;
|
||||
case 'BEGIN:VCARD':
|
||||
dbg_error_log( 'LOG WARNING', 'Application sent content-type of "%s" instead of "text/vcard"',
|
||||
(isset($this->content_type)?$this->content_type:'(null)') );
|
||||
$this->content_type = 'text/vcard';
|
||||
break;
|
||||
default:
|
||||
dbg_error_log( 'LOG NOTICE', 'Unusual content-type of "%s" and first word of content is "%s"',
|
||||
(isset($this->content_type)?$this->content_type:'(null)'), $first_word );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the URL referenced by this request points at a collection.
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user