you're telling me a puppy coded this??
module API.WebFinger (handleQuery) where

import Control.Monad (join)
import Data.Functor ((<&>))
import Data.Result
import Effectful
import Network.Wai (Request (..))
import Puppy.Logging (Log)
import qualified Data.ByteString as BS
import qualified Data.Text.Encoding as T
import qualified Puppy.Protocol.WebFinger as WebFinger

handleQuery
  :: (Log :> es)
  => Request 
  -> Eff es Result
handleQuery req = do
  let resource = 
        join (lookup "resource" (queryString req))
          >>= BS.stripPrefix "acct:"
          >>= WebFinger.parseHandle . T.decodeUtf8
  case resource of
    Just res -> WebFinger.lookupLocal res <&> maybe
      (Error 404 "No such resource")
      Value
    Nothing -> return (Error 400 "Bad resource")