Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactored common code from http handlers out to an abstract class ca…

…lled GitServerHttpHandler.
  • Loading branch information...
commit 94d69abe1cd0bc822635f0b4dc12e459fae4ef04 1 parent a575be3
Amit Apple amitapl authored davidebbo committed
20 Kudu.Services/GitServer/FetchHandler.cs
View
@@ -12,20 +12,16 @@
using Kudu.Core.Infrastructure;
using Kudu.Core.SourceControl.Git;
using Newtonsoft.Json.Linq;
-using System.Net;
namespace Kudu.Services.GitServer
{
- public class FetchHandler : IHttpHandler
+ public class FetchHandler : GitServerHttpHandler
{
private const string PrivateKeyFile = "id_rsa";
private const string PublicKeyFile = "id_rsa.pub";
- private readonly IGitServer _gitServer;
private readonly IDeploymentManager _deploymentManager;
private readonly IDeploymentSettingsManager _settings;
- private readonly ITracer _tracer;
- private readonly IOperationLock _deploymentLock;
private readonly RepositoryConfiguration _configuration;
private readonly IEnvironment _environment;
@@ -36,24 +32,14 @@ public class FetchHandler : IHttpHandler
IOperationLock deploymentLock,
RepositoryConfiguration configuration,
IEnvironment environment)
+ : base(tracer, gitServer, deploymentLock)
{
- _gitServer = gitServer;
_deploymentManager = deploymentManager;
_settings = settings;
- _tracer = tracer;
- _deploymentLock = deploymentLock;
_configuration = configuration;
_environment = environment;
}
- public bool IsReusable
- {
- get
- {
- return false;
- }
- }
-
private string MarkerFilePath
{
get
@@ -62,7 +48,7 @@ private string MarkerFilePath
}
}
- public void ProcessRequest(HttpContext context)
+ public override void ProcessRequest(HttpContext context)
{
using (_tracer.Step("FetchHandler"))
{
80 Kudu.Services/GitServer/GitServerHttpHandler.cs
View
@@ -0,0 +1,80 @@
+#region License
+
+// Copyright 2010 Jeremy Skinner (http://www.jeremyskinner.co.uk)
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// The latest version of this file can be found at http://github.com/JeremySkinner/git-dot-aspx
+
+// This file was modified from the one found in git-dot-aspx
+
+#endregion
+
+using System.IO;
+using System.IO.Compression;
+using System.Web;
+using Kudu.Contracts.Infrastructure;
+using Kudu.Contracts.Tracing;
+using Kudu.Core.SourceControl.Git;
+
+namespace Kudu.Services.GitServer
+{
+ public abstract class GitServerHttpHandler : IHttpHandler
+ {
+ protected readonly IGitServer _gitServer;
+ protected readonly ITracer _tracer;
+ protected readonly IOperationLock _deploymentLock;
+
+ public GitServerHttpHandler(ITracer tracer, IGitServer gitServer, IOperationLock deploymentLock)
+ {
+ _gitServer = gitServer;
+ _tracer = tracer;
+ _deploymentLock = deploymentLock;
+ }
+
+ public virtual bool IsReusable
+ {
+ get
+ {
+ return false;
+ }
+ }
+
+ public abstract void ProcessRequest(HttpContext context);
+
+ protected void UpdateNoCacheForResponse(HttpResponse response)
+ {
+ response.Buffer = false;
+ response.BufferOutput = false;
+
+ response.AddHeader("Expires", "Fri, 01 Jan 1980 00:00:00 GMT");
+ response.AddHeader("Pragma", "no-cache");
+ response.AddHeader("Cache-Control", "no-cache, max-age=0, must-revalidate");
+ }
+
+ protected Stream GetInputStream(HttpRequest request)
+ {
+ using (_tracer.Step("RpcService.GetInputStream"))
+ {
+ var contentEncoding = request.Headers["Content-Encoding"];
+
+ if (contentEncoding != null && contentEncoding.Contains("gzip"))
+ {
+ return new GZipStream(request.InputStream, CompressionMode.Decompress);
+ }
+
+ return request.InputStream;
+ }
+ }
+ }
+}
43 Kudu.Services/GitServer/ReceivePackHandler.cs
View
@@ -20,8 +20,6 @@
#endregion
-using System.IO;
-using System.IO.Compression;
using System.Web;
using Kudu.Contracts.Infrastructure;
using Kudu.Contracts.Tracing;
@@ -30,30 +28,16 @@
namespace Kudu.Services.GitServer
{
- public class ReceivePackHandler : IHttpHandler
+ public class ReceivePackHandler : GitServerHttpHandler
{
- private readonly IGitServer _gitServer;
- private readonly ITracer _tracer;
- private readonly IOperationLock _deploymentLock;
-
public ReceivePackHandler(ITracer tracer,
IGitServer gitServer,
IOperationLock deploymentLock)
+ : base(tracer, gitServer, deploymentLock)
{
- _gitServer = gitServer;
- _tracer = tracer;
- _deploymentLock = deploymentLock;
}
- public bool IsReusable
- {
- get
- {
- return false;
- }
- }
-
- public void ProcessRequest(HttpContext context)
+ public override void ProcessRequest(HttpContext context)
{
using (_tracer.Step("RpcService.ReceivePack"))
{
@@ -65,13 +49,9 @@ public void ProcessRequest(HttpContext context)
_gitServer.SetDeployer(username);
}
- context.Response.Buffer = false;
- context.Response.BufferOutput = false;
+ UpdateNoCacheForResponse(context.Response);
context.Response.ContentType = "application/x-git-receive-pack-result";
- context.Response.AddHeader("Expires", "Fri, 01 Jan 1980 00:00:00 GMT");
- context.Response.AddHeader("Pragma", "no-cache");
- context.Response.AddHeader("Cache-Control", "no-cache, max-age=0, must-revalidate");
_gitServer.Receive(GetInputStream(context.Request), context.Response.OutputStream);
},
@@ -82,20 +62,5 @@ public void ProcessRequest(HttpContext context)
});
}
}
-
- private Stream GetInputStream(HttpRequest request)
- {
- using (_tracer.Step("RpcService.GetInputStream"))
- {
- var contentEncoding = request.Headers["Content-Encoding"];
-
- if (contentEncoding != null && contentEncoding.Contains("gzip"))
- {
- return new GZipStream(request.InputStream, CompressionMode.Decompress);
- }
-
- return request.InputStream;
- }
- }
}
}
43 Kudu.Services/GitServer/UploadPackHandler.cs
View
@@ -20,8 +20,6 @@
#endregion
-using System.IO;
-using System.IO.Compression;
using System.Web;
using Kudu.Contracts.Infrastructure;
using Kudu.Contracts.Tracing;
@@ -29,58 +27,25 @@
namespace Kudu.Services.GitServer
{
- public class UploadPackHandler : IHttpHandler
+ public class UploadPackHandler : GitServerHttpHandler
{
- private readonly IGitServer _gitServer;
- private readonly ITracer _tracer;
- private readonly IOperationLock _deploymentLock;
-
public UploadPackHandler(ITracer tracer,
IGitServer gitServer,
IOperationLock deploymentLock)
+ : base(tracer, gitServer, deploymentLock)
{
- _gitServer = gitServer;
- _tracer = tracer;
- _deploymentLock = deploymentLock;
}
- public bool IsReusable
- {
- get
- {
- return false;
- }
- }
-
- public void ProcessRequest(HttpContext context)
+ public override void ProcessRequest(HttpContext context)
{
using (_tracer.Step("RpcService.UploadPackHandler"))
{
- context.Response.Buffer = false;
- context.Response.BufferOutput = false;
+ UpdateNoCacheForResponse(context.Response);
context.Response.ContentType = "application/x-git-{0}-result".With("upload-pack");
- context.Response.AddHeader("Expires", "Fri, 01 Jan 1980 00:00:00 GMT");
- context.Response.AddHeader("Pragma", "no-cache");
- context.Response.AddHeader("Cache-Control", "no-cache, max-age=0, must-revalidate");
_gitServer.Upload(GetInputStream(context.Request), context.Response.OutputStream);
}
}
-
- private Stream GetInputStream(HttpRequest request)
- {
- using (_tracer.Step("RpcService.GetInputStream"))
- {
- var contentEncoding = request.Headers["Content-Encoding"];
-
- if (contentEncoding != null && contentEncoding.Contains("gzip"))
- {
- return new GZipStream(request.InputStream, CompressionMode.Decompress);
- }
-
- return request.InputStream;
- }
- }
}
}
1  Kudu.Services/Kudu.Services.csproj
View
@@ -91,6 +91,7 @@
</Compile>
<Compile Include="Commands\CommandController.cs" />
<Compile Include="Deployment\DeploymentController.cs" />
+ <Compile Include="GitServer\GitServerHttpHandler.cs" />
<Compile Include="GitServer\UploadPackHandler.cs" />
<Compile Include="SSHKey\SSHKeyController.cs" />
<Compile Include="Editor\FilesController.cs" />
Please sign in to comment.
Something went wrong with that request. Please try again.