/// <summary>Uses the API request accept.</summary> /// <param name="pipline">The pipline.</param> /// <returns></returns> public static IApiRequestPipeline UseApiRequestAccept(this IApiRequestPipeline pipline) { return(pipline.UsePipelineComponent <ApiRequestAcceptPipelineComponent>()); }
/// <summary>Initializes a new instance of the <see cref="ApiRequestDelegateHandler"/> class.</summary> /// <param name="pipeline">The pipeline.</param> /// <param name="type">The type.</param> public ApiRequestDelegateHandler(IApiRequestPipeline pipeline, Type type) { this.pipeline = pipeline; this.requestDelegate = new ApiRequestDelegate(TaskInvoker); this.type = type; }
/// <summary>Uses the API request body binding.</summary> /// <param name="pipeline">The pipeline.</param> /// <returns></returns> public static IApiRequestPipeline UseApiRequestBodyBinding(this IApiRequestPipeline pipeline) { return(pipeline.UsePipelineComponent <ApiRequestBodyBindingPipelineComponent>()); }
/// <summary>Uses the API response HTTP caching.</summary> /// <param name="pipeline">The pipeline.</param> /// <returns></returns> public static IApiRequestPipeline UseApiResponseHttpCaching(this IApiRequestPipeline pipeline) { return(pipeline.UsePipelineComponent <ApiResponseHttpCachingPipelineComponent>()); }
/// <summary>Uses the API request canceled.</summary> /// <param name="pipeline">The pipeline.</param> /// <returns></returns> public static IApiRequestPipeline UseApiRequestCanceled(this IApiRequestPipeline pipeline) { return(pipeline.UsePipelineComponent <ApiRequestCanceledPipelineComponent>()); }
/// <summary>Uses the API request endpoint invocation.</summary> /// <param name="pipeline">The pipeline.</param> /// <returns></returns> public static IApiRequestPipeline UseApiRequestEndpointInvocation(this IApiRequestPipeline pipeline) { return(pipeline.UsePipelineComponent <ApiRequestEndpointInvocationPipelineComponent>()); }
/// <summary>Uses the API response unhandled exception handler.</summary> /// <param name="pipeline">The pipeline.</param> /// <returns></returns> public static IApiRequestPipeline UseApiResponseUnhandledExceptionHandler(this IApiRequestPipeline pipeline) { return(pipeline.UsePipelineComponent <ApiResponseUnhandledExceptionPipelineComponent>()); }
/// <summary>Uses the API response messages.</summary> /// <param name="pipeline">The pipeline.</param> /// <returns></returns> public static IApiRequestPipeline UseApiResponseMessages(this IApiRequestPipeline pipeline) { return(pipeline.UsePipelineComponent <ApiResponseMessagePipelineComponent>()); }
/// <summary>Uses the API response body writer.</summary> /// <param name="pipeline">The pipeline.</param> /// <returns></returns> public static IApiRequestPipeline UseApiResponseBodyWriter(this IApiRequestPipeline pipeline) { return(pipeline.UsePipelineComponent <ApiResponseBodyWriterPipelineComponent>()); }
/// <summary>Processes the API request.</summary> /// <param name="context">The context.</param> /// <param name="httpcontext">The httpcontext.</param> /// <param name="contextResolver">The context resolver.</param> /// <param name="requestPipeline">The request pipeline.</param> /// <param name="defaultRequestConfiguration">The default request configuration.</param> /// <returns></returns> internal static async Task <bool> ProcessApiRequest( this ApiRequestContext context, HttpContext httpcontext, IApiRequestContextResolver contextResolver, IApiRequestPipeline requestPipeline, IDeepSleepRequestConfiguration defaultRequestConfiguration) { if (!context.RequestAborted.IsCancellationRequested) { await requestPipeline.Run(contextResolver); context.SetThreadCulure(); var responseDate = DateTimeOffset.UtcNow; context.Response.Date = responseDate; context.Response.AddHeader( name: "Date", value: responseDate.ToString("r"), append: false, allowMultiple: false); httpcontext.Response.Headers.Add("Date", responseDate.ToString("r")); // Sync up the expire header for nocache requests with the date header being used var contextExpiresHeader = context.Response.Headers.FirstOrDefault(h => h.Name == "Expires"); var expirationSeconds = context.Configuration?.CacheDirective?.ExpirationSeconds ?? defaultRequestConfiguration?.CacheDirective?.ExpirationSeconds ?? ApiRequestContext.GetDefaultRequestConfiguration().CacheDirective.ExpirationSeconds.Value; var cacheability = context.Configuration?.CacheDirective?.Cacheability ?? defaultRequestConfiguration?.CacheDirective?.Cacheability ?? ApiRequestContext.GetDefaultRequestConfiguration().CacheDirective.Cacheability.Value; if (contextExpiresHeader != null) { if (cacheability == HttpCacheType.NoCache && expirationSeconds > 0) { contextExpiresHeader.Value = responseDate.AddSeconds(-1).ToString("r"); } else { contextExpiresHeader.Value = responseDate.AddSeconds(expirationSeconds).ToString("r"); } } // Merge status code to the http response httpcontext.Response.StatusCode = context.Response.StatusCode; if (context.Response.ResponseWriter != null && context.Response.ResponseWriterOptions != null) { context.Response.AddHeader( name: "Content-Type", value: context.Response.ContentType.ToString(), append: false, allowMultiple: false); if (!string.IsNullOrWhiteSpace(context.Response.ContentLanguage)) { context.Response.AddHeader( name: "Content-Language", value: context.Response.ContentLanguage, append: false, allowMultiple: false); } if (!context.Request.IsHeadRequest()) { var contentLength = await context.Response.ResponseWriter.WriteType( stream : httpcontext.Response.Body, obj : context.Response.ResponseObject, context.Response.ResponseWriterOptions, (l) => { context.Response.ContentLength = l; context.Response.AddHeader( name: "Content-Length", value: l.ToString(CultureInfo.InvariantCulture), append: false, allowMultiple: false); AddHeadersToResponse(httpcontext, context); }).ConfigureAwait(false); context.Response.ContentLength = contentLength; } else { using (var ms = new MemoryStream()) { await context.Response.ResponseWriter.WriteType( ms, context.Response.ResponseObject, context.Response.ResponseWriterOptions).ConfigureAwait(false); context.Response.ResponseObject = null; context.Response.ContentLength = ms.Length; context.Response.AddHeader( name: "Content-Length", value: ms.Length.ToString(CultureInfo.InvariantCulture), append: false, allowMultiple: false); AddHeadersToResponse(httpcontext, context); } } } else { context.Response.ContentLength = 0; context.Response.AddHeader("Content-Length", "0"); AddHeadersToResponse(httpcontext, context); } context.Runtime.Duration.UtcEnd = DateTime.UtcNow; } return(true); }
/// <summary>Uses the API request header validation.</summary> /// <param name="pipeline">The pipeline.</param> /// <returns></returns> public static IApiRequestPipeline UseApiRequestHeaderValidation(this IApiRequestPipeline pipeline) { return(pipeline.UsePipelineComponent <ApiRequestHeaderValidationPipelineComponent>()); }
/// <summary>Invokes the specified httpcontext.</summary> /// <param name="httpcontext">The httpcontext.</param> /// <param name="contextResolver">The context resolver.</param> /// <param name="requestPipeline">The request pipeline.</param> /// <param name="config">The config.</param> /// <returns></returns> public async Task Invoke(HttpContext httpcontext, IApiRequestContextResolver contextResolver, IApiRequestPipeline requestPipeline, IDeepSleepServiceConfiguration config) { var path = httpcontext?.Request?.Path.ToString() ?? string.Empty; if (!IsIncludedPath(path, config.IncludePaths)) { await apinext.Invoke(httpcontext); return; } if (IsExcludedPath(path, config.ExcludePaths)) { await apinext.Invoke(httpcontext); return; } contextResolver.SetContext(await BuildApiRequestContext(httpcontext)); var context = contextResolver.GetContext(); var defaultRequestConfiguration = context.RequestServices.GetService(typeof(IDeepSleepRequestConfiguration)) as IDeepSleepRequestConfiguration; await context.ProcessApiRequest(httpcontext, contextResolver, requestPipeline, defaultRequestConfiguration); }
/// <summary>Uses the API request not found.</summary> /// <param name="pipeline">The pipeline.</param> /// <returns></returns> public static IApiRequestPipeline UseApiRequestNotFound(this IApiRequestPipeline pipeline) { return(pipeline.UsePipelineComponent <ApiRequestNotFoundPipelineComponent>()); }
/// <summary>Uses the API request cors preflight.</summary> /// <param name="pipeline">The pipeline.</param> /// <returns></returns> public static IApiRequestPipeline UseApiRequestCorsPreflight(this IApiRequestPipeline pipeline) { return(pipeline.UsePipelineComponent <ApiRequestCorsPreflightPipelineComponent>()); }
/// <summary>Uses the API request authentication.</summary> /// <param name="pipeline">The pipeline.</param> /// <returns></returns> public static IApiRequestPipeline UseApiRequestAuthentication(this IApiRequestPipeline pipeline) { return(pipeline.UsePipelineComponent <ApiRequestAuthenticationPipelineComponent>()); }
/// <summary>Uses the API request invocation initializer.</summary> /// <param name="pipeline">The pipeline.</param> /// <returns></returns> public static IApiRequestPipeline UseApiRequestInvocationInitializer(this IApiRequestPipeline pipeline) { return(pipeline.UsePipelineComponent <ApiRequestInvocationInitializerPipelineComponent>()); }