提交 07dd1d37 编写于 作者: M Marek Habersack

Revert "[asp.net] Make sure output_stream is not null before using it"

This reverts commit a4ed8be6 since what we
do in ReleaseResources is not what .NET does - a better fix will follow.
上级 7cfce53c
...@@ -284,15 +284,14 @@ namespace System.Web ...@@ -284,15 +284,14 @@ namespace System.Web
public Stream Filter { public Stream Filter {
get { get {
if (WorkerRequest == null || output_stream == null) if (WorkerRequest == null)
return null; return null;
return output_stream.Filter; return output_stream.Filter;
} }
set { set {
if (output_stream != null) output_stream.Filter = value;
output_stream.Filter = value;
} }
} }
...@@ -572,14 +571,12 @@ namespace System.Web ...@@ -572,14 +571,12 @@ namespace System.Web
public void BinaryWrite (byte [] buffer) public void BinaryWrite (byte [] buffer)
{ {
if (output_stream != null) output_stream.Write (buffer, 0, buffer.Length);
output_stream.Write (buffer, 0, buffer.Length);
} }
internal void BinaryWrite (byte [] buffer, int start, int len) internal void BinaryWrite (byte [] buffer, int start, int len)
{ {
if (output_stream != null) output_stream.Write (buffer, start, len);
output_stream.Write (buffer, start, len);
} }
public void Clear () public void Clear ()
...@@ -589,8 +586,7 @@ namespace System.Web ...@@ -589,8 +586,7 @@ namespace System.Web
public void ClearContent () public void ClearContent ()
{ {
if (output_stream != null) output_stream.Clear ();
output_stream.Clear ();
content_length = -1; content_length = -1;
} }
...@@ -684,8 +680,7 @@ namespace System.Web ...@@ -684,8 +680,7 @@ namespace System.Web
// If we are buffering and this is the last flush, not a middle-flush, // If we are buffering and this is the last flush, not a middle-flush,
// we know the content-length. // we know the content-length.
// //
if (output_stream != null) content_length = output_stream.total;
content_length = output_stream.total;
write_headers.Add (HttpWorkerRequest.GetKnownResponseHeaderName (HttpWorkerRequest.HeaderContentLength), write_headers.Add (HttpWorkerRequest.GetKnownResponseHeaderName (HttpWorkerRequest.HeaderContentLength),
content_length.ToString (Helpers.InvariantCulture)); content_length.ToString (Helpers.InvariantCulture));
} else { } else {
...@@ -800,7 +795,7 @@ namespace System.Web ...@@ -800,7 +795,7 @@ namespace System.Web
internal void DoFilter (bool close) internal void DoFilter (bool close)
{ {
if (output_stream != null && output_stream.HaveFilter && context != null && context.Error == null) if (output_stream.HaveFilter && context != null && context.Error == null)
output_stream.ApplyFilter (close); output_stream.ApplyFilter (close);
} }
...@@ -817,7 +812,7 @@ namespace System.Web ...@@ -817,7 +812,7 @@ namespace System.Web
if (!headers_sent) if (!headers_sent)
WriteHeaders (true); WriteHeaders (true);
output_stream.Clear (); output_stream.Clear ();
if (WorkerRequest != null && output_stream != null) if (WorkerRequest != null)
output_stream.Flush (WorkerRequest, true); // ignore final_flush here. output_stream.Flush (WorkerRequest, true); // ignore final_flush here.
return; return;
} }
...@@ -834,7 +829,7 @@ namespace System.Web ...@@ -834,7 +829,7 @@ namespace System.Web
if (IsCached) if (IsCached)
cached_response.SetData (output_stream.GetData ()); cached_response.SetData (output_stream.GetData ());
if (WorkerRequest != null && output_stream != null) if (WorkerRequest != null)
output_stream.Flush (WorkerRequest, final_flush); output_stream.Flush (WorkerRequest, final_flush);
} }
...@@ -1078,9 +1073,6 @@ namespace System.Web ...@@ -1078,9 +1073,6 @@ namespace System.Web
internal void WriteFile (FileStream fs, long offset, long size) internal void WriteFile (FileStream fs, long offset, long size)
{ {
if (output_stream == null)
return;
byte [] buffer = new byte [32*1024]; byte [] buffer = new byte [32*1024];
if (offset != 0) if (offset != 0)
...@@ -1109,14 +1101,12 @@ namespace System.Web ...@@ -1109,14 +1101,12 @@ namespace System.Web
WriteFile (fs, 0, fs.Length); WriteFile (fs, 0, fs.Length);
} else { } else {
FileInfo fi = new FileInfo (filename); FileInfo fi = new FileInfo (filename);
if (output_stream != null) output_stream.WriteFile (filename, 0, fi.Length);
output_stream.WriteFile (filename, 0, fi.Length);
} }
if (buffer) if (buffer)
return; return;
if (output_stream != null) output_stream.ApplyFilter (false);
output_stream.ApplyFilter (false);
Flush (); Flush ();
} }
...@@ -1142,8 +1132,7 @@ namespace System.Web ...@@ -1142,8 +1132,7 @@ namespace System.Web
if (buffer) if (buffer)
return; return;
if (output_stream != null) output_stream.ApplyFilter (false);
output_stream.ApplyFilter (false);
Flush (); Flush ();
} }
#endif #endif
...@@ -1166,8 +1155,7 @@ namespace System.Web ...@@ -1166,8 +1155,7 @@ namespace System.Web
if (buffer) if (buffer)
return; return;
if (output_stream != null) output_stream.ApplyFilter (false);
output_stream.ApplyFilter (false);
Flush (); Flush ();
} }
...@@ -1214,21 +1202,15 @@ namespace System.Web ...@@ -1214,21 +1202,15 @@ namespace System.Web
{ {
FileInfo fi = new FileInfo (filename); FileInfo fi = new FileInfo (filename);
using (Stream s = fi.OpenRead ()); // Just check if we can read. using (Stream s = fi.OpenRead ()); // Just check if we can read.
if (output_stream != null) { output_stream.WriteFile (filename, 0, fi.Length);
output_stream.WriteFile (filename, 0, fi.Length); output_stream.ApplyFilter (final_flush);
output_stream.ApplyFilter (final_flush);
}
Flush (final_flush); Flush (final_flush);
} }
public void TransmitFile (string filename, long offset, long length) public void TransmitFile (string filename, long offset, long length)
{ {
if (output_stream != null) { output_stream.WriteFile (filename, offset, length);
output_stream.WriteFile (filename, offset, length); output_stream.ApplyFilter (false);
output_stream.ApplyFilter (false);
}
Flush (false); Flush (false);
} }
...@@ -1247,18 +1229,15 @@ namespace System.Web ...@@ -1247,18 +1229,15 @@ namespace System.Web
TransmitFile (HostingEnvironment.MapPath (vf.VirtualPath), final_flush); TransmitFile (HostingEnvironment.MapPath (vf.VirtualPath), final_flush);
return; return;
} }
byte[] buf = new byte [bufLen]; byte[] buf = new byte [bufLen];
using (Stream s = vf.Open ()) { using (Stream s = vf.Open ()) {
int readBytes; int readBytes;
if (output_stream != null) { while ((readBytes = s.Read (buf, 0, bufLen)) > 0) {
while ((readBytes = s.Read (buf, 0, bufLen)) > 0) { output_stream.Write (buf, 0, readBytes);
output_stream.Write (buf, 0, readBytes); output_stream.ApplyFilter (final_flush);
output_stream.ApplyFilter (final_flush); Flush (false);
Flush (false);
}
} }
if (final_flush) if (final_flush)
Flush (true); Flush (true);
} }
...@@ -1337,18 +1316,13 @@ namespace System.Web ...@@ -1337,18 +1316,13 @@ namespace System.Web
internal int GetOutputByteCount () internal int GetOutputByteCount ()
{ {
if (output_stream != null) return output_stream.GetTotalLength ();
return output_stream.GetTotalLength ();
else
return -1;
} }
internal void ReleaseResources () internal void ReleaseResources ()
{ {
if (output_stream != null) { output_stream.ReleaseResources (true);
output_stream.ReleaseResources (true); output_stream = null;
output_stream = null;
}
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册