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:
Andrew McMillan 2010-08-29 13:01:56 +12:00
parent f0f708ec38
commit 64f20edaab
2 changed files with 36 additions and 0 deletions

View File

@ -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 */

View File

@ -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.
*/