packages feed

http-client 0.4.29 → 0.4.30

raw patch · 7 files changed

+75/−29 lines, 7 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Network.HTTP.Client: defaultRequest :: Request
+ Network.HTTP.Client: parseRequest :: MonadThrow m => String -> m Request
+ Network.HTTP.Client: parseRequest_ :: String -> Request
+ Network.HTTP.Client: parseUrlThrow :: MonadThrow m => String -> m Request
+ Network.HTTP.Client.Internal: defaultRequest :: Request
+ Network.HTTP.Client.Internal: parseRequest :: MonadThrow m => String -> m Request
+ Network.HTTP.Client.Internal: parseRequest_ :: String -> Request
+ Network.HTTP.Client.Internal: parseUrlThrow :: MonadThrow m => String -> m Request

Files

ChangeLog.md view
@@ -1,3 +1,9 @@+## 0.4.30++* Initial implementation of [#193](https://github.com/snoyberg/http-client/issues/193)+    * Deprecate `parseUrl`+    * Add `parseUrlThrow`, `parseRequest`, and `parseRequest_`+ ## 0.4.29  * Changed the order of connecting a socket and tweaking a socket, such that the socket tweaking callback now happen before connecting.
Network/HTTP/Client.hs view
@@ -49,7 +49,7 @@ -- The next core component is a 'Request', which represents a single HTTP -- request to be sent to a specific server. 'Request's allow for many settings -- to control exact how they function, but usually the simplest approach for--- creating a 'Request' is to use 'parseUrl'.+-- creating a 'Request' is to use 'parseRequest'. -- -- Finally, a 'Response' is the result of sending a single 'Request' to a -- server, over a connection which was acquired from a 'Manager'. Note that you@@ -70,7 +70,7 @@ -- 'applyBasicAuth' are guaranteed to be total (or there\'s a bug in the -- library). ----- One thing to be cautioned about: the type of 'parseUrl' allows it to work in+-- One thing to be cautioned about: the type of 'parseRequest' allows it to work in -- different monads. If used in the 'IO' monad, it will throw an exception in -- the case of an invalid URI. In addition, if you leverage the @IsString@ -- instance of the 'Request' value via @OverloadedStrings@, an invalid URI will@@ -129,6 +129,11 @@     , rawConnectionModifySocket       -- * Request     , parseUrl+    , parseUrlThrow+    , parseRequest+    , parseRequest_+    , defaultRequest+     , applyBasicAuth     , urlEncodedBody     , getUri@@ -296,7 +301,7 @@ -- > main = do -- >   manager <- newManager defaultManagerSettings -- >--- >   request <- parseUrl "http://httpbin.org/post"+-- >   request <- parseRequest "http://httpbin.org/post" -- >   response <- httpLbs request manager -- > -- >   putStrLn $ "The status code was: " ++ (show $ statusCode $ responseStatus response)@@ -316,7 +321,7 @@ -- > -- >   -- Create the request -- >   let requestObject = object ["name" .= "Michael", "age" .= 30]--- >   initialRequest <- parseUrl "http://httpbin.org/post"+-- >   initialRequest <- parseRequest "http://httpbin.org/post" -- >   let request = initialRequest { method = "POST", requestBody = RequestBodyLBS $ encode requestObject } -- > -- >   response <- httpLbs request manager
Network/HTTP/Client/MultipartFormData.hs view
@@ -11,9 +11,9 @@ -- > import Control.Monad -- > -- > main = withSocketsDo $ void $ withManager defaultManagerSettings $ \m -> do--- >     req1 <- parseUrl "http://random-cat-photo.net/cat.jpg"+-- >     req1 <- parseRequest "http://random-cat-photo.net/cat.jpg" -- >     res <- httpLbs req1 m--- >     req2 <- parseUrl "http://example.org/~friedrich/blog/addPost.hs"+-- >     req2 <- parseRequest "http://example.org/~friedrich/blog/addPost.hs" -- >     flip httpLbs m =<< -- >         (formDataBody [partBS "title" "Bleaurgh" -- >                       ,partBS "text" $ TE.encodeUtf8 "矢田矢田矢田矢田矢田"
Network/HTTP/Client/Request.hs view
@@ -8,6 +8,10 @@  module Network.HTTP.Client.Request     ( parseUrl+    , parseUrlThrow+    , parseRequest+    , parseRequest_+    , defaultRequest     , setUriRelative     , getUri     , setUri@@ -67,6 +71,36 @@ import System.IO (withBinaryFile, hTell, hFileSize, Handle, IOMode (ReadMode)) import Control.Monad (liftM) +-- | Deprecated synonym for 'parseUrlThrow'. You probably want+-- 'parseRequest' or 'parseRequest_' instead.+--+-- @since 0.1.0+parseUrl :: MonadThrow m => String -> m Request+parseUrl = parseUrlThrow+{-# DEPRECATED parseUrl "Please use parseUrlThrow, parseRequest, or parseRequest_ instead" #-}++-- | Same as 'parseRequest', except will throw an 'HttpException' in+-- the event of a non-2XX response.+--+-- @since 0.4.30+parseUrlThrow :: MonadThrow m => String -> m Request+parseUrlThrow s' =+    case parseURI (encode s) of+        Just uri -> liftM setMethod (setUri def uri)+        Nothing  -> throwM $ InvalidUrlException s "Invalid URL"+  where+    encode = escapeURIString isAllowedInURI+    (mmethod, s) =+        case break (== ' ') s' of+            (x, ' ':y) | all (\c -> 'A' <= c && c <= 'Z') x -> (Just x, y)+            _ -> (Nothing, s')++    setMethod req =+        case mmethod of+            Nothing -> req+            Just m -> req { method = S8.pack m }++ -- | Convert a URL into a 'Request'. -- -- This defaults some of the values in 'Request', such as setting 'method' to@@ -79,28 +113,23 @@ -- space, e.g.: -- -- @@@--- parseUrl "POST http://httpbin.org/post"+-- parseRequeset "POST http://httpbin.org/post" -- @@@ -- -- Note that the request method must be provided as all capital letters. ----- Since 0.1.0-parseUrl :: MonadThrow m => String -> m Request-parseUrl s' =-    case parseURI (encode s) of-        Just uri -> liftM setMethod (setUri def uri)-        Nothing  -> throwM $ InvalidUrlException s "Invalid URL"+-- @since 0.4.30+parseRequest :: MonadThrow m => String -> m Request+parseRequest =+    liftM noThrow . parseUrlThrow   where-    encode = escapeURIString isAllowedInURI-    (mmethod, s) =-        case break (== ' ') s' of-            (x, ' ':y) | all (\c -> 'A' <= c && c <= 'Z') x -> (Just x, y)-            _ -> (Nothing, s')+    noThrow req = req { checkStatus = \_ _ _ -> Nothing } -    setMethod req =-        case mmethod of-            Nothing -> req-            Just m -> req { method = S8.pack m }+-- | Same as 'parseRequest', but in the cases of a parse error+-- generates an impure exception. Mostly useful for static strings which+-- are known to be correctly formatted.+parseRequest_ :: String -> Request+parseRequest_ = either throw id . parseRequest  -- | Add a 'URI' to the request. If it is absolute (includes a host name), add -- it as per 'setUri'; if it is relative, merge it with the existing request.@@ -219,6 +248,12 @@ useDefaultTimeout :: Maybe Int useDefaultTimeout = Just (-3425) +-- | A default request value+--+-- @since 0.4.30+defaultRequest :: Request+defaultRequest = def { checkStatus = \_ _ _ -> Nothing }+ instance Default Request where     def = Request         { host = "localhost"@@ -280,7 +315,7 @@ -- | Add a Basic Auth header (with the specified user name and password) to the -- given Request. Ignore error handling: ----- >  applyBasicAuth "user" "pass" $ fromJust $ parseUrl url+-- >  applyBasicAuth "user" "pass" $ parseRequest_ url -- -- Since 0.1.0 applyBasicAuth :: S.ByteString -> S.ByteString -> Request -> Request@@ -301,7 +336,7 @@ -- | Add a Proxy-Authorization header (with the specified username and -- password) to the given 'Request'. Ignore error handling: ----- > applyBasicProxyAuth "user" "pass" <$> parseUrl "http://example.org"+-- > applyBasicProxyAuth "user" "pass" <$> parseRequest "http://example.org" -- -- Since 0.3.4 
Network/HTTP/Client/Response.hs view
@@ -33,7 +33,7 @@ -- a new request from the old request, the server headers returned with the -- redirection, and the redirection code itself. This function returns 'Nothing' -- if the code is not a 3xx, there is no 'location' header included, or if the--- redirected response couldn't be parsed with 'parseUrl'.+-- redirected response couldn't be parsed with 'parseRequest'. -- -- If a user of this library wants to know the url chain that results from a -- specific request, that user has to re-implement the redirect-following logic
Network/HTTP/Client/Types.hs view
@@ -307,17 +307,17 @@ -- | All information on how to connect to a host and what should be sent in the -- HTTP request. ----- If you simply wish to download from a URL, see 'parseUrl'.+-- If you simply wish to download from a URL, see 'parseRequest'. -- -- The constructor for this data type is not exposed. Instead, you should use--- either the 'def' method to retrieve a default instance, or 'parseUrl' to+-- either the 'defaultRequest' value, or 'parseRequest' to -- construct from a URL, and then use the records below to make modifications. -- This approach allows http-client to add configuration options without -- breaking backwards compatibility. -- -- For example, to construct a POST request, you could do something like: ----- > initReq <- parseUrl "http://www.example.com/path"+-- > initReq <- parseRequest "http://www.example.com/path" -- > let req = initReq -- >             { method = "POST" -- >             }
http-client.cabal view
@@ -1,5 +1,5 @@ name:                http-client-version:             0.4.29+version:             0.4.30 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