packages feed

strelka-wai (empty) → 0.4

raw patch · 4 files changed

+155/−0 lines, 4 filesdep +basedep +base-preludedep +bytestringsetup-changed

Dependencies added: base, base-prelude, bytestring, case-insensitive, http-types, strelka, text, unordered-containers, wai, warp

Files

+ LICENSE view
@@ -0,0 +1,22 @@+Copyright (c) 2016, Nikita Volkov++Permission is hereby granted, free of charge, to any person+obtaining a copy of this software and associated documentation+files (the "Software"), to deal in the Software without+restriction, including without limitation the rights to use,+copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the+Software is furnished to do so, subject to the following+conditions:++The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR+OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ library/Strelka/WAI.hs view
@@ -0,0 +1,76 @@+module Strelka.WAI+(+  strelkaServer,+  strelkaApplication,+)+where++import BasePrelude+import Data.Text (Text)+import System.IO (stderr)+import qualified Strelka.RequestParser as A+import qualified Strelka.ResponseBuilder as B+import qualified Strelka.Executor as C+import qualified Strelka.Model as F+import qualified Network.Wai as D+import qualified Network.Wai.Handler.Warp as E+import qualified Network.HTTP.Types as G+import qualified Data.CaseInsensitive as H+import qualified Data.ByteString.Builder as I+import qualified Data.HashMap.Strict as J+import qualified Data.Text.IO as K+++strelkaServer :: Monad m => Int -> (forall a. m a -> IO (Either Text a)) -> A.RequestParser m B.ResponseBuilder -> IO ()+strelkaServer port runBase route =+  E.run port (strelkaApplication runBase route)++strelkaApplication :: Monad m => (forall a. m a -> IO (Either Text a)) -> A.RequestParser m B.ResponseBuilder -> D.Application+strelkaApplication runBase route =+  \request responseHandler ->+    do+      responseEither <- fmap join (runBase (C.route (strelkaRequest request) route))+      case responseEither of+        Left msg ->+          do+            K.hPutStrLn stderr msg+            responseHandler (waiResponse (B.run B.internalErrorStatus))+        Right response ->+          responseHandler (waiResponse response)++strelkaRequest :: D.Request -> F.Request+strelkaRequest waiRequest =+  F.Request method path query headers inputStream+  where+    method =+      F.Method (H.foldCase (D.requestMethod waiRequest))+    path =+      F.Path (D.rawPathInfo waiRequest)+    query =+      J.fromList (map row (D.queryString waiRequest))+      where+        row (name, value) =+          (F.ParamName name, F.ParamValue value)+    headers =+      J.fromList (map row (D.requestHeaders waiRequest))+      where+        row (name, value) =+          (F.HeaderName (H.foldedCase name), F.HeaderValue value)+    inputStream =+      F.InputStream (D.requestBody waiRequest)++waiResponse :: F.Response -> D.Response+waiResponse (F.Response status headerList outputStream) =+  D.responseStream (waiStatus status) (map waiHeader headerList) (waiStreamingBody outputStream)++waiStatus :: F.Status -> G.Status+waiStatus (F.Status statusCode) =+  toEnum statusCode++waiHeader :: F.Header -> G.Header+waiHeader (F.Header (F.HeaderName name) (F.HeaderValue value)) =+  (H.mk name, value)++waiStreamingBody :: F.OutputStream -> D.StreamingBody+waiStreamingBody (F.OutputStream outputStreamFn) =+  \consumeBuilder flush -> outputStreamFn (consumeBuilder . I.byteString) flush
+ strelka-wai.cabal view
@@ -0,0 +1,55 @@+name:+  strelka-wai+version:+  0.4+synopsis:+  WAI compatibility layer for "strelka"+homepage:+  https://github.com/nikita-volkov/strelka-wai+bug-reports:+  https://github.com/nikita-volkov/strelka-wai/issues +author:+  Nikita Volkov <nikita.y.volkov@mail.ru>+maintainer:+  Nikita Volkov <nikita.y.volkov@mail.ru>+copyright:+  (c) 2016, Nikita Volkov+license:+  MIT+license-file:+  LICENSE+build-type:+  Simple+cabal-version:+  >=1.10+++source-repository head+  type:+    git+  location:+    git://github.com/nikita-volkov/strelka-wai.git+++library+  hs-source-dirs:+    library+  exposed-modules:+    Strelka.WAI+  default-extensions:+    Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric, DeriveTraversable, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, LambdaCase, LiberalTypeSynonyms, MagicHash, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators, UnboxedTuples+  default-language:+    Haskell2010+  build-depends:+    -- +    wai >= 3.2 && < 4,+    warp >= 3.2 && < 4,+    http-types >= 0.9 && < 0.10,+    strelka == 0.4.*,+    -- +    unordered-containers == 0.2.*,+    case-insensitive >= 1 && < 2,+    text == 1.*,+    bytestring == 0.10.*,+    base-prelude < 2,+    base < 5