1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-27 17:54:53 +09:00

Git upload-pack request handler, parses it but returns nothing

This commit is contained in:
fr33domlover 2016-04-26 05:58:05 +00:00
parent 4381213446
commit 66bc49df15
2 changed files with 41 additions and 22 deletions

View file

@ -16,27 +16,35 @@
-- | Custom HTTP response content types.
module Vervis.Content
( GitRefDiscovery (..)
, GitUploadPackResult (..)
)
where
import Prelude
import Data.ByteString (ByteString)
import Data.Monoid ((<>))
import Network.Git.Put (serializeService)
import Network.Git.Transport.HTTP.Fetch.RefDiscovery
import Yesod.Core.Content
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
data GitRefDiscovery = GitRefDiscovery
{ grdContent :: BL.ByteString
, grdService :: B.ByteString
}
newtype GitRefDiscovery = GitRefDiscovery { unGRD :: RefDiscover }
instance ToContent GitRefDiscovery where
toContent (GitRefDiscovery c _) = toContent c
toContent = toContent . serializeRefDiscover . unGRD
instance ToTypedContent GitRefDiscovery where
toTypedContent grd@(GitRefDiscovery _ s) =
let t = "application/x-" <> s <> "-advertisement"
toTypedContent grd =
let serv = rdService $ unGRD grd
t = "application/x-" <> serializeService serv <> "-advertisement"
c = toContent grd
in TypedContent t c
newtype GitUploadPackResult = GitUploadPackResult { unGUPR :: () }
instance ToContent GitUploadPackResult where
toContent = toContent . unGUPR
instance ToTypedContent GitUploadPackResult where
toTypedContent gupr =
TypedContent "application/x-git-upload-pack-result" (toContent gupr)

View file

@ -25,10 +25,14 @@ import Control.Monad.IO.Class (liftIO)
import Data.Git.Storage (isRepo, withRepo)
import Data.String (fromString)
import Data.Text (Text)
import Data.Text.Encoding (encodeUtf8)
import Network.Git.Get (parseService)
import Network.Git.Transport.HTTP.Fetch.RefDiscovery
import Network.Git.Transport.HTTP.Fetch.UploadRequest
import Yesod.Core.Handler
import Vervis.Content (GitRefDiscovery (..))
import Vervis.BinaryBody (decodeRequestBody)
import Vervis.Content
import Vervis.Foundation (Handler)
import Vervis.Path (askRepoDir)
@ -41,19 +45,26 @@ getGitRefDiscoverR sharer repo = do
then do
rq <- getRequest
case reqGetParams rq of
[("service", serv)] ->
if serv == "git-upload-pack"
then do
[("service", servT)] ->
case parseService $ encodeUtf8 servT of
Just serv -> do
rd <- liftIO $ withRepo pathG $
flip buildRefDiscover' "git-upload-pack"
flip buildRefDiscover' serv
setHeader "Cache-Control" "no-cache"
return GitRefDiscovery
{ grdContent = serializeRefDiscover rd
, grdService = "git-upload-pack"
}
else permissionDenied "Service not supported"
return $ GitRefDiscovery rd
Nothing -> permissionDenied "Service not supported"
_ -> notFound
else notFound
postGitUploadRequestR :: Text -> Text -> Handler Text
postGitUploadRequestR sharer repo = notFound
postGitUploadRequestR :: Text -> Text -> Handler GitUploadPackResult
postGitUploadRequestR sharer repo = do
path <- askRepoDir sharer repo
let pathG = fromString path
seemsThere <- liftIO $ isRepo pathG
if seemsThere
then do
ereq <- decodeRequestBody getUploadRequest
case ereq of
Left _ -> invalidArgs ["UploadRequest"]
Right ur -> return $ GitUploadPackResult ()
else notFound