From 766e825f995715577e4b6873dd73553a8aaadedd Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Mon, 28 Jun 2010 08:39:39 +1200 Subject: [PATCH] Forece content-type in some circumstances. If the method is REPORT or PROPFIND it won't be valid if they didn't send XML, so assume they did, with a warning. Otherwise, if the content-type is XML, but they sent less than 7 bytes, assume that it has no content-type. --- inc/CalDAVRequest.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/inc/CalDAVRequest.php b/inc/CalDAVRequest.php index 4fad7ede..7ac2d7dd 100644 --- a/inc/CalDAVRequest.php +++ b/inc/CalDAVRequest.php @@ -163,9 +163,18 @@ class CalDAVRequest $_SERVER['REQUEST_METHOD'] = $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']; } $this->method = $_SERVER['REQUEST_METHOD']; - $this->content_type = (isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : null); - if ( preg_match( '{^(\S+/\S+)\s*(;.*)?$}', $this->content_type, $matches ) ) { - $this->content_type = $matches[1]; + if ( isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH'] > 7 ) { + $this->content_type = (isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : null); + if ( preg_match( '{^(\S+/\S+)\s*(;.*)?$}', $this->content_type, $matches ) ) { + $this->content_type = $matches[1]; + } + if ( $this->method == 'PROPFIND' || $this->method == 'REPORT' ) { + if ( !preg_match( '{^(text|application)/xml$}', $this->content_type ) ) { + dbg_error_log( "LOG request", 'Request is "%s" but client set content-type to "%s". Assuming they meant XML!', + $request->method, $this->content_type ); + $this->content_type = 'text/xml'; + } + } } $this->user_agent = ((isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "Probably Mulberry"));