protected bool HasAccess(Rpc rpc, bool checkContentType = false) { if (checkContentType && Request.ContentType != string.Format("application/x-git-{0}-request", rpc.GetDescription())) { return false; } if (rpc == Rpc.ReceivePack) { return AppSettings.ReceivePack; } if (rpc == Rpc.UploadPack) { return AppSettings.UploadPack; } return false; }
ActionResult ExecuteRpc(string project, Rpc rpc, Action<Repository> action) { if (!HasAccess(rpc, checkContentType: true)) { return new ForbiddenResult(); } Response.ContentType = string.Format("application/x-git-{0}-result", rpc.GetDescription()); WriteNoCache(); var repository = repositories.GetRepository(project); if (repository == null) { return new NotFoundResult(); } using (repository) { action(repository); } return new EmptyResult(); }