req 1.1.0 → 1.2.0
raw patch · 4 files changed
+49/−6 lines, 4 filesdep ~http-api-datadep ~http-clientdep ~unordered-containers
Dependency ranges changed: http-api-data, http-client, unordered-containers
Files
- CHANGELOG.md +4/−0
- Network/HTTP/Req.hs +13/−1
- pure-tests/Network/HTTP/ReqSpec.hs +27/−0
- req.cabal +5/−5
CHANGELOG.md view
@@ -1,3 +1,7 @@+## Req 1.2.0++* Added the `parseUrl` function.+ ## Req 1.1.0 * Added `customAuth` and `attachHeader` to facilitate creation of custom
Network/HTTP/Req.hs view
@@ -146,6 +146,7 @@ , (/:) , parseUrlHttp , parseUrlHttps+ , parseUrl -- ** Body -- $body , NoReqBody (..)@@ -798,7 +799,8 @@ -- $url -- -- We use 'Url's which are correct by construction, see 'Url'. To build a--- 'Url' from a 'ByteString', use 'parseUrlHttp' or 'parseUrlHttps'.+-- 'Url' from a 'ByteString', use 'parseUrlHttp', 'parseUrlHttps', or+-- generic 'parseUrl'. -- | Request's 'Url'. Start constructing your 'Url' with 'http' or 'https' -- specifying the scheme and host at the same time. Then use the @('/~')@@@ -883,6 +885,16 @@ url <- B.stripPrefix "https://" url' (host :| path, option) <- parseUrlHelper url return (foldl (/:) (https host) path, option)++-- | A more general URI parsing function that can be used when scheme is not+-- known beforehand.+--+-- @since 1.2.0++parseUrl+ :: ByteString+ -> Maybe (Either (Url 'Http, Option scheme) (Url 'Https, Option scheme))+parseUrl url = Left <$> parseUrlHttp url <|> Right <$> parseUrlHttps url -- | Get host\/collection of path pieces and possibly query parameters -- already converted to 'Option'. This function is not public.
pure-tests/Network/HTTP/ReqSpec.hs view
@@ -135,6 +135,33 @@ parseUrlHttp "https://my-site.com:bob/far" `shouldSatisfy` isNothing parseUrlHttp "https://my-site.com:7001uh/api" `shouldSatisfy` isNothing parseUrlHttp "https://my-site.com:/bar" `shouldSatisfy` isNothing+ describe "parseUrl" $ do+ it "does not recognize non-http and non-https schemes" $+ parseUrl "ftp://httpbin.org" `shouldSatisfy` isNothing+ it "parses correct http URLs" $+ property $ \host mport' pieces queryParams -> do+ let (url', path, queryString) =+ assembleUrl Http host mport' pieces queryParams+ Left (url'', options) = fromJust (parseUrl url')+ request <- req_ GET url'' NoReqBody options+ L.host request `shouldBe` urlEncode (unHost host)+ L.port request `shouldBe` maybe 80 getNonNegative mport'+ L.path request `shouldBe` path+ L.queryString request `shouldBe` queryString+ it "parses correct https URLs" $+ property $ \host mport' pieces queryParams -> do+ let (url', path, queryString) =+ assembleUrl Https host mport' pieces queryParams+ Right (url'', options) = fromJust (parseUrl url')+ request <- req_ GET url'' NoReqBody options+ L.host request `shouldBe` urlEncode (unHost host)+ L.port request `shouldBe` maybe 443 getNonNegative mport'+ L.path request `shouldBe` path+ L.queryString request `shouldBe` queryString+ it "rejects gibberish in port component" $ do+ parseUrl "http://my-site.com:bob/far" `shouldSatisfy` isNothing+ parseUrl "https://my-site.com:7001uh/api" `shouldSatisfy` isNothing+ parseUrl "http://my-site.com:/bar" `shouldSatisfy` isNothing describe "bodies" $ do describe "NoReqBody" $
req.cabal view
@@ -1,7 +1,7 @@ name: req-version: 1.1.0+version: 1.2.0 cabal-version: 1.18-tested-with: GHC==7.10.3, GHC==8.0.2, GHC==8.2.2, GHC==8.4.2+tested-with: GHC==7.10.3, GHC==8.0.2, GHC==8.2.2, GHC==8.4.3 license: BSD3 license-file: LICENSE.md author: Mark Karpov <markkarpov92@gmail.com>@@ -27,7 +27,7 @@ default: False library- build-depends: aeson >= 0.9 && < 1.4+ build-depends: aeson >= 0.9 && < 1.5 , authenticate-oauth >= 1.5 && < 1.7 , base >= 4.8 && < 5.0 , blaze-builder >= 0.3 && < 0.5@@ -67,7 +67,7 @@ hs-source-dirs: pure-tests type: exitcode-stdio-1.0 build-depends: QuickCheck >= 2.7 && < 3.0- , aeson >= 0.9 && < 1.4+ , aeson >= 0.9 && < 1.5 , base >= 4.8 && < 5.0 , blaze-builder >= 0.3 && < 0.5 , bytestring >= 0.10.8 && < 0.11@@ -94,7 +94,7 @@ hs-source-dirs: httpbin-tests type: exitcode-stdio-1.0 build-depends: QuickCheck >= 2.7 && < 3.0- , aeson >= 0.9 && < 1.4+ , aeson >= 0.9 && < 1.5 , base >= 4.8 && < 5.0 , bytestring >= 0.10.8 && < 0.11 , data-default-class