From 44c9fa9c49628005e3d385b900e1da963841f798 Mon Sep 17 00:00:00 2001 From: Henry Laxen Date: Sun, 24 May 2020 13:10:01 -0700 Subject: [PATCH 1/4] fixed 5 warnings --- snap-server.cabal | 1 + src/Snap/Internal/Http/Server/Address.hs | 14 +++++++------- src/Snap/Internal/Http/Server/Session.hs | 2 +- src/Snap/Internal/Http/Server/Socket.hs | 4 ++-- src/Snap/Internal/Http/Server/TLS.hs | 2 +- test/Paths_snap_server.hs | 4 ++-- test/Test/Common/TestHandler.hs | 2 +- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/snap-server.cabal b/snap-server.cabal index e39abf3c..68f81ea2 100644 --- a/snap-server.cabal +++ b/snap-server.cabal @@ -507,6 +507,7 @@ Executable snap-test-server clock, containers, directory, + filepath, io-streams, io-streams-haproxy, lifted-base, diff --git a/src/Snap/Internal/Http/Server/Address.hs b/src/Snap/Internal/Http/Server/Address.hs index c9def8e7..ebb4e318 100644 --- a/src/Snap/Internal/Http/Server/Address.hs +++ b/src/Snap/Internal/Http/Server/Address.hs @@ -22,10 +22,8 @@ import Control.Monad (liftM) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as S import Data.Maybe (fromMaybe) -import qualified Data.Text as T -import qualified Data.Text.Encoding as T import Data.Typeable (Typeable) -import Network.Socket (AddrInfo (addrAddress, addrFamily, addrFlags, addrSocketType), AddrInfoFlag (AI_NUMERICSERV, AI_PASSIVE), Family (AF_INET, AF_INET6), HostName, NameInfoFlag (NI_NUMERICHOST), ServiceName, SockAddr (SockAddrInet, SockAddrInet6, SockAddrUnix), SocketType (Stream), defaultHints, getAddrInfo, getNameInfo) +import Network.Socket (AddrInfo (addrAddress, addrFamily, addrFlags, addrSocketType), AddrInfoFlag (AI_NUMERICSERV, AI_PASSIVE), Family (AF_INET, AF_INET6), HostName, NameInfoFlag (NI_NUMERICHOST), ServiceName, SockAddr (SockAddrInet, SockAddrInet6), SocketType (Stream), defaultHints, getAddrInfo, getNameInfo) ------------------------------------------------------------------------------ @@ -65,13 +63,15 @@ getAddressImpl !_getHostAddr addr = case addr of SockAddrInet p _ -> host (fromIntegral p) SockAddrInet6 p _ _ _ -> host (fromIntegral p) - SockAddrUnix path -> return (-1, prefix path) #if MIN_VERSION_network(2,6,0) _ -> fail "Unsupported address type" + where + host port = (,) port . S.pack <$> _getHostAddr addr +#else + SockAddrUnix path -> return (-1, prefix path) + where + prefix path = T.encodeUtf8 $! T.pack $ "unix:" ++ path #endif - where - prefix path = T.encodeUtf8 $! T.pack $ "unix:" ++ path - host port = (,) port . S.pack <$> _getHostAddr addr ------------------------------------------------------------------------------ diff --git a/src/Snap/Internal/Http/Server/Session.hs b/src/Snap/Internal/Http/Server/Session.hs index 4c0b4fe5..4be9ce12 100644 --- a/src/Snap/Internal/Http/Server/Session.hs +++ b/src/Snap/Internal/Http/Server/Session.hs @@ -35,7 +35,7 @@ import Data.Maybe (fromJust, fromMaybe, #if !MIN_VERSION_base(4,8,0) import Data.Monoid (mconcat) #endif -import Data.Monoid ((<>)) +import Data.Monoid () import Data.Time.Format (formatTime) import Data.Typeable (Typeable) import Data.Version (showVersion) diff --git a/src/Snap/Internal/Http/Server/Socket.hs b/src/Snap/Internal/Http/Server/Socket.hs index 42b962ae..d14d849d 100644 --- a/src/Snap/Internal/Http/Server/Socket.hs +++ b/src/Snap/Internal/Http/Server/Socket.hs @@ -21,7 +21,7 @@ import Data.ByteString.Char8 (ByteString) import Network.Socket (Socket, SocketOption (NoDelay, ReuseAddr), accept, close, getSocketName, setSocketOption, socket) import qualified Network.Socket as N #ifdef HAS_SENDFILE -import Network.Socket (fdSocket) +import Network.Socket (unsafeFdSocket) import System.Posix.IO (OpenMode (..), closeFd, defaultFileFlags, openFd) import System.Posix.Types (Fd (..)) import System.SendFile (sendFile, sendHeaders) @@ -175,7 +175,7 @@ sendFileFunc sock !_ builder fPath offset nbytes = bracket acquire closeFd go where acquire = openFd fPath ReadOnly Nothing defaultFileFlags #if MIN_VERSION_network(3,0,0) - go fileFd = do sockFd <- Fd `fmap` fdSocket sock + go fileFd = do sockFd <- Fd `fmap` unsafeFdSocket sock sendHeaders builder sockFd sendFile sockFd fileFd offset nbytes #else diff --git a/src/Snap/Internal/Http/Server/TLS.hs b/src/Snap/Internal/Http/Server/TLS.hs index 551966f5..ee50926c 100644 --- a/src/Snap/Internal/Http/Server/TLS.hs +++ b/src/Snap/Internal/Http/Server/TLS.hs @@ -105,7 +105,7 @@ bindHttps bindAddress bindPort cert chainCert key = (Socket.close . fst) $ \(sock, addr) -> do Socket.setSocketOption sock Socket.ReuseAddr 1 - Socket.bindSocket sock addr + Socket.bind sock addr Socket.listen sock 150 ctx <- SSL.context diff --git a/test/Paths_snap_server.hs b/test/Paths_snap_server.hs index cc6e18f9..7118abc9 100644 --- a/test/Paths_snap_server.hs +++ b/test/Paths_snap_server.hs @@ -2,7 +2,7 @@ module Paths_snap_server ( version ) where -import Data.Version (Version (..)) +import Data.Version (Version, makeVersion) version :: Version -version = Version {versionBranch = [0,0,0], versionTags = ["unknown"]} +version = makeVersion [0,0,0] diff --git a/test/Test/Common/TestHandler.hs b/test/Test/Common/TestHandler.hs index 002ead71..6125b5b0 100644 --- a/test/Test/Common/TestHandler.hs +++ b/test/Test/Common/TestHandler.hs @@ -15,7 +15,7 @@ import qualified Data.ByteString.Lazy.Char8 as L import Data.List (sort) import qualified Data.Map as Map import Data.Maybe (fromMaybe) -import Data.Monoid (Monoid (mappend, mconcat, mempty)) +import Data.Monoid () ------------------------------------------------------------------------------ import Snap.Core (Request (rqParams, rqURI), Snap, getParam, getRequest, logError, modifyResponse, redirect, route, rqClientAddr, rqClientPort, setContentLength, setContentType, setHeader, setResponseBody, setResponseCode, setTimeout, transformRequestBody, writeBS, writeBuilder, writeLBS) import Snap.Internal.Debug () From 48fb021f9cc829b5217325f1bb1971a57ed8667d Mon Sep 17 00:00:00 2001 From: Henry Laxen Date: Sun, 24 May 2020 13:55:11 -0700 Subject: [PATCH 2/4] maybe fixed monoids --- src/Snap/Internal/Http/Server/Session.hs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Snap/Internal/Http/Server/Session.hs b/src/Snap/Internal/Http/Server/Session.hs index 4be9ce12..1825401a 100644 --- a/src/Snap/Internal/Http/Server/Session.hs +++ b/src/Snap/Internal/Http/Server/Session.hs @@ -35,6 +35,9 @@ import Data.Maybe (fromJust, fromMaybe, #if !MIN_VERSION_base(4,8,0) import Data.Monoid (mconcat) #endif +#if !MIN_VERSION_base(4,11,0) +import Data.Semigroup (Semigroup (..)) +#endif import Data.Monoid () import Data.Time.Format (formatTime) import Data.Typeable (Typeable) From 1d87b147a27b13777c2f3027f077da076bb812ba Mon Sep 17 00:00:00 2001 From: Henry Laxen Date: Sun, 24 May 2020 15:09:16 -0700 Subject: [PATCH 3/4] fixed Monoid in TestHandler --- .travis.yml | 18 ------------------ test/Test/Common/TestHandler.hs | 2 +- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8313f0b1..9ab65cd4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,24 +33,6 @@ before_cache: - rm -rfv $CABALHOME/packages/head.hackage jobs: include: - - compiler: ghc-8.10.1 - addons: {"apt":{"sources":[{"sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main","key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286"}],"packages":["ghc-8.10.1","cabal-install-3.2"]}} - os: linux - - compiler: ghc-8.8.3 - addons: {"apt":{"sources":[{"sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main","key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286"}],"packages":["ghc-8.8.3","cabal-install-3.2"]}} - os: linux - - compiler: ghc-8.6.5 - addons: {"apt":{"sources":[{"sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main","key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286"}],"packages":["ghc-8.6.5","cabal-install-3.2"]}} - os: linux - - compiler: ghc-8.4.4 - addons: {"apt":{"sources":[{"sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main","key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286"}],"packages":["ghc-8.4.4","cabal-install-3.2"]}} - os: linux - - compiler: ghc-8.2.2 - addons: {"apt":{"sources":[{"sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main","key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286"}],"packages":["ghc-8.2.2","cabal-install-3.2"]}} - os: linux - - compiler: ghc-8.0.2 - addons: {"apt":{"sources":[{"sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main","key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286"}],"packages":["ghc-8.0.2","cabal-install-3.2"]}} - os: linux - compiler: ghc-7.10.3 addons: {"apt":{"sources":[{"sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main","key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286"}],"packages":["ghc-7.10.3","cabal-install-3.2"]}} os: linux diff --git a/test/Test/Common/TestHandler.hs b/test/Test/Common/TestHandler.hs index 6125b5b0..002ead71 100644 --- a/test/Test/Common/TestHandler.hs +++ b/test/Test/Common/TestHandler.hs @@ -15,7 +15,7 @@ import qualified Data.ByteString.Lazy.Char8 as L import Data.List (sort) import qualified Data.Map as Map import Data.Maybe (fromMaybe) -import Data.Monoid () +import Data.Monoid (Monoid (mappend, mconcat, mempty)) ------------------------------------------------------------------------------ import Snap.Core (Request (rqParams, rqURI), Snap, getParam, getRequest, logError, modifyResponse, redirect, route, rqClientAddr, rqClientPort, setContentLength, setContentType, setHeader, setResponseBody, setResponseCode, setTimeout, transformRequestBody, writeBS, writeBuilder, writeLBS) import Snap.Internal.Debug () From 7d47dae1e68d8abbcff173fc87cbedd4fdd9fe04 Mon Sep 17 00:00:00 2001 From: Henry Laxen Date: Sun, 24 May 2020 20:08:54 -0700 Subject: [PATCH 4/4] fixed network socket import for old Network.Socket --- .travis.yml | 18 ++++++++++++++++++ src/Snap/Internal/Http/Server/Socket.hs | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/.travis.yml b/.travis.yml index 9ab65cd4..8313f0b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,6 +33,24 @@ before_cache: - rm -rfv $CABALHOME/packages/head.hackage jobs: include: + - compiler: ghc-8.10.1 + addons: {"apt":{"sources":[{"sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main","key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286"}],"packages":["ghc-8.10.1","cabal-install-3.2"]}} + os: linux + - compiler: ghc-8.8.3 + addons: {"apt":{"sources":[{"sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main","key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286"}],"packages":["ghc-8.8.3","cabal-install-3.2"]}} + os: linux + - compiler: ghc-8.6.5 + addons: {"apt":{"sources":[{"sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main","key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286"}],"packages":["ghc-8.6.5","cabal-install-3.2"]}} + os: linux + - compiler: ghc-8.4.4 + addons: {"apt":{"sources":[{"sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main","key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286"}],"packages":["ghc-8.4.4","cabal-install-3.2"]}} + os: linux + - compiler: ghc-8.2.2 + addons: {"apt":{"sources":[{"sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main","key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286"}],"packages":["ghc-8.2.2","cabal-install-3.2"]}} + os: linux + - compiler: ghc-8.0.2 + addons: {"apt":{"sources":[{"sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main","key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286"}],"packages":["ghc-8.0.2","cabal-install-3.2"]}} + os: linux - compiler: ghc-7.10.3 addons: {"apt":{"sources":[{"sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main","key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286"}],"packages":["ghc-7.10.3","cabal-install-3.2"]}} os: linux diff --git a/src/Snap/Internal/Http/Server/Socket.hs b/src/Snap/Internal/Http/Server/Socket.hs index d14d849d..e62b0e9c 100644 --- a/src/Snap/Internal/Http/Server/Socket.hs +++ b/src/Snap/Internal/Http/Server/Socket.hs @@ -21,7 +21,11 @@ import Data.ByteString.Char8 (ByteString) import Network.Socket (Socket, SocketOption (NoDelay, ReuseAddr), accept, close, getSocketName, setSocketOption, socket) import qualified Network.Socket as N #ifdef HAS_SENDFILE +#if MIN_VERSION_network(3,0,0) import Network.Socket (unsafeFdSocket) +#else +import Network.Socket (fdSocket) +#endif import System.Posix.IO (OpenMode (..), closeFd, defaultFileFlags, openFd) import System.Posix.Types (Fd (..)) import System.SendFile (sendFile, sendHeaders)