http-client 0.3.8.2 → 0.4.0
raw patch · 3 files changed
+34/−9 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Network.HTTP.Client.MultipartFormData: Part :: Text -> Maybe String -> Maybe MimeType -> IO RequestBody -> Part
+ Network.HTTP.Client.MultipartFormData: addPartHeaders :: Part -> [Header] -> Part
+ Network.HTTP.Client.MultipartFormData: partHeaders :: Part -> [Header]
Files
- ChangeLog.md +3/−0
- Network/HTTP/Client/MultipartFormData.hs +29/−7
- http-client.cabal +2/−2
+ ChangeLog.md view
@@ -0,0 +1,3 @@+## 0.4.0++* Hide the `Part` constructor, and allow for additional headers. See: https://github.com/snoyberg/http-client/issues/76
Network/HTTP/Client/MultipartFormData.hs view
@@ -23,7 +23,12 @@ module Network.HTTP.Client.MultipartFormData ( -- * Part type- Part(..)+ Part+ ,partName+ ,partFilename+ ,partContentType+ ,partHeaders+ ,partGetBody -- * Constructing parts ,partBS ,partLBS@@ -32,6 +37,8 @@ ,partFileSourceChunked ,partFileRequestBody ,partFileRequestBodyM+ -- * Headers+ ,addPartHeaders -- * Building form data ,formDataBody ,formDataBodyWithBoundary@@ -45,8 +52,9 @@ import Network.HTTP.Client import Network.Mime-import Network.HTTP.Types (hContentType, methodPost)+import Network.HTTP.Types (hContentType, methodPost, Header()) import Data.Monoid ((<>))+import Data.Foldable (foldMap) import Blaze.ByteString.Builder @@ -55,6 +63,8 @@ import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString as BS +import qualified Data.CaseInsensitive as CI+ import Control.Monad.Trans.State.Strict (state, runState) import Control.Monad.IO.Class import System.FilePath@@ -72,12 +82,13 @@ { partName :: Text -- ^ Name of the corresponding \<input\> , partFilename :: Maybe String -- ^ A file name, if this is an attached file , partContentType :: Maybe MimeType -- ^ Content type+ , partHeaders :: [Header] -- ^ List of additional headers , partGetBody :: IO RequestBody -- ^ Action in m which returns the body -- of a message. } instance Show Part where- showsPrec d (Part n f c _) =+ showsPrec d (Part n f c h _) = showParen (d>=11) $ showString "Part " . showsPrec 11 n . showString " "@@ -85,6 +96,8 @@ . showString " " . showsPrec 11 c . showString " "+ . showsPrec 11 h+ . showString " " . showString "<m (RequestBody m)>" -- | Make a 'Part' whose content is a strict 'BS.ByteString'.@@ -94,7 +107,7 @@ partBS :: Text -- ^ Name of the corresponding \<input\>. -> BS.ByteString -- ^ The body for this 'Part'. -> Part-partBS n b = Part n mempty mempty $ return $ RequestBodyBS b+partBS n b = Part n mempty mempty mempty $ return $ RequestBodyBS b -- | Make a 'Part' whose content is a lazy 'BL.ByteString'. --@@ -103,7 +116,7 @@ partLBS :: Text -- ^ Name of the corresponding \<input\>. -> BL.ByteString -- ^ The body for this 'Part'. -> Part-partLBS n b = Part n mempty mempty $ return $ RequestBodyLBS b+partLBS n b = Part n mempty mempty mempty $ return $ RequestBodyLBS b -- | Make a 'Part' from a file. --@@ -185,15 +198,19 @@ -> IO RequestBody -- ^ Action that will supply data to upload. -> Part partFileRequestBodyM n f rqb =- Part n (Just f) (Just $ defaultMimeLookup $ pack f) rqb+ Part n (Just f) (Just $ defaultMimeLookup $ pack f) mempty rqb {-# INLINE cp #-} cp :: BS.ByteString -> RequestBody cp bs = RequestBodyBuilder (fromIntegral $ BS.length bs) $ copyByteString bs +-- | Add a list of additional headers to this 'Part'.+addPartHeaders :: Part -> [Header] -> Part+addPartHeaders p hs = p { partHeaders = partHeaders p <> hs }+ renderPart :: BS.ByteString -- ^ Boundary between parts. -> Part -> IO RequestBody-renderPart boundary (Part name mfilename mcontenttype get) = liftM render get+renderPart boundary (Part name mfilename mcontenttype hdrs get) = liftM render get where render renderBody = cp "--" <> cp boundary <> cp "\r\n" <> cp "Content-Disposition: form-data; name=\""@@ -208,6 +225,11 @@ <> cp "Content-Type: " <> cp ct _ -> mempty)+ <> foldMap (\(k, v) ->+ cp "\r\n"+ <> cp (CI.original k)+ <> cp ": "+ <> cp v) hdrs <> cp "\r\n\r\n" <> renderBody <> cp "\r\n"
http-client.cabal view
@@ -1,5 +1,5 @@ name: http-client-version: 0.3.8.2+version: 0.4.0 synopsis: An HTTP client engine, intended as a base layer for more user-friendly packages. description: This codebase has been refactored from http-conduit. homepage: https://github.com/snoyberg/http-client@@ -9,7 +9,7 @@ maintainer: michael@snoyman.com category: Network build-type: Simple-extra-source-files: README.md+extra-source-files: README.md ChangeLog.md cabal-version: >=1.10 flag network-uri