Represents the response of the HTTP worker.
Beispiel #1
0
        /// <summary>
        /// Performs a request against the host application using the specified HTTP method.
        /// </summary>
        /// <param name="method">The HTTP method that should be used.</param>
        /// <param name="path">The path that is being requested.</param>
        /// <param name="overrides">A configuration object for providing the HTTP payload for the request.</param>
        /// <returns>A <see cref="ClientResponse"/> instance of the executed request.</returns>
        public virtual ClientResponse PerformRequest(string method, string path, Action<HttpPayload> overrides = null)
        {
            Ensure.NotNull(method, "method");
            Ensure.NotNull(path, "path");

            var payload = new HttpPayload(method);
            if (defaults != null)
            {
                defaults.ApplyTo(payload);
            }

            path = path.RemoveLeadingSlash();
            path = payload.ExtractQueryString(path);

            overrides.TryInvoke(payload);

            CrowbarContext.Reset();

            var request = new CrowbarHttpRequestCapture(new CrowbarHttpRequest(path, payload));
            var response = new CrowbarHttpResponse();

            using (var handle = CreateRequestWaitHandle())
            {
                var worker = new CrowbarHttpWorker(request, response, handle);
                HttpRuntime.ProcessRequest(worker);
                handle.Wait();

                return CreateResponse(request, response);
            }
        }
 public CrowbarHttpWorker(ICrowbarHttpRequest request, CrowbarHttpResponse response, IRequestWaitHandle handle)
     : base(request.Path, request.QueryString, response.Output)
 {
     this.request = request;
     this.response = response;
     this.handle = handle;
 }
Beispiel #3
0
        /// <summary>
        /// Creates the client response.
        /// </summary>
        /// <param name="request">The HTTP request.</param>
        /// <param name="response">The HTTP response.</param>
        /// <returns>The client response.</returns>
        protected virtual ClientResponse CreateResponse(ICrowbarHttpRequest request, CrowbarHttpResponse response)
        {
            if (CrowbarContext.ExceptionContext != null)
            {
                Throw(request);
            }

            return new ClientResponse
            {
                Advanced = new AdvancedClientResponse
                {
                    ActionExecutedContext = CrowbarContext.ActionExecutedContext,
                    ActionExecutingContext = CrowbarContext.ActionExecutingContext,
                    ResultExecutedContext = CrowbarContext.ResultExecutedContext,
                    ResultExecutingContext = CrowbarContext.ResultExecutingContext,
                    HttpResponse = CrowbarContext.HttpResponse,
                    HttpSessionState = CrowbarContext.HttpSessionState
                },
                Headers = response.GetHeaders(),
                ResponseBody = response.GetResponseBody(),
                RawHttpRequest = request.ToString(),
                RawHttpResponse = response.ToString(),
                StatusCode = response.StatusCode,
                StatusDescription = response.StatusDescription
            };
        }