<?php

class GenericHTTPResponse{
	var $HTTPResponse;
	var $HTTPDate;
	var $P3P;
	var $Connection;
	var $Encoding;
	var $TransferEncoding;
	var $ContentType;
	var $HTTPBody;

	function setHTTPResponse($HTTPResponse){
		$this->HTTPResponse=$HTTPResponse;
	}

	function getHTTPResponse(){
		return $this->HTTPResponse;
	}

	function setHTTPDate($HTTPDate){
		$this->HTTPDate=$HTTPDate;
	}

	function getHTTPDate(){
		return $this->HTTPDate;
	}

	function setP3P($P3P){
		$this->P3P=$P3P;
	}

	function getP3P(){
		return $this->P3P;
	}
	function setConnection($Connection){
		$this->Connection=$Connection;
	}

	function getConnection(){
		return $this->Connection;
	}
	function setEncoding($Encoding){
		$this->Encoding=$Encoding;
	}

	function getEncoding(){
		return $this->Encoding;
	}
	function setTransferEncoding($TransferEncoding){
		$this->TransferEncoding=$TransferEncoding;
	}

	function getTransferEncoding(){
		return $this->TransferEncoding;
	}
	function setContentType($ContentType){
		$this->ContentType=$ContentType;
	}

	function getContentType(){
		return $this->ContentType;
	}
	function setHTTPBody($HTTPBody){
		$this->HTTPBody=$HTTPBody;
	}

	function getHTTPBody(){
		return $this->HTTPBody;
	}

	function chewRESTResponse($response){
		/* This function assumes that a REST response has been returned... 
		and tries to parse it as such, returning the body of the REST response */

		$pieces= explode("\n",$response);	
		$body="";
		$prebody="false";
		for($i=0;$i<sizeof($pieces);$i++){
			if(preg_match("/^HTTP/",$pieces[$i])){
				$this->setHTTPResponse(trim($pieces[$i]));
			} else if(preg_match("/^Date\:/",$pieces[$i])){
				$this->setHTTPDate(trim($pieces[$i]));
			} else if(preg_match("/^P3P\:/",$pieces[$i])){
				$this->setP3P(trim($pieces[$i]));
			}	else if(preg_match("/^Connection\:/", $pieces[$i])){
				$this->setConnection(trim($pieces[$i]));
			} else if(preg_match("/^Encoding\:/", $pieces[$i])){
				$this->setEncoding(trim($pieces[$i]));
			} else if(preg_match("/^Transfer-Encoding\:/",$pieces[$i])){
				$this->setTransferEncoding(trim($pieces[$i]));
			} else if(preg_match("/^Content-Type/",$pieces[$i])){
				$this->setContentType(trim($pieces[$i]));
			} else if(preg_match("/^<\?xml/",$pieces[$i])){
				$prebody="true";	
			}
			if($prebody=="true"){
					$body=$body.$pieces[$i];
			}
			
		}
		$this->setHTTPBody($body);
	}
}
	
?>
