packages feed

http-client 0.4.22.1 → 0.4.23

raw patch · 5 files changed

+42/−5 lines, 5 files

Files

ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.4.23++* Case insensitive cookie domains [#158](https://github.com/snoyberg/http-client/issues/158)+ ## 0.4.22  * ProxyConnectException now returns Right HttpException. [#155](https://github.com/snoyberg/http-client/pull/155)
Network/HTTP/Client/Cookies.hs view
@@ -52,13 +52,17 @@  -- | This corresponds to the subcomponent algorithm entitled \"Domain Matching\" detailed -- in section 5.1.3-domainMatches :: BS.ByteString -> BS.ByteString -> Bool-domainMatches string domainString+domainMatches :: BS.ByteString -- ^ Domain to test+              -> BS.ByteString -- ^ Domain from a cookie+              -> Bool+domainMatches string' domainString'   | string == domainString = True   | BS.length string < BS.length domainString + 1 = False   | domainString `BS.isSuffixOf` string && BS.singleton (BS.last difference) == "." && not (isIpAddress string) = True   | otherwise = False   where difference = BS.take (BS.length string - BS.length domainString) string+        string = CI.foldCase string'+        domainString = CI.foldCase domainString'  -- | This corresponds to the subcomponent algorithm entitled \"Paths\" detailed -- in section 5.1.4@@ -136,7 +140,7 @@ computeCookieString request cookie_jar now is_http_api = (output_line, cookie_jar')   where matching_cookie cookie = condition1 && condition2 && condition3 && condition4           where condition1-                  | cookie_host_only cookie = Req.host request == cookie_domain cookie+                  | cookie_host_only cookie = CI.foldCase (Req.host request) == CI.foldCase (cookie_domain cookie)                   | otherwise = domainMatches (Req.host request) (cookie_domain cookie)                 condition2 = pathMatches (Req.path request) (cookie_path cookie)                 condition3
Network/HTTP/Client/Types.hs view
@@ -55,6 +55,7 @@ import Data.Text (Text) import Data.Streaming.Zlib (ZlibException) import Control.Concurrent.MVar (MVar)+import Data.CaseInsensitive as CI  -- | An @IO@ action that represents an incoming response body coming from the -- server. Data provided by this action has already been gunzipped and@@ -159,7 +160,7 @@ instance Eq Cookie where   (==) a b = name_matches && domain_matches && path_matches     where name_matches = cookie_name a == cookie_name b-          domain_matches = cookie_domain a == cookie_domain b+          domain_matches = CI.foldCase (cookie_domain a) == CI.foldCase (cookie_domain b)           path_matches = cookie_path a == cookie_path b  instance Ord Cookie where
http-client.cabal view
@@ -1,5 +1,5 @@ name:                http-client-version:             0.4.22.1+version:             0.4.23 synopsis:            An HTTP client engine, intended as a base layer for more user-friendly packages. description:         Hackage documentation generation is not reliable. For up to date documentation, please see: <http://www.stackage.org/package/http-client>. homepage:            https://github.com/snoyberg/http-client@@ -99,6 +99,7 @@                        Network.HTTP.Client.HeadersSpec                        Network.HTTP.Client.RequestSpec                        Network.HTTP.Client.RequestBodySpec+                       Network.HTTP.Client.CookieSpec   build-depends:       base                      , http-client                      , hspec
+ test-nonet/Network/HTTP/Client/CookieSpec.hs view
@@ -0,0 +1,27 @@+{-# LANGUAGE OverloadedStrings #-}+module Network.HTTP.Client.CookieSpec where++import           Data.Time.Clock+import           Network.HTTP.Client.Internal+import           Network.HTTP.Types+import           Test.Hspec++main :: IO ()+main = hspec spec++spec :: Spec+spec = describe "CookieSpec" $ do+    it "cookie equality - case insensitive Eq" $ do+      now <- getCurrentTime+      let cookie1 = Cookie "test" "value" now "doMain.Org" "/" now now False False False False+          cookie2 = Cookie "test" "value" now "DOMAIn.ORg" "/" now now False False False False+      cookie1 `shouldBe` cookie2++    it "domainMatches - case insensitive" $ do+      domainMatches "www.org" "www.org" `shouldBe` True+      domainMatches "wWw.OrG" "Www.oRG" `shouldBe` True+      domainMatches "wxw.OrG" "Www.oRG" `shouldBe` False++    it "domainMatches - case insensitive, partial" $ do+      domainMatches "www.org" "xxx.www.org" `shouldBe` False+      domainMatches "xxx.www.org" "WWW.ORG" `shouldBe` True