Skip to content

Commit

Permalink
Return the correct length for input streams
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalop committed Oct 17, 2011
1 parent 00903aa commit 4b72b76
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion mcs/class/System/System.Net/WebConnectionStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class WebConnectionStream : Stream
byte [] readBuffer;
int readBufferOffset;
int readBufferSize;
int stream_length; // -1 when CL not present
int contentLength;
int totalRead;
internal long totalWritten;
Expand Down Expand Up @@ -91,6 +92,10 @@ public WebConnectionStream (WebConnection cnc)
} else {
contentLength = Int32.MaxValue;
}

// Negative numbers?
if (!Int32.TryParse (clength, out stream_length))
stream_length = -1;
}

public WebConnectionStream (WebConnection cnc, HttpWebRequest request)
Expand Down Expand Up @@ -804,7 +809,11 @@ public override bool CanWrite {
}

public override long Length {
get { throw new NotSupportedException (); }
get {
if (!isRead)
throw new NotSupportedException ();
return stream_length;
}
}

public override long Position {
Expand Down

0 comments on commit 4b72b76

Please sign in to comment.