Compare commits

...
Author SHA1 Message Date
Miguel de Icaza 9de8c08d26 Force use of 4.0.0.0 version for System.Net.Http 2014-05-13 12:09:44 -04:00
Martin Baulig bc488bd546 [Http]: Correctly handle request bodies when resending with authentication.
My previous changes modified the way how we're handing the request body when
resending a request due to a 30x redirection.

Authentication is a "special" form of redirection because we sometimes need
to resend a request with additional authentication headers.  Unfortunately,
I forgot this, causing a regression which is now fixed.

This has been reported as bugs #19119 and #19068.
2014-04-17 22:46:42 +02:00
Martin Baulig 8593ebe2b3 [Http]: Disable redirect with body and no buffering. 2014-04-17 22:45:00 +02:00
Martin Baulig 15f8e79bb9 [Http]: Clear the 'SendChunked' flag when redirecting. 2014-04-17 22:44:52 +02:00
Martin Baulig b266dd15a3 [Http]: Remove chunked/etc headers when redirecting a request as GET. 2014-04-17 22:44:26 +02:00
Rodrigo Kumpera fcf29c0e2f [corlib] Fix the mobile profile. 2014-04-08 11:01:39 -04:00
Jonathan Pryor b4c684a209 [android-hack] Fix SleepEx() compilation under the Android NDK
Apparently the Android NDK on Wrench doesn't declare
clock_nanosleep()/etc., so 0947ffd8 resulted in the same error.

The correct fix would be to update the NDK on Wrench, which has a
proper solution which isn't yet ready, so in the meantime/for
expediency, declare the required functions so that we can get on with
our lives.

DO NOT CHERRY-PICK.
2014-04-08 09:50:58 -04:00
Jonathan Pryor 0947ffd89c [runtime] Fix SleepEx() compilation under the Android NDK.
SleepEx() requires clock_nanosleep(), which Android provides, but
declares in <time.h>, not <sys/time.h>

Add #include<time.h> so that SleepEx() compiles.
2014-04-07 23:12:33 -04:00
Miguel de Icaza bca9714576 WebResponse.cs: Implement SupportsHeaders property 2014-04-07 14:35:07 -04:00
Miguel de Icaza 242ea36e35 System/PCL: Implement HttpWebRequest.SupportsCookieContainer, WebRequest.CreateHttp; Fixes #18378 2014-04-07 14:35:00 -04:00
7 changed files with 81 additions and 26 deletions

No files matched your search

@@ -44,10 +44,10 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany (Consts.MonoCompany)]
[assembly: AssemblyProduct (Consts.MonoProduct)]
[assembly: AssemblyCopyright (Consts.MonoCopyright)]
[assembly: AssemblyVersion (Consts.FxVersion)]
[assembly: SatelliteContractVersion (Consts.FxVersion)]
[assembly: AssemblyInformationalVersion (Consts.FxFileVersion)]
[assembly: AssemblyFileVersion (Consts.FxFileVersion)]
[assembly: AssemblyVersion ("4.0.0.0")]
[assembly: SatelliteContractVersion ("4.0.0.0")]
[assembly: AssemblyInformationalVersion ("4.0.50524.0")]
[assembly: AssemblyFileVersion ("4.0.50524.0")]
[assembly: NeutralResourcesLanguage ("en-US")]
[assembly: CLSCompliant (true)]
+30 -15
View File
@@ -56,6 +56,7 @@ namespace System.Net
bool allowBuffering = true;
X509CertificateCollection certificates;
string connectionGroup;
bool haveContentLength;
long contentLength = -1;
HttpContinueDelegate continueDelegate;
CookieContainer cookieContainer;
@@ -277,6 +278,7 @@ namespace System.Net
throw new ArgumentOutOfRangeException ("value", "Content-Length must be >= 0");
contentLength = value;
haveContentLength = true;
}
}
@@ -593,10 +595,11 @@ namespace System.Net
get { return servicePoint; }
}
#if NET_4_0
[MonoTODO ("for portable library support")]
public virtual bool SupportsCookieContainer {
get {
throw new NotImplementedException ();
// The managed implementation supports the cookie container
// it is only Silverlight that returns false here
return true;
}
}
#endif
@@ -1108,8 +1111,15 @@ namespace System.Net
if (continueDelegate != null)
continueDelegate (statusCode, headers);
}
void RewriteRedirectToGet ()
{
method = "GET";
webHeaders.RemoveInternal ("Transfer-Encoding");
sendChunked = false;
}
bool Redirect (WebAsyncResult result, HttpStatusCode code)
bool Redirect (WebAsyncResult result, HttpStatusCode code, WebResponse response)
{
redirects++;
Exception e = null;
@@ -1121,12 +1131,12 @@ namespace System.Net
case HttpStatusCode.MovedPermanently: // 301
case HttpStatusCode.Redirect: // 302
if (method == "POST")
method = "GET";
RewriteRedirectToGet ();
break;
case HttpStatusCode.TemporaryRedirect: // 307
break;
case HttpStatusCode.SeeOther: //303
method = "GET";
RewriteRedirectToGet ();
break;
case HttpStatusCode.NotModified: // 304
return false;
@@ -1139,12 +1149,13 @@ namespace System.Net
break;
}
if (method != "GET" && !InternalAllowBuffering)
e = new WebException ("The request requires buffering data to succeed.", null, WebExceptionStatus.ProtocolError, webResponse);
if (e != null)
throw e;
contentLength = -1;
//bodyBufferLength = 0;
//bodyBuffer = null;
uriString = webResponse.Headers ["Location"];
if (uriString == null)
@@ -1174,12 +1185,15 @@ namespace System.Net
} else if (contentLength != -1) {
if (auth_state.NtlmAuthState == NtlmAuthState.Challenge || proxy_auth_state.NtlmAuthState == NtlmAuthState.Challenge) {
// We don't send any body with the NTLM Challenge request.
webHeaders.SetInternal ("Content-Length", "0");
if (haveContentLength || gotRequestStream || contentLength > 0)
webHeaders.SetInternal ("Content-Length", "0");
else
webHeaders.RemoveInternal ("Content-Length");
} else {
if (contentLength > 0)
continue100 = true;
if (gotRequestStream || contentLength > 0)
if (haveContentLength || gotRequestStream || contentLength > 0)
webHeaders.SetInternal ("Content-Length", contentLength.ToString ());
}
webHeaders.RemoveInternal ("Transfer-Encoding");
@@ -1517,6 +1531,11 @@ namespace System.Net
r.SetCompleted (false, webResponse);
r.DoCallback ();
} else {
if (sendChunked) {
sendChunked = false;
webHeaders.RemoveInternal ("Transfer-Encoding");
}
if (webResponse != null) {
if (HandleNtlmAuth (r))
return;
@@ -1651,11 +1670,7 @@ namespace System.Net
if (!usedPreAuth && CheckAuthorization (webResponse, code)) {
// Keep the written body, so it can be rewritten in the retry
if (InternalAllowBuffering) {
// NTLM: This is to avoid sending data in the 'challenge' request
// We save it in the first request (first 401), don't send anything
// in the challenge request and send it in the response request along
// with the buffers kept form the first request.
if (auth_state.NtlmAuthState == NtlmAuthState.Challenge || proxy_auth_state.NtlmAuthState == NtlmAuthState.Challenge) {
if (writeStream.WriteBufferLength > 0) {
bodyBuffer = writeStream.WriteBuffer;
bodyBufferLength = writeStream.WriteBufferLength;
}
@@ -1702,7 +1717,7 @@ namespace System.Net
bool b = false;
int c = (int) code;
if (allowAutoRedirect && c >= 300) {
b = Redirect (result, code);
b = Redirect (result, code, webResponse);
if (InternalAllowBuffering && writeStream.WriteBufferLength > 0) {
bodyBuffer = writeStream.WriteBuffer;
bodyBufferLength = writeStream.WriteBufferLength;
@@ -514,6 +514,13 @@ namespace System.Net
Buffer.BlockCopy (buffer, offset, newBuffer, head.Length, size);
Buffer.BlockCopy (crlf, 0, newBuffer, head.Length + size, crlf.Length);
if (allowBuffering) {
if (writeBuffer == null)
writeBuffer = new MemoryStream ();
writeBuffer.Write (buffer, offset, size);
totalWritten += size;
}
buffer = newBuffer;
offset = 0;
size = chunkSize;
+14 -4
View File
@@ -287,16 +287,26 @@ namespace System.Net
return GetCreator (requestUri.Scheme).Create (requestUri);
}
#if NET_4_0
[MonoTODO ("for portable library support")]
static HttpWebRequest SharedCreateHttp (Uri uri)
{
if (uri.Scheme != "http" && uri.Scheme != "https")
throw new NotSupportedException ("The uri should start with http or https");
return new HttpWebRequest (uri);
}
public static HttpWebRequest CreateHttp (string requestUriString)
{
throw new NotImplementedException ();
if (requestUriString == null)
throw new ArgumentNullException ("requestUriString");
return SharedCreateHttp (new Uri (requestUriString));
}
[MonoTODO ("for portable library support")]
public static HttpWebRequest CreateHttp (Uri requestUri)
{
throw new NotImplementedException ();
if (requestUri == null)
throw new ArgumentNullException ("requestUri");
return SharedCreateHttp (requestUri);
}
#endif
public virtual Stream EndGetRequestStream (IAsyncResult asyncResult)
+6 -2
View File
@@ -86,9 +86,13 @@ namespace System.Net
get { throw new NotSupportedException (); }
}
#if NET_4_0
[MonoTODO ("for portable library support")]
public virtual bool SupportsHeaders {
get { throw new NotImplementedException (); }
get {
// The managed stack always returns this as true, it is only
// the Silverlight stack that does not support this.
return true;
}
}
#endif
// Methods
@@ -85,7 +85,11 @@ namespace System.Threading {
if (ec.FlowSuppressed)
return null;
if (nullOnEmpty && ec._sc == null && (ec._lcc == null || !ec._lcc.HasInfo))
if (nullOnEmpty
#if !MOBILE
&& ec._sc == null
#endif
&& (ec._lcc == null || !ec._lcc.HasInfo))
return null;
ExecutionContext capture = new ExecutionContext (ec);
+15
View File
@@ -17,6 +17,7 @@
#include <signal.h>
#include <sched.h>
#include <sys/time.h>
#include <time.h>
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
@@ -36,6 +37,20 @@
#include <valgrind/memcheck.h>
#endif
#ifdef PLATFORM_ANDROID
/*
* HACK
* Android supports clock_*(), but didn't declare them consistently until
* recently, e.g. on NDK r8e API-3, API-4, and API-5 declare them in <time.h>,
* but higher API levels do not. This isn't corrected until r9c, which
* Wrench isn't currently using.
*
* Manually declare them so that we don't get implicit declaration errors.
*/
extern int clock_gettime(clockid_t, struct timespec *);
extern int clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *);
#endif /* PLATFORM_ANDROID */
#if 0
#define DEBUG(...) g_message(__VA_ARGS__)
#else