Skip to content

Commit

Permalink
Changed the GitCommandResult, the GitStreamResult, and the `GitFi…
Browse files Browse the repository at this point in the history
…leResult` to write data directly in binary format.

This prevents the transmission of the `charset=iso-8859-1` piece in the Content-type header, which was causing issues with JGit.  This is more for #24.
  • Loading branch information
otac0n committed Sep 16, 2011
1 parent ea29e32 commit f82a433
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions WebGitNet/ActionResults/GitCommandResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,23 @@ public override void ExecuteResult(ControllerContext context)
var response = context.HttpContext.Response;

var commandResult = GitUtilities.Execute(string.Format(this.commandFormat, this.service), this.workingDir);
var commandData = GitUtilities.DefaultEncoding.GetBytes(commandResult);

response.StatusCode = 200;
response.ContentType = "application/x-git-" + this.service + "-advertisement";
response.ContentEncoding = GitUtilities.DefaultEncoding;
response.Write(PacketFormat(string.Format("# service=git-{0}\n", this.service)));
response.Write(PacketFlush());
response.Write(commandResult);
response.BinaryWrite(PacketFormat(string.Format("# service=git-{0}\n", this.service)));
response.BinaryWrite(PacketFlush());
response.BinaryWrite(commandData);
}

private static string PacketFormat(string packet)
private static byte[] PacketFormat(string packet)
{
return (packet.Length + 4).ToString("X").ToLower().PadLeft(4, '0') + packet;
return GitUtilities.DefaultEncoding.GetBytes((packet.Length + 4).ToString("X").ToLower().PadLeft(4, '0') + packet);
}

private static string PacketFlush()
private static byte[] PacketFlush()
{
return "0000";
return new[] { (byte)'0', (byte)'0', (byte)'0', (byte)'0' };
}
}
}
4 changes: 2 additions & 2 deletions WebGitNet/ActionResults/GitFileResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public override void ExecuteResult(ControllerContext context)

response.ContentType = this.contentType;
response.AddHeader("Content-disposition", "attachment");
response.ContentEncoding = GitUtilities.DefaultEncoding;
response.Buffer = false;
response.BufferOutput = false;

Expand All @@ -41,7 +40,8 @@ public override void ExecuteResult(ControllerContext context)
int writeCount;
while ((writeCount = git.StandardOutput.ReadBlock(writeBuffer, 0, writeBuffer.Length)) > 0)
{
response.Write(writeBuffer, 0, writeCount);
var bytes = GitUtilities.DefaultEncoding.GetBytes(writeBuffer, 0, writeCount);
response.BinaryWrite(bytes);
}

git.WaitForExit();
Expand Down
4 changes: 2 additions & 2 deletions WebGitNet/ActionResults/GitStreamResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public override void ExecuteResult(ControllerContext context)
var request = context.HttpContext.Request;

response.ContentType = "application/git-" + this.action + "-result";
response.ContentEncoding = GitUtilities.DefaultEncoding;

using (var git = GitUtilities.Start(string.Format(this.commandFormat, this.action), this.repoPath, redirectInput: true))
{
Expand Down Expand Up @@ -88,7 +87,8 @@ public override void ExecuteResult(ControllerContext context)
int writeCount;
while ((writeCount = git.StandardOutput.ReadBlock(writeBuffer, 0, writeBuffer.Length)) > 0)
{
response.Write(writeBuffer, 0, writeCount);
var bytes = GitUtilities.DefaultEncoding.GetBytes(writeBuffer, 0, writeCount);
response.BinaryWrite(bytes);
}

readThread.Join();
Expand Down

0 comments on commit f82a433

Please sign in to comment.