diff options
Diffstat (limited to 'src/Network/BitTorrent/Tracker/RPC/HTTP.hs')
-rw-r--r-- | src/Network/BitTorrent/Tracker/RPC/HTTP.hs | 13 |
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 | ||
29 | import Control.Applicative | 29 | import Control.Applicative |
30 | import Control.Exception | 30 | import Control.Exception |
31 | import Control.Monad | ||
31 | import Control.Monad.Trans.Resource | 32 | import Control.Monad.Trans.Resource |
32 | import Data.BEncode as BE | 33 | import Data.BEncode as BE |
33 | import Data.ByteString as BS | 34 | import 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 |