Compare commits

...

8 Commits

Author SHA1 Message Date
Gregor Kleen
cb25dd23c4 fix: ignore body of responses to head requests as per spec 2024-03-31 00:30:13 +01:00
Sarah Vaupel
fafc203e1b fix build 2024-01-18 04:25:54 +01:00
Sarah Vaupel
3dcb276521 Merge branch 'master' into uni2work 2024-01-18 02:22:46 +01:00
Gregor Kleen
42103ab247 fix: bump for unliftio 2020-08-10 16:31:03 +02:00
Gregor Kleen
076d65a618 Merge branch 'master' of https://github.com/minio/minio-hs into uni2work 2020-08-10 13:17:01 +02:00
Gregor Kleen
9a4e3889a9 feat: export connect 2020-07-03 10:49:31 +02:00
Gregor Kleen
c79a03a3af fix: build 2020-07-03 10:37:09 +02:00
Gregor Kleen
1beeab1e68 feat: Expose ConnectInfo record fields 2020-07-03 09:54:26 +02:00
7 changed files with 23 additions and 13 deletions

View File

@ -37,13 +37,14 @@ import UnliftIO as Exports
throwIO,
try,
)
import qualified Data.Text.Encoding as T
-- | Apply a function on both elements of a pair
both :: (a -> b) -> (a, a) -> (b, b)
both f (a, b) = (f a, f b)
showBS :: (Show a) => a -> ByteString
showBS a = encodeUtf8 (show a :: Text)
showBS :: Show a => a -> ByteString
showBS a = T.encodeUtf8 (show a :: Text)
toStrictBS :: LByteString -> ByteString
toStrictBS = LB.toStrict

View File

@ -41,13 +41,14 @@ module Network.Minio
findFirst,
-- * Connecting to object storage
ConnectInfo,
ConnectInfo(..),
setRegion,
setCreds,
setCredsFrom,
isConnectInfoSecure,
disableTLSCertValidation,
MinioConn,
connect,
mkMinioConn,
-- ** Connection helpers

View File

@ -1068,7 +1068,7 @@ defaultS3ReqInfo =
getS3Path :: Maybe Bucket -> Maybe Object -> ByteString
getS3Path b o =
let segments = map encodeUtf8 $ catMaybes $ b : bool [] [o] (isJust b)
let segments = map TE.encodeUtf8 $ catMaybes $ b : bool [] [o] (isJust b)
in B.concat ["/", B.intercalate "/" segments]
type RegionMap = H.HashMap Bucket Region
@ -1084,10 +1084,12 @@ newtype Minio a = Minio
Monad,
MonadIO,
MonadReader MinioConn,
MonadResource,
MonadUnliftIO
MonadResource
)
instance MonadUnliftIO Minio where
withRunInIO inner = Minio $ U.askUnliftIO >>= \(U.UnliftIO unliftIO) -> liftIO (inner $ \(Minio f) -> unliftIO f)
-- | MinioConn holds connection info and a connection pool to allow
-- for efficient resource re-use.
data MinioConn = MinioConn

View File

@ -41,6 +41,7 @@ import qualified Data.Aeson as Json
import Data.ByteString.Builder (byteString, toLazyByteString)
import qualified Data.HashMap.Strict as H
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
import qualified Data.Time as Time
import Lib.Prelude
import qualified Network.HTTP.Client as NClient
@ -334,7 +335,7 @@ presignedPostPolicy p = do
mkPair (PPCEquals k v) = Just (k, v)
mkPair _ = Nothing
formFromPolicy =
H.map encodeUtf8 $
H.map TE.encodeUtf8 $
H.fromList $
mapMaybe
mkPair

View File

@ -109,6 +109,7 @@ where
import qualified Data.ByteString as BS
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
import Lib.Prelude
import qualified Network.HTTP.Conduit as NC
import qualified Network.HTTP.Types as HT
@ -389,7 +390,7 @@ putObjectPart bucket object uploadId partNumber headers payload = do
srcInfoToHeaders :: SourceInfo -> [HT.Header]
srcInfoToHeaders srcInfo =
( "x-amz-copy-source",
encodeUtf8 $
TE.encodeUtf8 $
T.concat
[ "/",
srcBucket srcInfo,

View File

@ -49,6 +49,8 @@ import Network.Minio.Data.Crypto
import Network.Minio.Data.Time
import Network.Minio.Errors
import Text.Printf (printf)
import qualified Data.Text.Encoding as TE
import qualified Data.Text as T
-- these headers are not included in the string to sign when signing a
-- request
@ -86,7 +88,7 @@ mkAuthHeader accessKey scope signedHeaderKeys sign =
let authValue =
B.concat
[ "AWS4-HMAC-SHA256 Credential=",
encodeUtf8 accessKey,
TE.encodeUtf8 accessKey,
"/",
scope,
", SignedHeaders=",
@ -317,7 +319,7 @@ getSigningKey :: SignParams -> ByteString
getSigningKey sp =
hmacSHA256RawBS "aws4_request"
. hmacSHA256RawBS (toByteString $ spService sp)
. hmacSHA256RawBS (encodeUtf8 $ fromMaybe "" $ spRegion sp)
. hmacSHA256RawBS (TE.encodeUtf8 $ fromMaybe "" $ spRegion sp)
. hmacSHA256RawBS (awsDateFormatBS $ spTimeStamp sp)
$ B.concat ["AWS4", BA.convert $ spSecretKey sp]

View File

@ -184,10 +184,10 @@ httpLbs req mgr = do
resp <- either throwIO return respE
unless (isSuccessStatus $ NC.responseStatus resp) $
case contentTypeMay resp of
Just "application/xml" -> do
Just "application/xml" | expectBody -> do
sErr <- parseErrResponse $ NC.responseBody resp
throwIO sErr
Just "application/json" -> do
Just "application/json" | expectBody -> do
sErr <- parseErrResponseJSON $ NC.responseBody resp
throwIO sErr
_ ->
@ -204,6 +204,7 @@ httpLbs req mgr = do
contentTypeMay resp =
lookupHeader Hdr.hContentType $
NC.responseHeaders resp
expectBody = NC.method req /= HT.methodHead
http ::
(MonadUnliftIO m, R.MonadResource m) =>
@ -215,7 +216,7 @@ http req mgr = do
resp <- either throwIO return respE
unless (isSuccessStatus $ NC.responseStatus resp) $
case contentTypeMay resp of
Just "application/xml" -> do
Just "application/xml" | expectBody -> do
respBody <- C.connect (NC.responseBody resp) CB.sinkLbs
sErr <- parseErrResponse respBody
throwIO sErr
@ -235,6 +236,7 @@ http req mgr = do
contentTypeMay resp =
lookupHeader Hdr.hContentType $
NC.responseHeaders resp
expectBody = NC.method req /= HT.methodHead
-- Similar to mapConcurrently but limits the number of threads that
-- can run using a quantity semaphore.