/// <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();
        }
Esempio n. 2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="RecordedResponse" /> class.
        /// </summary>
        /// <param name="response">The <see cref="IStumpsHttpResponse" /> used to initialize the instance.</param>
        /// <param name="decoderHandling">The <see cref="ContentDecoderHandling" /> requirements for the HTTP body.</param>
        /// <exception cref="ArgumentNullException"><paramref name="response"/> is <c>null</c>.</exception>
        public RecordedResponse(IStumpsHttpResponse response, ContentDecoderHandling decoderHandling)
            : base(response, decoderHandling)
        {
            response = response ?? throw new ArgumentNullException(nameof(response));

            this.RedirectAddress   = response.RedirectAddress;
            this.StatusCode        = response.StatusCode;
            this.StatusDescription = response.StatusDescription;
        }
Esempio n. 3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="RecordedContext" /> class.
        /// </summary>
        /// <param name="context">The <see cref="IStumpsHttpContext"/> used to initialize the instance.</param>
        /// <param name="decoderHandling">The <see cref="ContentDecoderHandling" /> requirements for the HTTP body.</param>
        /// <exception cref="ArgumentNullException"><paramref name="context"/> is <c>null</c>.</exception>
        public RecordedContext(IStumpsHttpContext context, ContentDecoderHandling decoderHandling)
        {
            context = context ?? throw new ArgumentNullException(nameof(context));

            this.Request  = new RecordedRequest(context.Request, decoderHandling);
            this.Response = new RecordedResponse(context.Response, decoderHandling);

            this.ReceivedDate     = context.ReceivedDate;
            this.UniqueIdentifier = context.UniqueIdentifier;
        }
Esempio n. 4
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="RecordedRequest" /> class.
        /// </summary>
        /// <param name="request">The <see cref="IStumpsHttpRequest"/> used to initialize the instance.</param>
        /// <param name="decoderHandling">The <see cref="ContentDecoderHandling"/> requirements for the HTTP body.</param>
        /// <exception cref="ArgumentNullException"><paramref name="request"/> is <c>null</c>.</exception>
        public RecordedRequest(IStumpsHttpRequest request, ContentDecoderHandling decoderHandling)
            : base(request, decoderHandling)
        {
            request = request ?? throw new ArgumentNullException(nameof(request));

            this.HttpMethod      = request.HttpMethod;
            this.LocalEndPoint   = request.LocalEndPoint ?? new IPEndPoint(0, 0);
            this.ProtocolVersion = request.ProtocolVersion;
            this.RawUrl          = request.RawUrl;
            this.RemoteEndPoint  = request.RemoteEndPoint ?? new IPEndPoint(0, 0);
        }
Esempio n. 5
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:Stumps.Server.RecordedResponse" /> class.
        /// </summary>
        /// <param name="response">The <see cref="T:Stumps.IStumpsHttpResponse" /> used to initialize the instance.</param>
        /// <param name="decoderHandling">The <see cref="T:Stumps.Server.ContentDecoderHandling" /> requirements for the HTTP body.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="response"/> is <c>null</c>.</exception>
        public RecordedResponse(IStumpsHttpResponse response, ContentDecoderHandling decoderHandling)
            : base(response, decoderHandling)
        {
            if (response == null)
            {
                throw new ArgumentNullException("response");
            }

            this.RedirectAddress = response.RedirectAddress;
            this.StatusCode = response.StatusCode;
            this.StatusDescription = response.StatusDescription;
        }
Esempio n. 6
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:Stumps.Server.RecordedContext" /> class.
        /// </summary>
        /// <param name="context">The <see cref="T:Stumps.IStumpsHttpContext"/> used to initialize the instance.</param>
        /// <param name="decoderHandling">The <see cref="T:Stumps.Server.ContentDecoderHandling" /> requirements for the HTTP body.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="context"/> is <c>null</c>.</exception>
        public RecordedContext(IStumpsHttpContext context, ContentDecoderHandling decoderHandling)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            this.Request = new RecordedRequest(context.Request, decoderHandling);
            this.Response = new RecordedResponse(context.Response, decoderHandling);

            this.ReceivedDate = context.ReceivedDate;
            this.UniqueIdentifier = context.UniqueIdentifier;
        }
Esempio n. 7
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:Stumps.Server.RecordedRequest" /> class.
        /// </summary>
        /// <param name="request">The <see cref="T:Stumps.IStumpsHttpRequest"/> used to initialize the instance.</param>
        /// <param name="decoderHandling">The <see cref="T:Stumps.Server.ContentDecoderHandling"/> requirements for the HTTP body.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="request"/> is <c>null</c>.</exception>
        public RecordedRequest(IStumpsHttpRequest request, ContentDecoderHandling decoderHandling)
            : base(request, decoderHandling)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            this.HttpMethod = request.HttpMethod;
            this.LocalEndPoint = request.LocalEndPoint ?? new IPEndPoint(0, 0);
            this.ProtocolVersion = request.ProtocolVersion;
            this.RawUrl = request.RawUrl;
            this.RemoteEndPoint = request.RemoteEndPoint ?? new IPEndPoint(0, 0);
        }
Esempio n. 8
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();
        }