hackMessageFlow  ::  Env ->  IO Response
hackMessageFlow req1=   do
     let httpreq1= http  req1
     let cookies= {-# SCC "getCookies" #-} getCookies  httpreq1

     (flowval , retcookies) <-  case lookup ( flow) cookies of
              Just fl -> return  (fl, [])
              Nothing  -> do
                     fl <- newFlow
                     return ( fl,  [( flow,  fl,  "/",(Just $ show $ 365*24*60*60))])

{-  for state persistence in cookies
     putStateCookie req1 cookies
     let retcookies= case getStateCookie req1 of
                                Nothing -> retcookies1
                                Just ck -> ck:retcookies1
-}

     let input=
           case  ( requestMethod req1, lookup  "Content-Type" httpreq1 )  of
              (POST,Just "application/x-www-form-urlencoded") -> urlDecode . unpack $ hackInput  req1
              (GET, _) -> urlDecode . queryString $ req1
              _ -> []

     let req = case retcookies of
          [] -> req1{http=  (input ++ cookies) ++ http req1}   -- !> "REQ"
          _  -> req1{http=(flow, flowval): ( input ++ cookies ) ++ http req1}   -- !> "REQ"


     (resp',th) <- msgScheduler  req


     let resp''= toResponse resp'
     let headers1= case retcookies of [] -> headers resp''; _ ->   (cookieHeaders retcookies)
     let resp =   resp''{status=200, headers= headers1 {-,("Content-Length",show $ B.length x) -}}

     return resp


------persistent state in cookies (not tested)
hackMessageFlow  ::  Env ->  IO Response
hackMessageFlow req1=   do
     let httpreq1= http  req1
     let cookies= {-# SCC "getCookies" #-} getCookies  httpreq1

     (flowval , retcookies) <-  case lookup ( flow) cookies of
              Just fl -> return  (fl, [])
              Nothing  -> do
                     fl <- newFlow
                     return ( fl,  [( flow,  fl,  "/",(Just $ show $ 365*24*60*60))])

{-  for state persistence in cookies
     putStateCookie req1 cookies
     let retcookies= case getStateCookie req1 of
                                Nothing -> retcookies1
                                Just ck -> ck:retcookies1
-}

     let input=
           case  ( requestMethod req1, lookup  "Content-Type" httpreq1 )  of
              (POST,Just "application/x-www-form-urlencoded") -> urlDecode . unpack $ hackInput  req1
              (GET, _) -> urlDecode . queryString $ req1
              _ -> []

     let req = case retcookies of
          [] -> req1{http=  (input ++ cookies) ++ http req1}   -- !> "REQ"
          _  -> req1{http=(flow, flowval): ( input ++ cookies ) ++ http req1}   -- !> "REQ"


     (resp',th) <- msgScheduler  req


     let resp''= toResponse resp'
     let headers1= case retcookies of [] -> headers resp''; _ ->   (cookieHeaders retcookies)
     let resp =   resp''{status=200, headers= headers1 {-,("Content-Length",show $ B.length x) -}}

     return resp


------persistent state in cookies (not tested)
hackMessageFlow req1=   do
     let httpreq1= http  req1
     let cookies= {-# SCC "getCookies" #-} getCookies  httpreq1

     (flowval , retcookies) <-  case lookup ( flow) cookies of
              Just fl -> return  (fl, [])
              Nothing  -> do
                     fl <- newFlow
                     return ( fl,  [( flow,  fl,  "/",(Just $ show $ 365*24*60*60))])

{-  for state persistence in cookies
     putStateCookie req1 cookies
     let retcookies= case getStateCookie req1 of
                                Nothing -> retcookies1
                                Just ck -> ck:retcookies1
-}

     let input=
           case  ( requestMethod req1, lookup  "Content-Type" httpreq1 )  of
              (POST,Just "application/x-www-form-urlencoded") -> urlDecode . unpack $ hackInput  req1
              (GET, _) -> urlDecode . queryString $ req1
              _ -> []

     let req = case retcookies of
          [] -> req1{http=  (input ++ cookies) ++ http req1}   -- !> "REQ"
          _  -> req1{http=(flow, flowval): ( input ++ cookies ) ++ http req1}   -- !> "REQ"


     (resp',th) <- msgScheduler  req


     let resp''= toResponse resp'
     let headers1= case retcookies of [] -> headers resp''; _ ->   (cookieHeaders retcookies)
     let resp =   resp''{status=200, headers= headers1 {-,("Content-Length",show $ B.length x) -}}

     return resp


------persistent state in cookies (not tested)