Ejemplo n.º 1
0
        public static WebResponseStream Create(CFHTTPMessage request, WebRequestStream body)
        {
            var stream = CFStream.CreateForStreamedHTTPRequest(request, body.ReadStream);

            if (stream == null)
            {
                return(null);
            }

            return(new WebResponseStream(stream, body));
        }
Ejemplo n.º 2
0
		async Task<HttpResponseMessage> ProcessRequest (HttpRequestMessage request,
		                                                CFHTTPMessage message,
		                                                WebRequestStream body,
		                                                bool retryWithCredentials,
		                                                CancellationToken cancellationToken)
		{
			cancellationToken.ThrowIfCancellationRequested ();

			WebResponseStream stream;
			if (body != null)
				stream = WebResponseStream.Create (message, body);
			else
				stream = WebResponseStream.Create (message);
			if (stream == null)
				throw new HttpRequestException (string.Format (
					"Failed to create web request for '{0}'.",
					request.RequestUri)
				);

			stream.Stream.ShouldAutoredirect = AllowAutoRedirect;
			stream.Stream.AttemptPersistentConnection = GetKeepAlive (request);

			var response = await stream.Open (
				WorkerThread, cancellationToken).ConfigureAwait (false);

			var status = (HttpStatusCode)response.ResponseStatusCode;

			if (retryWithCredentials && (body == null) &&
			    (status == HttpStatusCode.Unauthorized) ||
			    (status == HttpStatusCode.ProxyAuthenticationRequired)) {
				if (HandleAuthentication (request.RequestUri, message, response)) {
					stream.Dispose ();
					return await ProcessRequest (
						request, message, null, false, cancellationToken);
				}
			}

			// The Content object takes ownership of the stream, so we don't
			// dispose it here.

			var retval = new HttpResponseMessage ();
			retval.StatusCode = response.ResponseStatusCode;
			retval.ReasonPhrase = GetReasonPhrase (response);
			retval.Version = response.Version;

			var content = new Content (stream);
			retval.Content = content;

			DecodeHeaders (response, retval, content);
			return retval;
		}
Ejemplo n.º 3
0
 WebResponseStream(CFHTTPStream stream, WebRequestStream body)
 {
     this.stream = stream;
     this.body   = body;
     syncRoot    = new object();
 }
Ejemplo n.º 4
0
        async Task <HttpResponseMessage> ProcessRequest(HttpRequestMessage request,
                                                        CFHTTPMessage message,
                                                        WebRequestStream body,
                                                        bool retryWithCredentials,
                                                        CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            WebResponseStream stream;

            if (body != null)
            {
                stream = WebResponseStream.Create(message, body);
            }
            else
            {
                stream = WebResponseStream.Create(message);
            }
            if (stream == null)
            {
                throw new HttpRequestException(string.Format(
                                                   "Failed to create web request for '{0}'.",
                                                   request.RequestUri)
                                               );
            }

            stream.Stream.ShouldAutoredirect          = AllowAutoRedirect;
            stream.Stream.AttemptPersistentConnection = GetKeepAlive(request);

            var response = await stream.Open(
                WorkerThread, cancellationToken).ConfigureAwait(false);

            var status = (HttpStatusCode)response.ResponseStatusCode;

            if (retryWithCredentials && (body == null) &&
                (status == HttpStatusCode.Unauthorized) ||
                (status == HttpStatusCode.ProxyAuthenticationRequired))
            {
                if (HandleAuthentication(request.RequestUri, message, response))
                {
                    stream.Dispose();
                    return(await ProcessRequest(
                               request, message, null, false, cancellationToken));
                }
            }

            // The Content object takes ownership of the stream, so we don't
            // dispose it here.

            var retval = new HttpResponseMessage();

            retval.StatusCode   = response.ResponseStatusCode;
            retval.ReasonPhrase = GetReasonPhrase(response);
            retval.Version      = response.Version;

            var content = new Content(stream);

            retval.Content = content;

            DecodeHeaders(response, retval, content);
            return(retval);
        }