Skip to content

Commit

Permalink
Merge branch 'luite-master'
Browse files Browse the repository at this point in the history
Conflicts:
	HTTP.cabal
  • Loading branch information
hsenag committed Dec 18, 2014
2 parents 11e4161 + c038fb8 commit 4ee2ff3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
12 changes: 6 additions & 6 deletions HTTP.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Library

-- note the test harness constraints should be kept in sync with these
-- where dependencies are shared
Build-depends: base >= 4.3.0.0 && < 4.8, parsec >= 2.0 && < 3.2
Build-depends: base >= 4.3.0.0 && < 4.9, parsec >= 2.0 && < 3.2
Build-depends: array >= 0.3.0.2 && < 0.6, old-time >= 1.0.0.0 && < 1.2, bytestring >= 0.9.1.5 && < 0.11

Extensions: FlexibleInstances
Expand Down Expand Up @@ -141,9 +141,9 @@ Test-Suite test
httpd-shed >= 0.4 && < 0.5,
mtl >= 1.1.1.0 && < 2.3,
bytestring >= 0.9.1.5 && < 0.11,
deepseq >= 1.3.0.0 && < 1.4,
deepseq >= 1.3.0.0 && < 1.5,
pureMD5 >= 0.2.4 && < 2.2,
base >= 4.3.0.0 && < 4.8,
base >= 4.3.0.0 && < 4.9,
split >= 0.1.3 && < 0.3,
test-framework >= 0.2.0 && < 0.9,
test-framework-hunit >= 0.3.0 && <0.4
Expand All @@ -158,15 +158,15 @@ Test-Suite test
build-depends:
case-insensitive >= 0.4.0.1 && < 1.3,
http-types >= 0.8.0 && < 0.9,
wai >= 2.1.0 && < 2.2,
warp >= 2.1.0 && < 2.2
wai >= 2.1.0 && < 3.1,
warp >= 2.1.0 && < 3.1

if flag(conduit10)
build-depends:
conduit >= 1.0.8 && < 1.1
else
build-depends:
conduit >= 1.1 && < 1.2,
conduit >= 1.1 && < 1.3,
conduit-extra >= 1.1 && < 1.2


35 changes: 26 additions & 9 deletions test/Httpd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import Control.Arrow ( (***) )
import Control.DeepSeq
import Control.Monad
import Control.Monad.Trans ( liftIO )
import Data.ByteString as B ( empty, concat, length, ByteString )
import Data.ByteString.Char8 as BC ( pack, unpack )
import Data.ByteString.Lazy.Char8 as BLC ( pack )
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString.Lazy.Char8 as BLC
#ifdef WARP_TESTS
import qualified Data.CaseInsensitive as CI ( mk, original )
import qualified Data.CaseInsensitive as CI
#endif
import Data.Maybe ( fromJust )
import Network.URI ( URI, parseRelativeReference )
Expand All @@ -43,13 +44,13 @@ import qualified Network.Shed.Httpd as Shed
, reqMethod, reqURI, reqHeaders, reqBody
)
#ifdef WARP_TESTS
#if !MIN_VERSION_wai(3,0,0)
import qualified Data.Conduit.Lazy as Warp
( lazyConsume )
#endif

import qualified Network.HTTP.Types as Warp
( Status(..) )
import qualified Network.Wai as Warp
( Request(requestMethod, requestHeaders, rawPathInfo, requestBody)
, responseLBS )
import qualified Network.Wai.Handler.Warp as Warp
( runSettingsSocket, defaultSettings, setPort )
#endif
Expand Down Expand Up @@ -117,10 +118,17 @@ warp ipv6 port handler = do
setSocketOption sock ReuseAddr 1
bind sock (addrAddress addri)
listen sock 5
#if MIN_VERSION_wai(3,0,0)
Warp.runSettingsSocket (Warp.setPort port Warp.defaultSettings) sock $ \warpRequest warpRespond -> do
request <- requestFromWarp warpRequest
response <- handler request
warpRespond (responseToWarp response)
#else
Warp.runSettingsSocket (Warp.setPort port Warp.defaultSettings) sock $ \warpRequest -> do
request <- requestFromWarp warpRequest
response <- handler request
return (responseToWarp response)
#endif
where
responseToWarp (Response status hdrs body) =
Warp.responseLBS
Expand All @@ -131,8 +139,17 @@ warp ipv6 port handler = do
headerFromWarp (name, value) =
(BC.unpack (CI.original name), BC.unpack value)
requestFromWarp request = do
body <- Warp.lazyConsume (Warp.requestBody request)
#if MIN_VERSION_wai(3,0,1)
body <- fmap BLC.unpack $ Warp.strictRequestBody request
#else
# if MIN_VERSION_wai(1,4,1)
body <- fmap BLC.unpack $ Warp.lazyRequestBody request
# else
body <- fmap (BC.unpack . B.concat) $
Warp.lazyConsume (Warp.requestBody request)
# endif
body `deepseq` return ()
#endif
return $
Request
{
Expand All @@ -141,6 +158,6 @@ warp ipv6 port handler = do
BC.unpack . Warp.rawPathInfo $
request,
reqHeaders = map headerFromWarp (Warp.requestHeaders request),
reqBody = BC.unpack (B.concat body)
reqBody = body
}
#endif

0 comments on commit 4ee2ff3

Please sign in to comment.