From da245d5d462cb9c98d3a52b4b467db8ce0281ae7 Mon Sep 17 00:00:00 2001 From: Anton Kortunov Date: Mon, 18 Apr 2011 17:11:53 +0400 Subject: [PATCH 1/2] Fix GitAuthenticationMode param handling --- GitTools/GitHandler.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GitTools/GitHandler.cs b/GitTools/GitHandler.cs index 165d790..80184bc 100644 --- a/GitTools/GitHandler.cs +++ b/GitTools/GitHandler.cs @@ -88,9 +88,9 @@ private bool HasAccess() { var authMode = ConfigurationManager.AppSettings["GitAuthenticationMode"]; - if (string.Compare(authMode, "none", true)==0) return true; - - if (string.Compare(authMode, "all")==0 || context.Request.RawUrl.IndexOf("git-receive-pack") >= 0) + if (string.IsNullOrEmpty(authMode) || authMode.Equals("none")) return true; + + if (authMode.Equals("all") || context.Request.RawUrl.IndexOf("git-receive-pack") >= 0) { string authHeader = context.Request.Headers["Authorization"]; From 9c68bad9bd1c6c00d5b46bbf10f290c7accda1ee Mon Sep 17 00:00:00 2001 From: Anton Kortunov Date: Mon, 18 Apr 2011 17:13:30 +0400 Subject: [PATCH 2/2] Add gzipped POST support --- GitTools/GitHandler.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/GitTools/GitHandler.cs b/GitTools/GitHandler.cs index 80184bc..77d72e3 100644 --- a/GitTools/GitHandler.cs +++ b/GitTools/GitHandler.cs @@ -138,11 +138,20 @@ private void ServiceRpc(string serviceName) using (var file = File.Create(fin)) { - byte[] buffer = new byte[4096]; - int bytesRead; - while ((bytesRead = context.Request.InputStream.Read(buffer, 0, buffer.Length)) != 0) + var encoding = context.Request.Headers["Content-Encoding"]; + if (string.IsNullOrEmpty(encoding)) + encoding = context.Request.ContentEncoding.EncodingName; + + if (encoding.Equals("gzip")) + { + using (GZipStream decomp = new GZipStream(context.Request.InputStream, CompressionMode.Decompress)) + { + decomp.CopyTo(file); + } + } + else { - file.Write(buffer, 0, bytesRead); + context.Request.InputStream.CopyTo(file); } }