mirror of
https://github.com/snoyberg/keter.git
synced 2024-12-12 14:06:10 +03:00
Fix warnings
This commit is contained in:
parent
1cf11ffb0a
commit
5e857eb989
@ -66,12 +66,12 @@ openRotatingLog :: FilePath -- ^ folder to contain logs
|
||||
openRotatingLog dir maxTotal = do
|
||||
createDirectoryIfMissing True dir
|
||||
bracketOnError (moveCurrent dir) SIO.hClose $ \handle -> do
|
||||
queue <- newTBQueueIO 5
|
||||
let s = Running handle queue
|
||||
queue' <- newTBQueueIO 5
|
||||
let s = Running handle queue'
|
||||
ts <- newTVarIO s
|
||||
void $ forkIO $ loop dir ts maxTotal
|
||||
let rl = RotatingLog ts
|
||||
addFinalizer rl (atomically (writeTBQueue queue Close))
|
||||
addFinalizer rl (atomically (writeTBQueue queue' Close))
|
||||
return rl
|
||||
|
||||
current :: FilePath -- ^ folder containing logs
|
||||
@ -117,14 +117,14 @@ loop dir ts maxTotal =
|
||||
s <- readTVar ts
|
||||
case s of
|
||||
Closed -> return Nothing
|
||||
Running handle queue -> do
|
||||
cmd <- readTBQueue queue
|
||||
Running handle queue' -> do
|
||||
cmd <- readTBQueue queue'
|
||||
case cmd of
|
||||
Close -> return Nothing
|
||||
AddChunk bs -> return $! Just (handle, queue, bs)
|
||||
AddChunk bs -> return $! Just (handle, queue', bs)
|
||||
case res of
|
||||
Nothing -> return ()
|
||||
Just (handle, queue, bs) -> do
|
||||
Just (handle, queue', bs) -> do
|
||||
let total' = total + fromIntegral (S.length bs)
|
||||
S.hPut handle bs
|
||||
SIO.hFlush handle
|
||||
@ -132,7 +132,7 @@ loop dir ts maxTotal =
|
||||
then do
|
||||
bracket
|
||||
(SIO.hClose handle >> moveCurrent dir)
|
||||
(\handle' -> atomically $ writeTVar ts $ Running handle' queue)
|
||||
(\handle' -> atomically $ writeTVar ts $ Running handle' queue')
|
||||
(const $ return ())
|
||||
go 0
|
||||
else go total'
|
||||
|
@ -44,10 +44,9 @@ import Data.Typeable (Typeable)
|
||||
import Foreign.C.Types
|
||||
import Prelude (Bool (..), Either (..), IO,
|
||||
Maybe (..), Monad (..), Show,
|
||||
const, error, flip, fmap,
|
||||
fromIntegral, fst, head, id,
|
||||
length, map, maybe, show, snd,
|
||||
($), ($!), (*), (.), (<),
|
||||
const, error,
|
||||
map, maybe, show,
|
||||
($), ($!), (*), (<),
|
||||
(==))
|
||||
import System.Exit (ExitCode)
|
||||
import System.IO (hClose)
|
||||
|
@ -28,6 +28,7 @@ import Data.Text.Encoding (encodeUtf8)
|
||||
import Keter.Types
|
||||
import Keter.LabelMap (LabelMap)
|
||||
import qualified Keter.LabelMap as LabelMap
|
||||
import Prelude hiding (log)
|
||||
|
||||
type HMState = LabelMap HostValue
|
||||
|
||||
|
@ -224,7 +224,7 @@ lookupTree [] _ = Nothing
|
||||
lookupTree _ EmptyLabelMap = Nothing
|
||||
|
||||
lookupTree [l] (Static t) = Map.lookup l t >>= getPortEntry
|
||||
lookupTree (_:_) (Wildcard w) = getPortEntry $ w
|
||||
--lookupTree (_:_) (Wildcard w) = getPortEntry $ w
|
||||
lookupTree [l] (WildcardExcept w t) =
|
||||
case Map.lookup l t >>= getPortEntry of
|
||||
Just e -> Just e
|
||||
|
@ -147,7 +147,7 @@ startWatching :: KeterConfig -> AppMan.AppManager -> (LogMessage -> IO ()) -> IO
|
||||
startWatching kc@KeterConfig {..} appMan log = do
|
||||
-- File system watching
|
||||
wm <- FSN.startManager
|
||||
FSN.watchDir wm incoming (const True) $ \e -> do
|
||||
_ <- FSN.watchDir wm incoming (const True) $ \e -> do
|
||||
e' <-
|
||||
case e of
|
||||
FSN.Removed fp _ -> do
|
||||
|
@ -44,10 +44,7 @@ reverseProxy :: Bool -> Manager -> HostLookup -> ListeningPort -> IO ()
|
||||
reverseProxy useHeader manager hostLookup listener =
|
||||
run $ withClient useHeader manager hostLookup
|
||||
where
|
||||
warp host port = Warp.defaultSettings
|
||||
{ Warp.settingsHost = host
|
||||
, Warp.settingsPort = port
|
||||
}
|
||||
warp host port = Warp.setHost host $ Warp.setPort port Warp.defaultSettings
|
||||
run =
|
||||
case listener of
|
||||
LPInsecure host port -> Warp.runSettings (warp host port)
|
||||
@ -59,13 +56,13 @@ withClient :: Bool -- ^ use incoming request header for IP address
|
||||
-> Manager
|
||||
-> HostLookup
|
||||
-> Wai.Application
|
||||
withClient useHeader manager portLookup req sendResponse =
|
||||
withClient useHeader manager portLookup req0 sendResponse =
|
||||
timeBound (5 * 60 * 1000 * 1000) (waiProxyToSettings getDest def
|
||||
{ wpsSetIpHeader =
|
||||
if useHeader
|
||||
then SIHFromHeader
|
||||
else SIHFromSocket
|
||||
} manager req sendResponse) sendResponse
|
||||
} manager req0 sendResponse)
|
||||
where
|
||||
-- FIXME This is a temporary workaround for
|
||||
-- https://github.com/snoyberg/keter/issues/29. After some research, it
|
||||
@ -74,7 +71,7 @@ withClient useHeader manager portLookup req sendResponse =
|
||||
-- infinitely without the server it's connecting to going down, so that
|
||||
-- requires more research. Meanwhile, this prevents the file descriptor
|
||||
-- leak from occurring.
|
||||
timeBound us f sendResponse = do
|
||||
timeBound us f = do
|
||||
mres <- timeout us f
|
||||
case mres of
|
||||
Just res -> return res
|
||||
|
@ -114,10 +114,9 @@ instance ParseYamlFile TLSConfig where
|
||||
host <- (fmap fromString <$> o .:? "host") .!= "*"
|
||||
port <- o .:? "port" .!= 443
|
||||
return $! TLSConfig
|
||||
Warp.defaultSettings
|
||||
{ Warp.settingsHost = host
|
||||
, Warp.settingsPort = port
|
||||
}
|
||||
( Warp.setHost host
|
||||
$ Warp.setPort port
|
||||
Warp.defaultSettings)
|
||||
WarpTLS.defaultTlsSettings
|
||||
{ WarpTLS.certFile = encodeString cert
|
||||
, WarpTLS.keyFile = encodeString key
|
||||
|
@ -12,7 +12,7 @@ import Keter.Types.Common
|
||||
import qualified Keter.Types.V04 as V04
|
||||
import Data.Yaml.FilePath
|
||||
import Data.Aeson (FromJSON (..), (.:), (.:?), Value (Object, String), withObject, (.!=))
|
||||
import Control.Applicative ((<$>), (<*>), pure, (<|>))
|
||||
import Control.Applicative ((<$>), (<*>), (<|>))
|
||||
import qualified Data.Set as Set
|
||||
import qualified Filesystem.Path.CurrentOS as F
|
||||
import Data.Default
|
||||
@ -20,7 +20,6 @@ import Data.String (fromString)
|
||||
import Data.Conduit.Network (HostPreference)
|
||||
import Data.Vector (Vector)
|
||||
import qualified Data.Vector as V
|
||||
import Data.Monoid (mempty)
|
||||
import Network.HTTP.ReverseProxy.Rewrite (ReverseProxyConfig)
|
||||
import Data.Maybe (fromMaybe, catMaybes)
|
||||
import qualified Network.Wai.Handler.Warp as Warp
|
||||
@ -104,8 +103,8 @@ instance ToCurrent KeterConfig where
|
||||
where
|
||||
getSSL Nothing = V.empty
|
||||
getSSL (Just (V04.TLSConfig s ts)) = V.singleton $ LPSecure
|
||||
(Warp.settingsHost s)
|
||||
(Warp.settingsPort s)
|
||||
(Warp.getHost s)
|
||||
(Warp.getPort s)
|
||||
(F.decodeString $ WarpTLS.certFile ts)
|
||||
(F.decodeString $ WarpTLS.keyFile ts)
|
||||
|
||||
@ -174,6 +173,7 @@ instance ToJSON (Stanza ()) where
|
||||
toJSON (StanzaReverseProxy x) = addStanzaType "reverse-proxy" x
|
||||
toJSON (StanzaBackground x) = addStanzaType "background" x
|
||||
|
||||
addStanzaType :: ToJSON a => Value -> a -> Value
|
||||
addStanzaType t x =
|
||||
case toJSON x of
|
||||
Object o -> Object $ HashMap.insert "type" t o
|
||||
|
@ -20,14 +20,12 @@ import Data.Map ( Map )
|
||||
import Data.Array ((!))
|
||||
import Data.Aeson
|
||||
import Control.Monad (unless)
|
||||
import Control.Monad.IO.Class (liftIO)
|
||||
|
||||
import qualified Data.ByteString as S
|
||||
import qualified Data.Text as T
|
||||
import Data.Text (Text)
|
||||
import Data.Text.Encoding (encodeUtf8, decodeUtf8)
|
||||
import qualified Data.CaseInsensitive as CI
|
||||
import Control.Monad.Trans.Reader (runReaderT)
|
||||
|
||||
import Blaze.ByteString.Builder (fromByteString)
|
||||
|
||||
@ -41,8 +39,6 @@ import Text.Regex.TDFA.String (Regex)
|
||||
import Data.Char (isDigit)
|
||||
|
||||
-- Reverse proxy apparatus
|
||||
import Data.Conduit
|
||||
|
||||
import qualified Network.Wai as Wai
|
||||
import Network.HTTP.Client.Conduit
|
||||
import qualified Network.HTTP.Client as NHC
|
||||
@ -153,7 +149,7 @@ simpleReverseProxy mgr rpConfig request sendResponse = bracket
|
||||
sendBody body send _flush = fix $ \loop -> do
|
||||
bs <- body
|
||||
unless (S.null bs) $ do
|
||||
send $ fromByteString bs
|
||||
() <- send $ fromByteString bs
|
||||
loop
|
||||
|
||||
data ReverseProxyConfig = ReverseProxyConfig
|
||||
|
Loading…
Reference in New Issue
Block a user