cvs: pear /HTTP_WebDAV_Server Server.php

From: Date: Tue, 05 Apr 2005 22:51:11 +0000
Subject: cvs: pear /HTTP_WebDAV_Server Server.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-30940@lists.php.net to get a copy of this message
hholzgra Tue Apr 5 18:51:11 2005 EDT Modified files: /pear/HTTP_WebDAV_Server Server.php Log: make sure collections end in trailing slash, redirect to '/' if no path given http://cvs.php.net/diff.php/pear/HTTP_WebDAV_Server/Server.php?r1=1.27&r2=1.28&ty=u Index: pear/HTTP_WebDAV_Server/Server.php diff -u pear/HTTP_WebDAV_Server/Server.php:1.27 pear/HTTP_WebDAV_Server/Server.php:1.28 --- pear/HTTP_WebDAV_Server/Server.php:1.27 Sat Apr 2 06:10:34 2005 +++ pear/HTTP_WebDAV_Server/Server.php Tue Apr 5 18:51:09 2005 @@ -17,7 +17,7 @@ // | Christian Stocker <chregu@bitflux.ch> | // +----------------------------------------------------------------------+ // -// $Id: Server.php,v 1.27 2005/04/02 11:10:34 hholzgra Exp $ +// $Id: Server.php,v 1.28 2005/04/05 22:51:09 hholzgra Exp $ // require_once "HTTP/WebDAV/Tools/_parse_propfind.php"; require_once "HTTP/WebDAV/Tools/_parse_proppatch.php"; @@ -39,6 +39,22 @@ // {{{ Member Variables /** + * complete URI for this request + * + * @var string + */ + var $uri; + + + /** + * base URI for this request + * + * @var string + */ + var $base_uri; + + + /** * URI path for this request * * @var string @@ -108,6 +124,13 @@ */ function ServeRequest() { + // default uri is the complete request uri + $uri = (@$_SERVER["HTTPS"] === "on" ? "https:" : "http:"); + $uri.= "//$_SERVER[HTTP_HOST]$_SERVER[SCRIPT_NAME]"; + + $this->base_uri = $uri; + $this->uri = $uri . $_SERVER[PATH_INFO]"; + // identify ourselves if (empty($this->dav_powered_by)) { header("X-Dav-Powered-By: PHP class: ".get_class($this)); @@ -137,7 +160,11 @@ } // set path - $this->path = $this->_urldecode(!empty($_SERVER["PATH_INFO"]) ? $_SERVER["PATH_INFO"] : "/"); + $this->path = $this->_urldecode($_SERVER["PATH_INFO"]); + if (!strlen($this->path)) { + header("Location: ".$this->base_uri."/"); + exit; + } if(ini_get("magic_quotes_gpc")) { $this->path = stripslashes($this->path); } @@ -605,8 +632,7 @@ echo " <D:response $ns_defs>\n"; - $href = $_SERVER['SCRIPT_NAME'] . $path; - //TODO make sure collection resource pathes end in a trailing slash + $href = $this->_slashify($_SERVER['SCRIPT_NAME'] . $path); echo " <D:href>$href</D:href>\n"; @@ -1685,9 +1711,7 @@ foreach($this->_if_header_uris as $uri => $conditions) { if ($uri == "") { - // default uri is the complete request uri - $uri = (@$_SERVER["HTTPS"] === "on" ? "https:" : "http:"); - $uri.= "//$_SERVER[HTTP_HOST]$_SERVER[SCRIPT_NAME]$_SERVER[PATH_INFO]"; + $uri = $this->uri; } // all must match $state = true; @@ -1880,6 +1904,19 @@ return utf8_encode($text); } } + + /** + * Slashify - make sure path ends in a slash + * + * @param string directory path + * @returns string directory path wiht trailing slash + */ + function _slashify($path) { + if ($path[strlen($path)-1] != '/') { + $path = $path."/"; + } + return $path; + } } /*

« previous php.pear.cvs (#30940) next »