@@ -16,6 +16,7 @@ import Control.Arrow ((&&&))
17import Data.Monoid
17import Data.Monoid
18import Data.ByteString (ByteString)
18import Data.ByteString (ByteString)
19+import qualified Data.ByteString as BS
20import Data.Int
21import Data.Int
21import Data.Word
22import Data.Word
@@ -149,7 +150,8 @@ showt = T.pack . show
150-- | /Case insensitive/.
151-- | /Case insensitive/.
152−-- Parse given text case insensitive and return the rest of the input.
153+-- Parse given text case insensitive and then parse the rest of the input
154+-- using @'parseUrlPiece'@.
154-- >>> parseUrlPieceWithPrefix "Just " "just 10" :: Either Text Int
156-- >>> parseUrlPieceWithPrefix "Just " "just 10" :: Either Text Int
155-- Right 10
157-- Right 10
@@ -169,6 +171,36 @@ parseUrlPieceWithPrefix pattern input
170 (prefix, rest) = T.splitAt (T.length pattern) input
172 (prefix, rest) = T.splitAt (T.length pattern) input
174+-- | Parse given bytestring then parse the rest of the input using @'parseHeader'@.
177+-- newtype BasicAuthToken = BasicAuthToken Text deriving (Show)
178+-- instance FromHttpApiData BasicAuthToken where
179+-- parseHeader h = BasicAuthToken <$> parseHeaderWithPrefix "Basic " h
180+-- parseQueryParam p = BasicAuthToken <$> parseQueryParam p
183+-- >>> parseHeader "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" :: Either Text BasicAuthToken
184+-- Right (BasicAuthToken "QWxhZGRpbjpvcGVuIHNlc2FtZQ==")
185+parseHeaderWithPrefix :: FromHttpApiData a => ByteString -> ByteString -> Either Text a
186+parseHeaderWithPrefix pattern input
187+ | pattern `BS.isPrefixOf` input = parseHeader (BS.drop (BS.length pattern) input)
188+ | otherwise = defaultParseError (showt input)
190+-- | /Case insensitive/.
192+-- Parse given text case insensitive and then parse the rest of the input
193+-- using @'parseQueryParam'@.
195+-- >>> parseQueryParamWithPrefix "z" "z10" :: Either Text Int
197+parseQueryParamWithPrefix :: FromHttpApiData a => Text -> Text -> Either Text a
198+parseQueryParamWithPrefix pattern input
199+ | T.toLower pattern == T.toLower prefix = parseQueryParam rest
200+ | otherwise = defaultParseError input
202+ (prefix, rest) = T.splitAt (T.length pattern) input
172#if USE_TEXT_SHOW
204#if USE_TEXT_SHOW
173-- | /Case insensitive/.
205-- | /Case insensitive/.