'''
httpResponse.py

Copyright 2006 Andres Riancho

This file is part of w3af, w3af.sourceforge.net .

w3af is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 2 of the License.

w3af is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with w3af; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

'''
from core.data.parsers.urlParser import *

class httpResponse:
	
	def __init__( self, code, read , info, geturl, originalUrl, msg='OK', id=None):
		self._code = code
		self._body = read
		self._headers = info
		self._realurl = uri2url( originalUrl )
		self._uri = originalUrl
		self._redirectedURL = geturl
		self._msg = msg
		# A unique id identifier for the response
		self.id = id
	
	def getRedirURL( self ): return self._redirectedURL
	def getCode( self ): return self._code
	def getBody( self ): return self._body
	def getHeaders( self ): return self._headers
	def getURL( self ): return self._realurl
	def getURI( self ): return self._uri
	
	def setRedirURL( self, ru ): self._redirectedURL = ru
	def setCode( self, code ): self._code = code
	def setBody( self, body): self._body = body
	def setHeaders( self, headers ): self._headers = headers
	def setURL( self, url ): self._realurl = url
	def setURI( self, uri ): self._uri = uri

	def dump( self ):
		'''
		Return a DETAILED str representation of this HTTP response object.
		'''
		strRes = 'HTTP/1.1 ' + str(self._code) + ' ' + self._msg + '\n'
		for header in self._headers.keys():
			strRes += header + ': ' + self._headers[ header ] + '\n'
		strRes += '\n\n'
		strRes += self._body
		
		return strRes
		
