Skip to content

Commit

Permalink
This needs to be cleaned up, but it gets things working with textwrit…
Browse files Browse the repository at this point in the history
…ters. Tomorrow will make everything use the stream internally.
  • Loading branch information
jacksonh committed Oct 23, 2010
1 parent dc6af03 commit 5c1d464
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
15 changes: 9 additions & 6 deletions src/Manos/Manos.Server/HttpResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void SendFile (string file)

Headers.ContentLength = fi.Length;

WriteMetaData ();
WriteMetaData (false);
Transaction.Write (Stream.GetBuffers ());
Transaction.SendFile (file);
}
Expand All @@ -145,19 +145,22 @@ public void Redirect (string url)
StatusCode = 302;
Headers.SetNormalizedHeader ("Location", url);

WriteMetaData ();
WriteMetaData (false);
}

public void WriteMetaData ()
public void WriteMetaData (bool update_size)
{
if (metadata_written)
return;

StringBuilder builder = new StringBuilder ();
WriteStatusLine (builder);

if (WriteHeaders)
if (WriteHeaders) {
if (update_size)
Headers.ContentLength = Stream.Position;
Headers.Write (builder, Cookies.Values, Encoding);
}

byte [] data = Encoding.GetBytes (builder.ToString ());

Expand All @@ -169,8 +172,8 @@ public void WriteMetaData ()

public void Finish ()
{
WriteMetaData ();
WriteMetaData (true);

Transaction.Write (Stream.GetBuffers ());
Transaction.Finish ();
}
Expand Down
12 changes: 9 additions & 3 deletions src/Manos/Manos.Server/HttpResponseStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

using System;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -284,8 +285,8 @@ public override void SetLength (long value)
public void Insert (byte [] buffer, int offset, int count)
{
if (AtEnd) {
Write (buffer, offset, count);
return;
Write (buffer, offset, count);
return;
}

var segment = new ArraySegment<byte> (buffer, offset, count);
Expand All @@ -300,13 +301,18 @@ public List<ArraySegment<byte>> GetBuffers ()

public override void Write (byte[] buffer, int offset, int count)
{
byte [] copy = new byte [buffer.Length];
Array.Copy (buffer, offset, copy, offset, count);
buffer = copy;

if (AtEnd) {
if (buffer.Length < MIN_BUFFER_SIZE) {
byte [] bigger = new byte [MIN_BUFFER_SIZE];
Array.Copy (buffer, offset, bigger, 0, count);
buffer = bigger;
}
segments.Add (new ArraySegment<byte> (buffer, offset, count));

segments.Add (new ArraySegment<byte> (buffer, offset, count));
current_segment = segments.Count - 1;
segment_offset = count;
return;
Expand Down

0 comments on commit 5c1d464

Please sign in to comment.