From 850baa0dbfa7decf84f10236573eb1e86152a19e Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Wed, 5 Oct 2011 09:41:00 +0200 Subject: [PATCH] Support gzip/deflate/compress encoding of incoming entity for PUT etc. --- inc/CalDAVRequest.php | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/inc/CalDAVRequest.php b/inc/CalDAVRequest.php index 8b0dec7b..4ee230fd 100644 --- a/inc/CalDAVRequest.php +++ b/inc/CalDAVRequest.php @@ -115,7 +115,33 @@ class CalDAVRequest if ( !isset($this->options['allow_by_email']) ) $this->options['allow_by_email'] = false; if ( !isset($c->raw_post) ) $c->raw_post = file_get_contents( 'php://input'); - $this->raw_post = $c->raw_post; + if ( isset($_SERVER['HTTP_CONTENT_ENCODING']) ) { + @dbg_error_log('caldav', 'Content-Encoding: %s', $_SERVER['HTTP_CONTENT_ENCODING'] ); + switch( $_SERVER['HTTP_CONTENT_ENCODING'] ) { + case 'gzip': + $this->raw_post = gzdecode($c->raw_post); + break; + case 'deflate': + $this->raw_post = gzinflate($c->raw_post); + break; + case 'compress': + $this->raw_post = gzuncompress($c->raw_post); + break; + default: + if ( ! ini_get('open_basedir') && (isset($c->dbg['ALL']) || isset($c->dbg['caldav'])) ) { + $fh = fopen('/tmp/raw_post','w'); + if ( $fh ) { + fwrite($fh,$request->raw_post); + fclose($fh); + } + } + $this->PreconditionFailed(402, 'content-encoding', 'This server does not presently support content encoded with "%s"', $_SERVER['HTTP_CONTENT_ENCODING']); + } + $c->raw_post = $this->raw_post; + } + else { + $this->raw_post = $c->raw_post; + } if ( isset($debugging) && isset($_GET['method']) ) { $_SERVER['REQUEST_METHOD'] = $_GET['method']; @@ -139,11 +165,6 @@ class CalDAVRequest } $this->user_agent = ((isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "Probably Mulberry")); - if ( isset($_SERVER['HTTP_CONTENT_ENCODING']) ) { - @dbg_error_log('caldav', 'Content-Encoding: %s', $_SERVER['HTTP_CONTENT_ENCODING']); - $this->PreconditionFailed(402, 'content-encoding', 'This server does not presently support encoded content.'); - } - /** * A variety of requests may set the "Depth" header to control recursion */ @@ -1091,11 +1112,11 @@ EOSQL; * @param string $precondition The namespaced precondition tag. * @param string $explanation An optional text explanation for the failure. */ - function PreconditionFailed( $status, $precondition, $explanation = '') { + function PreconditionFailed( $status, $precondition, $explanation = '', $xmlns='DAV:') { $xmldoc = sprintf(' - + <%s/>%s -', str_replace('DAV::', '', $precondition), $explanation ); +', $xmlns, str_replace($xmlns.':', '', $precondition), $explanation ); $this->DoResponse( $status, $xmldoc, 'text/xml; charset="utf-8"' ); exit(0); // Unecessary, but might clarify things