summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Tracker/RPC
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-03-02 16:26:15 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-03-02 16:26:15 +0400
commit215e478f5fbf90c528191beb211df3860f8d7ac4 (patch)
tree1da6beaa3f84470f0e8315870a93c721feaaf4ea /src/Network/BitTorrent/Tracker/RPC
parentb528cdfa794683d2ec0ee4c8785e1371171ba85e (diff)
Fix scrapeURL: do not throw exception
Diffstat (limited to 'src/Network/BitTorrent/Tracker/RPC')
-rw-r--r--src/Network/BitTorrent/Tracker/RPC/HTTP.hs13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/Network/BitTorrent/Tracker/RPC/HTTP.hs b/src/Network/BitTorrent/Tracker/RPC/HTTP.hs
index 33ceb077..81199921 100644
--- a/src/Network/BitTorrent/Tracker/RPC/HTTP.hs
+++ b/src/Network/BitTorrent/Tracker/RPC/HTTP.hs
@@ -28,6 +28,7 @@ module Network.BitTorrent.Tracker.RPC.HTTP
28 28
29import Control.Applicative 29import Control.Applicative
30import Control.Exception 30import Control.Exception
31import Control.Monad
31import Control.Monad.Trans.Resource 32import Control.Monad.Trans.Resource
32import Data.BEncode as BE 33import Data.BEncode as BE
33import Data.ByteString as BS 34import Data.ByteString as BS
@@ -159,12 +160,12 @@ scrapeURL uri = do
159 newPath <- replace (BC.pack (uriPath uri)) 160 newPath <- replace (BC.pack (uriPath uri))
160 return uri { uriPath = BC.unpack newPath } 161 return uri { uriPath = BC.unpack newPath }
161 where 162 where
162 replace p 163 replace p = do
163 | ps <- BC.splitWith (== '/') p 164 let ps = BC.splitWith (== '/') p
164 , "announce" `BS.isPrefixOf` L.last ps 165 guard (not (L.null ps))
165 = let newSuff = "scrape" <> BS.drop (BS.length "announce") (L.last ps) 166 guard ("announce" `BS.isPrefixOf` L.last ps)
166 in Just (BS.intercalate "/" (L.init ps ++ [newSuff])) 167 let newSuff = "scrape" <> BS.drop (BS.length "announce") (L.last ps)
167 | otherwise = Nothing 168 return (BS.intercalate "/" (L.init ps ++ [newSuff]))
168 169
169-- | For each 'InfoHash' of torrents request scrape info from the tracker. 170-- | For each 'InfoHash' of torrents request scrape info from the tracker.
170-- However if the info hash list is 'null', the tracker should list 171-- However if the info hash list is 'null', the tracker should list