Spock 0.10.0.0 → 0.10.0.1
raw patch · 3 files changed
+26/−24 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Web.Spock.Internal.Cookies: CookieSettings :: CookieEOL -> ByteString -> Maybe ByteString -> Bool -> Bool -> CookieSettings
+ Web.Spock.Internal.Cookies: CookieSettings :: CookieEOL -> Maybe ByteString -> Maybe ByteString -> Bool -> Bool -> CookieSettings
- Web.Spock.Internal.Cookies: [cs_path] :: CookieSettings -> ByteString
+ Web.Spock.Internal.Cookies: [cs_path] :: CookieSettings -> Maybe ByteString
- Web.Spock.Shared: CookieSettings :: CookieEOL -> ByteString -> Maybe ByteString -> Bool -> Bool -> CookieSettings
+ Web.Spock.Shared: CookieSettings :: CookieEOL -> Maybe ByteString -> Maybe ByteString -> Bool -> Bool -> CookieSettings
- Web.Spock.Shared: [cs_path] :: CookieSettings -> ByteString
+ Web.Spock.Shared: [cs_path] :: CookieSettings -> Maybe ByteString
Files
- Spock.cabal +1/−1
- src/Web/Spock/Internal/Cookies.hs +20/−19
- test/Web/Spock/Internal/CookiesSpec.hs +5/−4
Spock.cabal view
@@ -1,5 +1,5 @@ name: Spock-version: 0.10.0.0+version: 0.10.0.1 synopsis: Another Haskell web framework for rapid development description: This toolbox provides everything you need to get a quick start into web hacking with haskell: .
src/Web/Spock/Internal/Cookies.hs view
@@ -10,6 +10,7 @@ ) where +import Data.Maybe import Data.Monoid ((<>)) import Data.Time import qualified Data.ByteString.Char8 as BS@@ -26,7 +27,7 @@ = CookieSettings { cs_EOL :: CookieEOL -- ^ cookie expiration setting, see 'CookieEOL'- , cs_path :: BS.ByteString+ , cs_path :: Maybe BS.ByteString -- ^ a path for the cookie , cs_domain :: Maybe BS.ByteString -- ^ a domain for the cookie. 'Nothing' means no domain is set@@ -52,7 +53,7 @@ -- > , cs_HTTPOnly = False -- > , cs_secure = False -- > , cs_domain = Nothing--- > , cs_path = "/"+-- > , cs_path = Just "/" -- > } -- defaultCookieSettings :: CookieSettings@@ -62,7 +63,7 @@ , cs_HTTPOnly = False , cs_secure = False , cs_domain = Nothing- , cs_path = "/"+ , cs_path = Just "/" } generateCookieHeaderString ::@@ -72,9 +73,10 @@ -> UTCTime -> BS.ByteString generateCookieHeaderString name value CookieSettings{..} now =- BS.intercalate "; " $ filter (not . BS.null) fullCookie+ BS.intercalate "; " fullCookie where fullCookie =+ catMaybes [ nv , domain , path@@ -83,26 +85,25 @@ , httpOnly , secure ]- nv = BS.concat [T.encodeUtf8 name, "=", urlEncode value]- path = BS.concat ["path=", cs_path]+ nv = Just $ BS.concat [T.encodeUtf8 name, "=", urlEncode value]+ path = flip fmap cs_path $ \p -> BS.concat ["path=", p] domain =- case cs_domain of- Nothing -> BS.empty- Just d -> BS.concat ["domain=", d]- httpOnly = if cs_HTTPOnly then "HttpOnly" else BS.empty- secure = if cs_secure then "Secure" else BS.empty+ flip fmap cs_domain $ \d ->+ BS.concat ["domain=", d]+ httpOnly = if cs_HTTPOnly then Just "HttpOnly" else Nothing+ secure = if cs_secure then Just "Secure" else Nothing maxAge = case cs_EOL of- CookieValidForSession -> BS.empty- CookieValidFor n -> "max-age=" <> maxAgeValue n- CookieValidUntil t -> "max-age=" <> maxAgeValue (diffUTCTime t now)+ CookieValidForSession -> Nothing+ CookieValidFor n -> Just $ "max-age=" <> maxAgeValue n+ CookieValidUntil t -> Just $ "max-age=" <> maxAgeValue (diffUTCTime t now) expires = case cs_EOL of- CookieValidForSession -> BS.empty- CookieValidFor n -> "expires=" <> expiresValue (addUTCTime n now)- CookieValidUntil t -> "expires=" <> expiresValue t+ CookieValidForSession -> Nothing+ CookieValidFor n -> Just $ "expires=" <> expiresValue (addUTCTime n now)+ CookieValidUntil t -> Just $ "expires=" <> expiresValue t maxAgeValue :: NominalDiffTime -> BS.ByteString maxAgeValue nrOfSeconds =@@ -111,7 +112,7 @@ expiresValue :: UTCTime -> BS.ByteString expiresValue t =- BS.pack $ formatTime defaultTimeLocale "%a, %d %b %Y %X %Z" t+ BS.pack $ formatTime defaultTimeLocale "%a, %d-%b-%Y %X %Z" t urlEncode :: T.Text -> BS.ByteString urlEncode = URI.urlEncode True . T.encodeUtf8@@ -123,4 +124,4 @@ parseCookie :: BS.ByteString -> (T.Text, T.Text) parseCookie cstr = let (name, urlEncValue) = BS.break (== '=') cstr- in (T.decodeUtf8 name, T.decodeUtf8 . URI.urlDecode True . BS.drop 1 $ urlEncValue)+ in (T.strip $ T.decodeUtf8 name, T.decodeUtf8 . URI.urlDecode True . BS.drop 1 $ urlEncValue)
test/Web/Spock/Internal/CookiesSpec.hs view
@@ -38,7 +38,7 @@ do let generated = g "foo" "bar" def { cs_EOL = CookieValidUntil (UTCTime (fromGregorian 2016 1 1) 0) } it "should set the correct expires key" $- generated `shouldContainOnce` "expires=Fri, 01 Jan 2016 00:00:00 UTC"+ generated `shouldContainOnce` "expires=Fri, 01-Jan-2016 00:00:00 UTC" it "should set the correct max-age key" $ generated `shouldContainOnce` "max-age=10465200"@@ -47,14 +47,14 @@ do let generated = g "foo" "bar" def { cs_EOL = CookieValidUntil (UTCTime (fromGregorian 1970 1 1) 0) } it "should set the correct expires key" $- generated `shouldContainOnce` "expires=Thu, 01 Jan 1970 00:00:00 UTC"+ generated `shouldContainOnce` "expires=Thu, 01-Jan-1970 00:00:00 UTC" it "should set the max-age key to 0" $ generated `shouldContainOnce` "max-age=0" describe "when setting the path" $ it "should generate the correct path pair" $- g "foo" "bar" def { cs_path = "/the-path" } `shouldContainOnce` "path=/the-path"+ g "foo" "bar" def { cs_path = Just "/the-path" } `shouldContainOnce` "path=/the-path" describe "when setting the domain" $ it "should generate the correct domain pair" $@@ -76,7 +76,8 @@ describe "Parsing cookies" $ do it "should parse urlencoded multiple cookies" $ parseCookies "foo=bar;quux=h&m" `shouldBe` [("foo", "bar"), ("quux", "h&m")]-+ it "should handle spacing between cookies" $+ parseCookies "foo=bar; quux=bim" `shouldBe` [("foo", "bar"), ("quux", "bim")] it "should parse urlencoded values" $ parseCookies "foo=most%2Bspecial%20chars%3B%25" `shouldBe` [("foo", "most+special chars;%")]