git.iko.soy/typeable/http-api-data
on master help sign in
Add toEncodedUrlPiece
a10979bEdsko de Vries
http-api-data.cabal+1
@@ -41,6 +41,7 @@ library
41 , bytestring
41 , bytestring
42 , containers
42 , containers
43 , hashable
43 , hashable
44+ , http-types
44 , text >= 0.5
45 , text >= 0.5
45 , time
46 , time
46 , time-locale-compat >=0.1.1.0 && <0.2
47 , time-locale-compat >=0.1.1.0 && <0.2
src/Web/Internal/HttpApiData.hs+7
@@ -55,6 +55,9 @@ import qualified Data.UUID.Types as UUID
55
55
56import Data.Typeable (Typeable)
56import Data.Typeable (Typeable)
57import Data.Data (Data)
57import Data.Data (Data)
58+import qualified Data.ByteString.Builder as BS
59+import qualified Network.HTTP.Types as H
60+
58
61
59-- $setup
62-- $setup
60-- >>> data BasicAuthToken = BasicAuthToken Text deriving (Show)
63-- >>> data BasicAuthToken = BasicAuthToken Text deriving (Show)
@@ -70,6 +73,10 @@ class ToHttpApiData a where
70 toUrlPiece :: a -> Text
73 toUrlPiece :: a -> Text
71 toUrlPiece = toQueryParam
74 toUrlPiece = toQueryParam
72
75
76+ -- | Convert to a URL path piece, making sure to encode any special chars
77+ toEncodedUrlPiece :: a -> BS.Builder
78+ toEncodedUrlPiece = H.encodePathSegmentsRelative . (:[]) . toUrlPiece
79+
73 -- | Convert to HTTP header value.
80 -- | Convert to HTTP header value.
74 toHeader :: a -> ByteString
81 toHeader :: a -> ByteString
75 toHeader = encodeUtf8 . toUrlPiece
82 toHeader = encodeUtf8 . toUrlPiece