int bodyBufferLength;
bool getResponseCalled;
Exception saved_exc;
+ object locker = new object ();
#if NET_1_1
int maxResponseHeadersLength;
static int defaultMaxResponseHeadersLength;
}
#if NET_1_1
+ bool unsafe_auth_blah;
[MonoTODO]
public bool UnsafeAuthenticatedConnectionSharing
{
- get { throw new NotImplementedException (); }
- set { throw new NotImplementedException (); }
+ get { return unsafe_auth_blah; }
+ set { unsafe_auth_blah = value; }
}
#endif
internal ServicePoint GetServicePoint ()
{
- if (!hostChanged && servicePoint != null)
- return servicePoint;
-
- lock (this) {
+ lock (locker) {
if (hostChanged || servicePoint == null) {
servicePoint = ServicePointManager.FindServicePoint (actualUri, proxy);
hostChanged = false;
throw new InvalidOperationException ("rangeSpecifier");
webHeaders.RemoveAndAdd ("Range", value + from + "-" + to);
}
-
+#if !NET_2_0
public override int GetHashCode ()
{
return base.GetHashCode ();
}
+#endif
void CommonChecks (bool putpost)
{
CommonChecks (send);
- lock (this)
+ lock (locker)
{
if (asyncWrite != null) {
throw new InvalidOperationException ("Cannot re-call start of asynchronous " +
return EndGetRequestStream (asyncResult);
}
-
+
+ void CheckIfForceWrite ()
+ {
+ if (writeStream == null || contentLength < 0 || !InternalAllowBuffering)
+ return;
+
+ // This will write the POST/PUT if the write stream already has the expected
+ // amount of bytes in it (ContentLength) (bug #77753).
+ if (writeStream.WriteBufferLength == contentLength)
+ writeStream.WriteRequest ();
+ }
+
public override IAsyncResult BeginGetResponse (AsyncCallback callback, object state)
{
bool send = (method == "PUT" || method == "POST");
"method while a previous call is still in progress.");
}
+ CheckIfForceWrite ();
asyncRead = new WebAsyncResult (this, callback, state);
initialMethod = method;
if (haveResponse) {
case HttpStatusCode.MovedPermanently: // 301
case HttpStatusCode.Redirect: // 302
case HttpStatusCode.TemporaryRedirect: // 307
+ /* MS follows the redirect for POST too
if (method != "GET" && method != "HEAD") // 10.3
return false;
+ */
uriString = webResponse.Headers ["Location"];
break;
{
bool continue100 = false;
if (contentLength != -1) {
- continue100 = true;
+ if (contentLength > 0)
+ continue100 = true;
webHeaders.SetInternal ("Content-Length", contentLength.ToString ());
webHeaders.RemoveInternal ("Transfer-Encoding");
} else if (sendChunked) {
contentLength = bodyBufferLength;
writeStream.SendChunked = false;
}
-
+
SendRequestHeaders ();
haveRequest = true;
void CheckSendError (WebConnectionData data)
{
// Got here, but no one called GetResponse
- if (data.StatusCode < 400)
+ int status = data.StatusCode;
+ if (status < 400 || status == 401 || status == 407)
return;
if (writeStream != null && asyncRead == null && !writeStream.CompleteRequestWritten) {
}
if (wexc == null && (method == "POST" || method == "PUT")) {
- lock (this) {
+ lock (locker) {
CheckSendError (data);
if (saved_exc != null)
wexc = (WebException) saved_exc;
WebExceptionStatus protoError = WebExceptionStatus.ProtocolError;
HttpStatusCode code = 0;
if (throwMe == null && webResponse != null) {
- code = webResponse.StatusCode;
+ code = webResponse.StatusCode;
if (!authCompleted && ((code == HttpStatusCode.Unauthorized && credentials != null) ||
- code == HttpStatusCode.ProxyAuthenticationRequired)) {
+ (ProxyQuery && code == HttpStatusCode.ProxyAuthenticationRequired))) {
if (!usedPreAuth && CheckAuthorization (webResponse, code)) {
// Keep the written body, so it can be rewritten in the retry
if (InternalAllowBuffering) {
if (throwMe == null) {
bool b = false;
int c = (int) code;
- if (allowAutoRedirect && c >= 300)
+ if (allowAutoRedirect && c >= 300) {
+ if (InternalAllowBuffering && writeStream.WriteBufferLength > 0) {
+ bodyBuffer = writeStream.WriteBuffer;
+ bodyBufferLength = writeStream.WriteBufferLength;
+ }
b = Redirect (result, code);
+ }
if (resp != null && c >= 300 && c != 304)
resp.ReadAll ();