From 2aaeb4711b0e38993a9a242664abc5639f3d1da4 Mon Sep 17 00:00:00 2001 From: Artyom Date: Fri, 8 Apr 2016 23:40:09 +0300 Subject: [PATCH] Throw an error when the IP couldn't be parsed --- src/Main.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Main.hs b/src/Main.hs index 49822b6..da3629b 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -129,7 +129,11 @@ addEdit ed = do (Spock.header "X-Forwarded-For") ip <- case mbForwardedFor of Nothing -> sockAddrToIP . Wai.remoteHost <$> Spock.request - Just ff -> return (read (T.unpack ip)) + Just ff -> case readMaybe (T.unpack ip) of + Nothing -> error ("couldn't read Forwarded-For address: " ++ + show ip ++ " (full header: " ++ + show ff ++ ")") + Just i -> return i where addr = T.strip . snd . T.breakOnEnd "," $ ff ip -- [IPv6]:port