/// <summary>
        ///     Initializes a new instance of the <see cref="T:Stumps.Server.RecordedContextPartBase" /> class.
        /// </summary>
        /// <param name="contextPart">The context part.</param>
        /// <param name="decoderHandling">The <see cref="T:Stumps.Server.ContentDecoderHandling"/> requirements for the HTTP body.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="contextPart"/> is <c>null</c>.</exception>
        protected RecordedContextPartBase(IStumpsHttpContextPart contextPart, ContentDecoderHandling decoderHandling)
        {
            if (contextPart == null)
            {
                throw new ArgumentNullException("contextPart");
            }

            // Copy in the headers
            this.Headers = new HttpHeaders();
            contextPart.Headers.CopyTo(this.Headers);

            // Copy the body into the context part
            _bodyBuffer = new byte[contextPart.BodyLength];

            if (_bodyBuffer.Length > 0)
            {
                Buffer.BlockCopy(contextPart.GetBody(), 0, _bodyBuffer, 0, _bodyBuffer.Length);
            }

            // Decode the body if necessary
            if (decoderHandling == ContentDecoderHandling.DecodeRequired)
            {
                DecodeBody();
            }

            this.ExamineBody();
        }
Beispiel #2
0
        /// <summary>
        ///     Generates the HTTP headers used by a <see cref="IStumpsHttpContextPart"/>.
        /// </summary>
        /// <param name="part">The <see cref="IStumpsHttpContextPart"/> used to generate headers.</param>
        /// <returns>An array of <see cref="HeaderModel"/> objects.</returns>
        private HeaderModel[] GenerateHeaderModels(IStumpsHttpContextPart part)
        {
            var modelList = new List <HeaderModel>();

            foreach (var headerName in part.Headers.HeaderNames)
            {
                var modelHeader = new HeaderModel
                {
                    Name  = headerName,
                    Value = part.Headers[headerName]
                };

                modelList.Add(modelHeader);
            }

            return(modelList.ToArray());
        }
Beispiel #3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="RecordedContextPartBase" /> class.
        /// </summary>
        /// <param name="contextPart">The context part.</param>
        /// <param name="decoderHandling">The <see cref="ContentDecoderHandling"/> requirements for the HTTP body.</param>
        /// <exception cref="ArgumentNullException"><paramref name="contextPart"/> is <c>null</c>.</exception>
        protected RecordedContextPartBase(IStumpsHttpContextPart contextPart, ContentDecoderHandling decoderHandling)
        {
            contextPart = contextPart ?? throw new ArgumentNullException(nameof(contextPart));

            // Copy in the headers
            this.Headers = new HttpHeaders();
            contextPart.Headers.CopyTo(this.Headers);

            // Copy the body into the context part
            _bodyBuffer = new byte[contextPart.BodyLength];

            if (_bodyBuffer.Length > 0)
            {
                Buffer.BlockCopy(contextPart.GetBody(), 0, _bodyBuffer, 0, _bodyBuffer.Length);
            }

            // Decode the body if necessary
            if (decoderHandling == ContentDecoderHandling.DecodeRequired)
            {
                DecodeBody();
            }

            this.ExamineBody();
        }
Beispiel #4
0
        /// <summary>
        ///     Generates the HTTP headers used by a <see cref="T:Stumps.IStumpsHttpContextPart"/>.
        /// </summary>
        /// <param name="part">The <see cref="T:Stumps.IStumpsHttpContextPart"/> used to generate headers.</param>
        /// <returns>An array of <see cref="Stumps.Web.Models.HeaderModel"/> objects.</returns>
        private HeaderModel[] GenerateHeaderModels(IStumpsHttpContextPart part)
        {
            var modelList = new List<HeaderModel>();

            foreach (var headerName in part.Headers.HeaderNames)
            {
                var modelHeader = new HeaderModel
                {
                    Name = headerName,
                    Value = part.Headers[headerName]
                };

                modelList.Add(modelHeader);
            }

            return modelList.ToArray();
        }