byte [] readBuffer;
int readBufferOffset;
int readBufferSize;
+ int stream_length; // -1 when CL not present
int contentLength;
int totalRead;
internal long totalWritten;
public WebConnectionStream (WebConnection cnc)
{
+ if (cnc.Data == null)
+ throw new InvalidOperationException ("cnc.Data was not initialized");
+ if (cnc.Data.Headers == null)
+ throw new InvalidOperationException ("cnc.Data.Headers was not initialized");
+ if (cnc.Data.request == null)
+ throw new InvalidOperationException ("cnc.Data.request was not initialized");
isRead = true;
cb_wrapper = new AsyncCallback (ReadCallbackWrapper);
pending = new ManualResetEvent (true);
} else {
contentLength = Int32.MaxValue;
}
+
+ // Negative numbers?
+ if (!Int32.TryParse (clength, out stream_length))
+ stream_length = -1;
}
public WebConnectionStream (WebConnection cnc, HttpWebRequest request)
internal WebConnection Connection {
get { return cnc; }
}
-#if NET_2_0
public override bool CanTimeout {
get { return true; }
}
-#endif
-#if NET_2_0
- public override
-#endif
- int ReadTimeout {
+ public override int ReadTimeout {
get {
return read_timeout;
}
}
}
-#if NET_2_0
- public override
-#endif
- int WriteTimeout {
+ public override int WriteTimeout {
get {
return write_timeout;
}
long cl = request.ContentLength;
string method = request.Method;
bool no_writestream = (method == "GET" || method == "CONNECT" || method == "HEAD" ||
- method == "TRACE" || method == "DELETE");
- if (sendChunked || cl > -1 || no_writestream) {
+ method == "TRACE");
+ bool webdav = (method == "PROPFIND" || method == "PROPPATCH" || method == "MKCOL" ||
+ method == "COPY" || method == "MOVE" || method == "LOCK" ||
+ method == "UNLOCK");
+ if (sendChunked || cl > -1 || no_writestream || webdav) {
WriteHeaders ();
if (!initRead) {
initRead = true;
byte [] bytes = writeBuffer.GetBuffer ();
int length = (int) writeBuffer.Length;
// Headers already written to the stream
- try {
- return (length > 0) ? cnc.BeginWrite (request, bytes, 0, length, cb, state) : null;
- } catch {
- if (!IgnoreIOErrors)
- throw;
- return null;
- }
+ return (length > 0) ? cnc.BeginWrite (request, bytes, 0, length, cb, state) : null;
}
void WriteHeaders ()
if (!headersSent) {
string method = request.Method;
bool no_writestream = (method == "GET" || method == "CONNECT" || method == "HEAD" ||
- method == "TRACE" || method == "DELETE");
+ method == "TRACE");
if (!no_writestream)
request.InternalContentLength = length;
request.SendRequestHeaders (true);
throw new WebException ("Request was cancelled.", io, WebExceptionStatus.RequestCanceled);
}
- WriteRequest ();
+ // Commented out the next line to fix xamarin bug #1512
+ //WriteRequest ();
disposed = true;
}
}
public override long Length {
- get { throw new NotSupportedException (); }
+ get {
+ if (!isRead)
+ throw new NotSupportedException ();
+ return stream_length;
+ }
}
public override long Position {