Esempio n. 1
0
        /// <summary>
        /// Lowest-level Creator of a <see cref="HttpWebResponse"/> - full
        /// control over setting every parameter that can be passed into <see cref="HttpWebResponse"/>'s
        /// constructor, except <see cref="_responseUri"/> and <see cref="_method"/> which were provided
        /// in the constructor.  Use
        /// <see cref="HttpWebResponseCreator.Create(Uri,string,HttpStatusCode,Stream,WebHeaderCollection,DecompressionMethods,string,Nullable{long},string,bool,bool,bool,string)"/>
        /// if you need to set those as well
        /// </summary>
        /// <param name="statusCode">
        /// Sets <see cref="HttpWebResponse.StatusCode"/>
        /// </param>
        /// <param name="responseStream">
        /// Sets <see cref="HttpWebResponse.GetResponseStream"/>
        /// </param>
        /// <param name="responseHeaders">
        /// Sets <see cref="HttpWebResponse.Headers"/>.
        /// Use this to also set Cookies via <see cref="HttpResponseHeader.SetCookie"/>.
        /// </param>
        /// <param name="decompressionMethod">
        /// OPTIONAL: Controls if <see cref="HttpWebResponse"/> will decompress
        /// <paramref name="responseStream"/> in its constructor.
        /// Default is <see cref="DecompressionMethods.None"/>
        /// </param>
        /// <param name="mediaType">
        /// OPTIONAL:  If <see cref="HttpWebRequest.MediaType"/> is set, you
        /// should probably pass that value in here so the correct
        /// <see cref="HttpWebResponse.ContentType"/>  response header is processed
        /// and set.
        /// Default is <c>null</c>
        /// </param>
        /// <param name="contentLength">
        /// OPTIONAL: Set/override <see cref="HttpWebResponse.ContentLength"/>.
        /// If this is null, I'll just pull the length from <paramref name="responseStream"/>,
        /// thus this is necessary to set if <paramref name="responseStream"/> doesn't support
        /// getting its length
        /// </param>
        /// <param name="statusDescription">
        /// OPTIONAL: Set <see cref="HttpWebResponse.StatusDescription"/>.
        /// Default is <c>null</c>
        /// </param>
        /// <param name="isVersionHttp11">
        /// OPTIONAL: Set <see cref="HttpWebResponse.ProtocolVersion"/>
        /// Default is <c>true</c>
        /// </param>
        /// <param name="usesProxySemantics">
        /// OPTIONAL: Influences HttpWebResponse.KeepAlive
        /// but not really sure how.
        /// Default is <c>false</c>.
        /// </param>
        /// <param name="isWebSocket">
        /// OPTIONAL: Default is <c>false</c>
        /// </param>
        /// <param name="connectionGroupName">
        /// OPTIONAL: Default is <c>null</c>
        /// </param>

        public HttpWebResponse Create(
            HttpStatusCode statusCode,
            Stream responseStream,
            WebHeaderCollection responseHeaders,
            DecompressionMethods?decompressionMethod = null,
            string mediaType           = null,
            long?contentLength         = null,
            string statusDescription   = null,
            bool isVersionHttp11       = true,
            bool usesProxySemantics    = false,
            bool isWebSocket           = false,
            string connectionGroupName = null)
        {
            return(HttpWebResponseCreator.Create(
                       _responseUri,
                       _method,
                       statusCode,
                       responseStream,
                       responseHeaders,
                       decompressionMethod ?? _automaticDecompression,
                       mediaType,
                       contentLength,
                       statusDescription,
                       isVersionHttp11,
                       usesProxySemantics,
                       isWebSocket,
                       connectionGroupName));
        }
Esempio n. 2
0
 /// <summary>
 /// Create a new <see cref="HttpWebResponse"/>
 /// such that <see cref="HttpWebResponse.GetResponseStream"/>
 /// returns a stream containing <paramref name="responseBody"/>.
 /// </summary>
 /// <param name="responseBody">
 /// Text that <see cref="HttpWebResponse.GetResponseStream"/> will return.
 /// </param>
 /// <param name="statusCode">
 /// OPTIONAL: Sets <see cref="HttpWebResponse.StatusCode"/>.
 /// Defaults to <see cref="HttpStatusCode.OK"/>.
 /// </param>
 /// <param name="responseHeaders">
 /// OPTIONAL: Set <see cref="HttpWebResponse.Headers"/>.
 /// Defaults to an empty <see cref="WebHeaderCollection"/>
 /// <para />
 /// Use this to also set Cookies via <see cref="HttpResponseHeader.SetCookie"/>
 /// </param>
 public HttpWebResponse Create(
     string responseBody,
     HttpStatusCode statusCode           = HttpStatusCode.OK,
     WebHeaderCollection responseHeaders = null)
 {
     return(HttpWebResponseCreator.Create(
                _responseUri,
                _method,
                statusCode,
                responseBody,
                responseHeaders,
                _automaticDecompression));
 }
Esempio n. 3
0
 /// <summary>
 /// Create a new <see cref="HttpWebResponse"/>
 /// such that <see cref="HttpWebResponse.GetResponseStream"/>
 /// returns <paramref name="responseStream"/>.
 /// </summary>
 /// <param name="responseStream">
 /// Sets <see cref="HttpWebResponse.GetResponseStream"/>
 /// </param>
 /// <param name="statusCode">
 /// OPTIONAL: Sets <see cref="HttpWebResponse.StatusCode"/>.
 /// Defaults to <see cref="HttpStatusCode.OK"/>.
 /// </param>
 /// <param name="responseHeaders">
 /// OPTIONAL: Set <see cref="HttpWebResponse.Headers"/>.
 /// Defaults to an empty <see cref="WebHeaderCollection"/>
 /// <para />
 /// Use this to also set Cookies via <see cref="HttpResponseHeader.SetCookie"/>
 /// </param>
 /// <param name="decompressionMethod">
 /// OPTIONAL: Controls if <see cref="HttpWebResponse"/> will decompress
 /// <paramref name="responseStream"/> in its constructor.
 /// Default is <see cref="DecompressionMethods.None"/>
 /// </param>
 /// <param name="contentLength">
 /// OPTIONAL: Set/override <see cref="HttpWebResponse.ContentLength"/>.
 /// If this is null, I'll just pull the length from <paramref name="responseStream"/>,
 /// thus this is necessary to set if <paramref name="responseStream"/> doesn't support
 /// getting its length
 /// </param>
 public HttpWebResponse Create(
     Stream responseStream,
     HttpStatusCode statusCode                = HttpStatusCode.OK,
     WebHeaderCollection responseHeaders      = null,
     DecompressionMethods?decompressionMethod = null,
     long?contentLength = null)
 {
     return(HttpWebResponseCreator.Create(
                _responseUri,
                _method,
                statusCode,
                responseStream,
                responseHeaders ?? new WebHeaderCollection(),
                decompressionMethod ?? _automaticDecompression,
                contentLength: contentLength));
 }