byte [] readBuffer;
int readBufferOffset;
int readBufferSize;
+ int stream_length; // -1 when CL not present
int contentLength;
int totalRead;
- long totalWritten;
+ internal long totalWritten;
bool nextReadCalled;
int pendingReads;
int pendingWrites;
int read_timeout;
int write_timeout;
AsyncCallback cb_wrapper; // Calls to ReadCallbackWrapper or WriteCallbacWrapper
+ internal bool IgnoreIOErrors;
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);
write_timeout = read_timeout;
this.cnc = cnc;
string contentType = cnc.Data.Headers ["Transfer-Encoding"];
- bool chunkedRead = (contentType != null && contentType.ToLower ().IndexOf ("chunked") != -1);
+ bool chunkedRead = (contentType != null && contentType.IndexOf ("chunked", StringComparison.OrdinalIgnoreCase) != -1);
string clength = cnc.Data.Headers ["Content-Length"];
if (!chunkedRead && clength != null && clength != "") {
try {
} else {
contentLength = Int32.MaxValue;
}
+
+ // Negative numbers?
+ if (!Int32.TryParse (clength, out stream_length))
+ stream_length = -1;
}
public WebConnectionStream (WebConnection cnc, HttpWebRequest request)
bool isProxy = (request.Proxy != null && !request.Proxy.IsBypassed (request.Address));
string header_name = (isProxy) ? "Proxy-Authenticate" : "WWW-Authenticate";
string authHeader = cnc.Data.Headers [header_name];
- return (authHeader != null && authHeader.IndexOf ("NTLM") != -1);
+ return (authHeader != null && authHeader.IndexOf ("NTLM", StringComparison.Ordinal) != -1);
}
internal void CheckResponseInBuffer ()
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;
}
result.InnerAsyncResult = r;
result.DoCallback ();
} else {
- EndWrite (r);
+ try {
+ EndWrite (r);
+ } catch {
+ }
}
}
size = chunkSize;
}
- result.InnerAsyncResult = cnc.BeginWrite (request, buffer, offset, size, callback, result);
+ try {
+ result.InnerAsyncResult = cnc.BeginWrite (request, buffer, offset, size, callback, result);
+ } catch (Exception) {
+ if (!IgnoreIOErrors)
+ throw;
+ result.SetCompleted (true, 0);
+ result.DoCallback ();
+ }
totalWritten += size;
return result;
}
result.SetCompleted (false, 0);
result.DoCallback ();
} catch (Exception e) {
- result.SetCompleted (false, e);
+ if (IgnoreIOErrors)
+ result.SetCompleted (false, 0);
+ else
+ result.SetCompleted (false, e);
result.DoCallback ();
- throw;
+ if (!IgnoreIOErrors)
+ throw;
} finally {
if (sendChunked) {
lock (locker) {
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;
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 {