1
1
mirror of https://github.com/aelve/guide.git synced 2024-11-23 21:13:07 +03:00

Throw an error when the IP couldn't be parsed

This commit is contained in:
Artyom 2016-04-08 23:40:09 +03:00
parent f8c5f5c6b7
commit 2aaeb4711b

View File

@ -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