packages feed

hsp-0.2: HTTP/Response.hs

-----------------------------------------------------------------------------
-- |
-- Module      :  HTTP.Response
-- Copyright   :  (c) Andreas Farre, Niklas Broberg, 2004
-- License     :  BSD-style (see the file LICENSE.txt)
-- 
-- Maintainer  :  Andreas Farre, d00farre@dtek.chalmers.se,
--		  Niklas Broberg, d00nibro@dtek.chalmers.se
-- Stability   :  experimental
-- Portability :  portable
--
-- Datatypes representing the concept of an HTTP response.
-----------------------------------------------------------------------------
module HTTP.Response (
	-- * Datatypes
	  Response(..)
	, HTTPVersion(..)
	, StatusCode(..)
	, Reason -- (..) will be a datatype soon, no?
	, Header(..)
	, MessageBody(..)
	) where

import HTTP.Common
import HTTP.Util

import Data.Char ( intToDigit )

data Response 
    = Response {
                respVersion :: HTTPVersion,
                respStatus  :: StatusCode,
                respReason  :: Reason,
                respHeaders :: [Header],
                respBody    :: MessageBody
               } 

instance Show Response where
    showsPrec _ resp
	=  shows (respVersion resp) .
	      showsSpace .
	      shows (respStatus resp) .
	      showsSpace .
	      showString (respReason resp) .
	      showsCRLF .
	      shows (respHeaders resp) .
	      showsCRLF .
	      shows (respBody resp) .
	      showsCRLF .
	      showsCRLF


newtype StatusCode 
    = StatusCode (Int, Int, Int)

instance Show StatusCode where
    show (StatusCode (a,b,c))
         = map intToDigit [a,b,c]

type Reason = String