Skip to content

Commit

Permalink
Add upper bound for network and upgrade lts version (#22)
Browse files Browse the repository at this point in the history
Add upper bound for network and upgrade lts version
  • Loading branch information
creichert authored Jun 27, 2019
2 parents eece473 + 47eb677 commit e3db9cc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
5 changes: 3 additions & 2 deletions script/benchmark.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import Data.Monoid ((<>))
import Data.Text (Text, strip, stripPrefix, toCaseFold)
import Data.Text.Encoding (decodeUtf8)
import Network.HTTP.Types (hAuthorization, status200, status400)
import Network.Wai (Request, Response, requestBody, requestHeaders, responseLBS)
import Network.Wai (Request, Response, requestHeaders, responseLBS)
import Network.Wai.Internal (getRequestBodyChunk)
import Network.Wai.Handler.Warp (run)
import qualified Network.Wai.Middleware.Throttle as Throttle
import Network.Wreq ( defaults, getWith, header, postWith
Expand All @@ -43,7 +44,7 @@ extractKey =
serverWithThrottle :: (Eq a, Hashable a) => Throttle.Throttle a -> Int -> IO ThreadId
serverWithThrottle th port =
let app = Throttle.throttle th $ \ x f ->
f . responseLBS status200 [] . fromStrict =<< requestBody x
f . responseLBS status200 [] . fromStrict =<< getRequestBodyChunk x
in forkIO $ run port app

benchmark :: String -> Int -> Benchmark
Expand Down
5 changes: 3 additions & 2 deletions script/throttle-simple-server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import Data.Monoid ((<>))
import Data.Text (Text, strip, stripPrefix, toCaseFold)
import Data.Text.Encoding (decodeUtf8)
import Network.HTTP.Types (hAuthorization, status200, status400)
import Network.Wai (Request, Response, requestBody, requestHeaders, responseLBS)
import Network.Wai (Request, Response, requestHeaders, responseLBS)
import Network.Wai.Internal (getRequestBodyChunk)
import Network.Wai.Handler.Warp (run)
import qualified Network.Wai.Middleware.Throttle as Throttle
import Network.Wreq ( defaults, getWith, header, postWith
Expand Down Expand Up @@ -47,7 +48,7 @@ extractKey =
serverWithThrottle :: (Eq a, Hashable a) => Throttle.Throttle a -> Int -> IO ThreadId
serverWithThrottle th port =
let app = Throttle.throttle th $ \ x f ->
f . responseLBS status200 [] . fromStrict =<< requestBody x
f . responseLBS status200 [] . fromStrict =<< getRequestBodyChunk x
in forkIO $ run port app

makeRequest :: [String] -> Int -> Method -> IO ()
Expand Down
5 changes: 1 addition & 4 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@

resolver: lts-12.10

extra-deps:
- token-bucket-0.1.0.1
resolver: lts-13.12

packages:
- '.'
Expand Down
4 changes: 2 additions & 2 deletions wai-middleware-throttle.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: wai-middleware-throttle
version: 0.3.0.0
version: 0.3.0.1
license: BSD3
license-file: LICENSE
author: Christopher Reichert
Expand Down Expand Up @@ -34,7 +34,7 @@ library
, hashable >= 1.2
, http-types
, mtl
, network >= 2.1
, network >= 2.4.2 && <3.2
, safe-exceptions
, stm
, text
Expand Down

0 comments on commit e3db9cc

Please sign in to comment.