Commit Graph
106 Commits
Author SHA1 Message Date
Martin Baulig 7d8798c15d [System]: WebClient.OpenWrite() must get the response on close; fixes #10163.
When the stream returned by WebClient.OpenWrite() / OpenWriteAsync() /
OpenWriteTaskAsync(), we need to call GetResponse() and read the full
response.

Unfortunately, there is no async API available for this, so this API should
not be used in async applications.
2014-08-25 18:15:49 +02:00
Marek Safar d1d81c9cb5 [system] Fix warnings 2014-05-27 17:04:24 +02:00
Martin Baulig e49d56e8d1 [Http]: Cleanup chained async operations; bug #19161. 2014-05-21 02:26:48 +02:00
Miguel de Icaza 705da187cf [System] Fix build warnings 2014-05-04 17:15:18 -04:00
Martin Baulig 461855eddd [Http]: Clear the 'SendChunked' flag when redirecting. 2014-04-08 08:24:21 +02:00
Martin Baulig faaa8a7c94 Async-ify the remaining WebConnectionStream pieces. 2014-02-25 18:57:30 +01:00
Martin Baulig da6c88b49b [System] WebConnection and WebConnectionStream code cleanups.
* Merged WebConnection.EndWrite() and EndWrite2().

* WebConnectionStream.BeginWrite(): Use the same async-write
  callback for both chunked and non-chunked; remove the single-use
  small WriteRequestAsync() and inline it here to make the code
  more readable.

* WebConnectionStream.WriteRequestAsyncCB(): Now called for all
  async writes, call WebConnection.EndWrite() here.

The code is now more readable and easier to understand.  This is
the first part of a series of cleanups, which should eventually
lead towards full async and 100-continue.
2014-02-19 11:08:18 +01:00
Martin Baulig 5e03c107bc Put back and fix the SSL async patch.
Revert "Revert "Merge pull request #829 from symform/httpwebreq-async-ssl""

This reverts commit 56d9a057eb, which was a
revert of 35899c07ff, thus putting 35889 back.
2014-02-13 18:48:16 +01:00
Martin Baulig 4b5f5f96c8 [System]: Reset NTLM auth state when redirecting; distinguish host and proxy. 2014-02-13 15:48:44 +01:00
Martin Baulig c6a70a9586 Rewrite and fix the web stack's connection reuse and idle logic.
* ServicePoint now uses an idle timer to close idle connections.

* WebConnectionGroup has been mostly rewritten to use a linked
  list of open connections and their idle times.

  This fixes both the problem that we were leaking sockets and
  that we were not reusing existing connections.

* ServicePoint now correctly keeps track of the number of open
  connections.

* ServicePointManager now uses the correct default idle time
  of 100 seconds (previously 15 minutes).

* WebConnection uses the new WebConnectionGroup's busy logic
  to correctly flag connections as busy / reusable.
2014-02-13 14:17:14 +01:00
Martin Baulig 861d495951 Fix WebConnectionStream.CheckComplete() logic for chunked encoding. 2014-02-13 13:22:19 +01:00
Marek Safar 56d9a057eb Revert "Merge pull request #829 from symform/httpwebreq-async-ssl"
This reverts commit 35899c07ff, reversing
changes made to 80166fd02f.
2014-02-10 18:48:03 +01:00
Bassam Tabbara 90f9595967 Convert blocking operations in HttpWebRequest and SslClientStream to non-blocking operations. This fixes #15451.
More details:
  * HttpWebRequest now writes the HTTP request headers asynchronously. This will avoid blocking a thread pool thread until the headers are written.
  * SslClientStream was doing the TLS negotiations in a blocking manner. Converted the negotiation method to an async state machine where all operations are done asynchronously.
  * The test case identified in #15451 now completes quickly with less than 15 threads created, vs. 100s of threads used before this fix.

Future work if needed:
  * I did not convert SslServerStream but the same pattern could be used here.
  * SendAlert is still blocking. I thought it was not worth converting it to non-blocking.
2013-12-06 09:32:22 -08:00
Tammo 'kb' Hinrichs 170fc3aaf7 Reverted whitespace changes 2013-06-12 19:52:14 +02:00
Tammo 'kb' Hinrichs 907b13aa04 Fix race condition in WebConnectionStream
See https://bugzilla.xamarin.com/show_bug.cgi?id=1553
2013-05-08 16:34:17 +02:00
Miguel de Icaza aa4af9833a Add some defensive exceptions to WebConnectionStream to try to track down #6329 2012-11-07 13:22:18 -05:00
Miguel de Icaza a6b3391227 Add some defensive exceptions to WebConnectionStream to try to track down #6329 2012-11-07 13:22:12 -05:00
Martin Baulig f7db37a5ed Fix #5655: Always send HTTP headers for WebDAV methods. 2012-09-05 22:20:00 +02:00
Miguel de Icaza f48ceb9860 [System] Removal of the NET_2_0 in the source code
Modulo the GUID in the assembly and the GUID embedded in some
field initializers that use the assembly GUID for their name, the
assemblies are idential before and after the patch.
2012-06-02 13:16:40 -04:00
Gonzalo Paniagua Javier 4cb9ef3186 DELETE can have a request stream
Fixes bug #3276.
2012-02-27 10:53:41 -05:00
Gonzalo Paniagua Javier 4b72b76703 Return the correct length for input streams 2011-10-17 00:45:17 -04:00
Gonzalo Paniagua Javier 8e67b8c2fc Don't send the buffered request until GetResponse is called
Allows changing some header values after writing the request until the
	call to (Begin)GetResponse()
2011-10-16 01:57:41 -04:00
Gonzalo Paniagua Javier b1248b22e4 [HttpWebRequest] Can't ignore erros here 2011-02-10 17:25:15 -05:00
Gonzalo Paniagua Javier b92b165ddb [HttpWebRequest] Error handling for POST/PUT
When we get an error from the server before writing an entire
	unbuffered response, the server might close the connection leading to
	write errors. Ignore those and return the actual HTTP status code from
	the original server error.
2011-02-10 17:25:15 -05:00
Gonzalo Paniagua Javier 604d5faa0b More StringComparison.Ordinal
Use StringComparison.Ordinal when calling IndexOf to find the index of
	an ASCII string.
2010-10-31 17:23:18 -04:00
Gonzalo Paniagua Javier b24939c61c Create only 1 callback instance for read/write
Read/Write were creating one callback instance per call. Now we keep
	the same delegate around for all the calls.
2010-10-02 01:41:40 -04:00
Gonzalo Paniagua Javier 6a4600c8ec Adapt to changes in exceptions policy for TP.
These exception were being thrown, sometimes, in a threadpool thread and then
ignored.
2010-07-30 01:54:00 -04:00
Gonzalo Paniagua Javier eafc6c8b08 2009-10-17 Gonzalo Paniagua Javier <[email protected]>
* WebConnectionStream.cs: add 3 missing DoCallback() calls in
	EndRead/EndWrite.


svn path=/trunk/mcs/; revision=144315
2009-10-18 02:09:20 +00:00
Gonzalo Paniagua Javier ae20ad47f0 2009-08-13 Gonzalo Paniagua Javier <[email protected]>
* HttpWebRequest.cs:
	* WebConnectionStream.cs: if there's an error writing the headers from
	a buffered request, propagate the error instead of hiding it and
	causing a different one later (ie, ObjectDisposedException instead of
	the original WebException). This happened when posting without
	Content-Length set to an HTTPS url without validating the server
	certificate.


svn path=/trunk/mcs/; revision=139885
2009-08-13 22:12:18 +00:00
Gonzalo Paniagua Javier 27e633cf32 2009-07-22 Gonzalo Paniagua Javier <[email protected]>
* WebConnectionStream.cs: when sending a 0-length POST, ignore further
	writes instead of throwing.
	Fixes bug #524049.


svn path=/trunk/mcs/; revision=138447
2009-07-22 19:58:51 +00:00
Gonzalo Paniagua Javier 547e70a03b 2009-07-07 Gonzalo Paniagua Javier <[email protected]>
* WebClient.cs: set the content length when uploading values. This
	allows reusing the connection.
	* WebConnectionStream.cs: SetHeaders() takes ownership of the buffer
	and does not need to copy it any more. WriteRequest() wasn't always
	setting 'requestWritten' to true.
	* HttpWebRequest.cs: change in SetHeaders call.


svn path=/trunk/mcs/; revision=137497
2009-07-07 14:57:51 +00:00
Gert Driesen 8d403f0381 * WebConnectionStream.cs: Move and improve argument checks to match MS.
Modified CanRead and CanWrite to return false when instance is disposed.
* HttpWebRequestTest.cs: Enabled tests, and removed test that is now
covered by two separate CanTimeout tests for request and response
stream.
* HttpWebResponseStreamTest.cs: Enabled tests.

svn path=/trunk/mcs/; revision=137450
2009-07-06 19:58:00 +00:00
Gonzalo Paniagua Javier 781e4faf6c 2009-07-02 Gonzalo Paniagua Javier <[email protected]>
* WebConnection.cs: provide better error message when there's an error
	writing.
	* WebConnectionStream.cs: don't nullify the buffer until
	CheckFinalStatus() decides that there are no more authentication
	retries or redirects.


svn path=/trunk/mcs/; revision=137332
2009-07-02 23:03:11 +00:00
Gonzalo Paniagua Javier 77e7d3d183 fix
svn path=/trunk/mcs/; revision=137239
2009-07-02 07:34:09 +00:00
Gonzalo Paniagua Javier 7ff2c1978d 2009-07-02 Gonzalo Paniagua Javier <[email protected]>
* HttpWebRequest.cs: avoid duplicating Accept-Encoding if GetHeaders()
	is called twice.
	* WebConnectionStream.cs: don't send a 0 content length for non-write
	requests.


svn path=/trunk/mcs/; revision=137233
2009-07-02 07:33:12 +00:00
Gonzalo Paniagua Javier 08a92a49eb 2009-06-28 Gonzalo Paniagua Javier <[email protected]>
* WebConnectionStream.cs: when buffering the response, we have to set
	the internal length and regenerate the headers.


svn path=/trunk/mcs/; revision=137043
2009-06-28 04:03:49 +00:00
Gonzalo Paniagua Javier d89546ba92 2009-06-26 Gonzalo Paniagua Javier <[email protected]>
* HttpWebRequest.cs: don't send Content-Length header when SendChunked
	is enabled.
	* WebConnectionStream.cs: send the headers immediately when possible.
	When writing the request before a Close(), if there was an exception
	it was lost.


svn path=/trunk/mcs/; revision=137019
2009-06-26 22:45:35 +00:00
Gonzalo Paniagua Javier 7584df6cf8 2009-06-25 Gonzalo Paniagua Javier <[email protected]>
* WebAsyncResult.cs: new field that tells us if the request is being
	written automatically because we reached the content length.
	* WebConnection.cs:
	* WebConnectionStream.cs: make sure we only access the NetworkStream
	while we own it. Automatically write the request when we reach
	ContentLength number of bytes. Kill the write buffer as soon as
	possible. Don't use the buffer at all when chunked encoding is
	enabled.

	Fixes bugs #515931 and #510642.

svn path=/trunk/mcs/; revision=136900
2009-06-25 23:23:24 +00:00
Gonzalo Paniagua Javier f3f57ffb5d 2009-06-21 Gonzalo Paniagua Javier <[email protected]>
* WebConnectionStream.cs: close the underlying socket if there's an
	exception when closing the stream. Fixes bug #514996.


svn path=/trunk/mcs/; revision=136572
2009-06-22 01:47:57 +00:00
Gert Driesen e9ff61a03b * HttpWebRequestTest.cs: Improved and enabled test for bug #510642.
* WebConnectionStream.cs: Keep count of all bytes written, and perform
write overflow check in both buffered and non-buffered writing (if
not using chunked transfer encoding). Fixes bug #510642.

svn path=/trunk/mcs/; revision=136570
2009-06-21 19:09:27 +00:00
Gert Driesen 6f8bd0b8a8 * WebClient.cs: Use lowercase hex bytes to match MS. Avoid using
zero-length string literal. Fixed exception argument name to match
MS.
* WebConnectionStream.cs: Throw a WebException that wraps an
IOException when closing the stream before all bytes are written.

svn path=/trunk/mcs/; revision=136543
2009-06-20 13:17:16 +00:00
Gonzalo Paniagua Javier 4bfc82f892 2009-06-08 Gonzalo Paniagua Javier <[email protected]>
* WebConnectionStream.cs: throw a WebException instead of an IOException.


svn path=/trunk/mcs/; revision=135704
2009-06-08 22:26:59 +00:00
Atsushi Eno f5d1dc6c2c 2009-02-16 Atsushi Enomoto <[email protected]>
* WebConnectionStream.cs : use request only after it is set.


svn path=/trunk/mcs/; revision=126994
2009-02-16 05:45:36 +00:00
Gonzalo Paniagua Javier 17efcb2270 2009-02-13 Gonzalo Paniagua Javier <[email protected]>
* WebConnectionStream.cs: implemente (Read|Write)Timeout.
	Fixes bug #348159.


svn path=/trunk/mcs/; revision=126842
2009-02-13 15:09:07 +00:00
Gonzalo Paniagua Javier b528a9481f 2009-02-06 Gonzalo Paniagua Javier <[email protected]>
* WebConnectionStream.cs: set the content length to 0 when the
	response is not supposed to have any content.


svn path=/trunk/mcs/; revision=126090
2009-02-06 19:33:19 +00:00
Miguel de Icaza b36f2aa0dd 2009-02-05 Miguel de Icaza <[email protected]>
* WebConnectionStream.cs: Prevent a nullref here.   This might
	have to be backported to 2.2 and 2.4

svn path=/trunk/mcs/; revision=125823
2009-02-05 06:10:57 +00:00
Gonzalo Paniagua Javier f1c1d40b44 2009-01-14 Gonzalo Paniagua Javier <[email protected]>
* WebConnectionStream.cs: if the buffer has been killed, return -1 for
	its length. Fixes regression in System.Runtime.Remoting.


svn path=/trunk/mcs/; revision=123449
2009-01-15 04:56:16 +00:00
Gonzalo Paniagua Javier 538c44650f 2009-01-13 Gonzalo Paniagua Javier <[email protected]>
* HttpConnection.cs: we were not writing the headers for 0-length
	responses.
	* WebConnectionStream.cs: for 204/304 responses with an explicit
	content-length of 0, release the socket only once.
	Fixes bug #465638.


svn path=/trunk/mcs/; revision=123250
2009-01-13 20:32:26 +00:00
Gonzalo Paniagua Javier 34e930f822 2008-10-30 Gonzalo Paniagua Javier <[email protected]>
* WebConnectionStream.cs: when there's a NTLM authentication in
	progress, don't let the connection be used by the next request if we
	have the entire response in the input buffer.


svn path=/trunk/mcs/; revision=117511
2008-10-30 19:17:53 +00:00
Gonzalo Paniagua Javier 07c165832b 2008-10-23 Gonzalo Paniagua Javier <[email protected]>
* HttpWebRequest.cs: don't call ProxyRequest twice.
	* WebConnectionData.cs: remove unused fields.

	* WebConnection.cs:
	* WebConnectionStream.cs: when setting the input buffer, check to see
	if the entire response is already there and free up the request slot.
	Fixes bug #423156.

	* ResponseStream.cs:
	* HttpListenerResponse.cs: buffer the headers so that they are sent
	together with the data on the first Write (if any). The fix above
	didn't work with our HttpListener without this.


svn path=/trunk/mcs/; revision=116868
2008-10-23 19:11:33 +00:00