From 60d21cfefd82995265c00df9136b19fefa8910ac Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Thu, 28 Nov 2013 15:00:13 +0400 Subject: Get rid of the urlencoded package * It uses slow String's instead of Text. * It does not allow to encode infohash and peer ids properly. * It does not provide API for query string parsing. So it is better to use http-types package. --- src/Data/Torrent.hs | 4 ++-- src/Data/Torrent/Progress.hs | 24 ++++++++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) (limited to 'src/Data') diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs index e4b17c2b..d6227b6f 100644 --- a/src/Data/Torrent.hs +++ b/src/Data/Torrent.hs @@ -78,6 +78,7 @@ import Data.ByteString as BS import qualified Data.ByteString.Char8 as BC (pack, unpack) import qualified Data.ByteString.Lazy as BL import Data.Char as Char +import Data.Default import Data.Hashable as Hashable import qualified Data.List as L import Data.Maybe @@ -143,8 +144,7 @@ instance Hashable InfoDict where infoDictionary :: LayoutInfo -> PieceInfo -> Bool -> InfoDict infoDictionary li pinfo private = InfoDict ih li pinfo private where - ih = hashLazyIH $ encode $ InfoDict fake_ih li pinfo private - fake_ih = "0123456789012345678901234567890123456789" + ih = hashLazyIH $ encode $ InfoDict def li pinfo private getPrivate :: Get Bool getPrivate = (Just True ==) <$>? "private" diff --git a/src/Data/Torrent/Progress.hs b/src/Data/Torrent/Progress.hs index d0aa75c6..1a4a68e2 100644 --- a/src/Data/Torrent/Progress.hs +++ b/src/Data/Torrent/Progress.hs @@ -12,6 +12,7 @@ -- {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE ViewPatterns #-} +{-# OPTIONS -fno-warn-orphans #-} module Data.Torrent.Progress ( -- * Progress Progress (..) @@ -36,13 +37,15 @@ module Data.Torrent.Progress import Control.Applicative import Control.Lens hiding ((%=)) import Data.Aeson.TH +import Data.ByteString.Lazy.Builder as BS +import Data.ByteString.Lazy.Builder.ASCII as BS import Data.Default import Data.List as L import Data.Monoid import Data.Serialize as S import Data.Ratio -import Data.URLEncoded import Data.Word +import Network.HTTP.Types.QueryLike import Text.PrettyPrint as PP import Text.PrettyPrint.Class @@ -89,18 +92,19 @@ instance Monoid Progress where } {-# INLINE mappend #-} -instance URLShow Word64 where - urlShow = show - {-# INLINE urlShow #-} +instance QueryValueLike Builder where + toQueryValue = toQueryValue . BS.toLazyByteString + +instance QueryValueLike Word64 where + toQueryValue = toQueryValue . BS.word64Dec -- | HTTP Tracker protocol compatible encoding. -instance URLEncode Progress where - urlEncode Progress {..} = mconcat - [ s "uploaded" %= _uploaded - , s "left" %= _left - , s "downloaded" %= _downloaded +instance QueryLike Progress where + toQuery Progress {..} = + [ ("uploaded" , toQueryValue _uploaded) + , ("left" , toQueryValue _left) + , ("downloaded", toQueryValue _downloaded) ] - where s :: String -> String; s = id; {-# INLINE s #-} instance Pretty Progress where pretty Progress {..} = -- cgit v1.2.3