HttpResponseExtensions Class
Provides extension methods for modifying a controller action response with data relating to types from the persistence module.
public static class HttpResponseExtensionsInheritance System.Object 🡒 HttpResponseExtensions
Methods
Section titled “Methods”HttpResponseExtensions.TrySetRange<TResult>(this HttpResponse, Range<TResult>, Nullable<int>) Method
Section titled “HttpResponseExtensions.TrySetRange<TResult>(this HttpResponse, Range<TResult>, Nullable<int>) Method”Sets the range of the result.
public static HAKOM.ErrorHandling.Core.Net.Api.Result TrySetRange<TResult>(this Microsoft.AspNetCore.Http.HttpResponse response, HAKOM.Persistence.Core.Net.Api.Paging.Range<TResult> range, System.Nullable<int> total=null);Type parameters
Section titled “Type parameters”TResult
The type of data for which a partial range is returned.
Parameters
Section titled “Parameters”response Microsoft.AspNetCore.Http.HttpResponse
The Microsoft.AspNetCore.Http.HttpResponse to modify.
range HAKOM.Persistence.Core.Net.Api.Paging.Range<TResult>
The range that has been processed.
total System.Nullable<System.Int32>
When available the total number of available results that are not being included in the partial result.
Returns
Section titled “Returns”Result
A Result indicating whether the response was successfully modified.
Remarks
Section titled “Remarks”This should be called from within a controller action whenever a Range<TResult> parameter is being processed from range headers.
When processing range request headers, the response should include information about the range returned, such as setting the response status code to 206 (Partial Content) and setting the Content-Range header. Calling this does all of that.
Note that this must be called before any content is returned, i.e. before any return or [yield return](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/yield return ‘https://docs\.microsoft\.com/en\-us/dotnet/csharp/language\-reference/keywords/yield return’) statements. Otherwise it may fail with a RangeCannotBeSetAfterResponseHasAlreadyStartedException.
HttpResponseExtensions.TryUpdateRange<TResult>(this HttpResponse, int, int, Nullable<int>) Method
Section titled “HttpResponseExtensions.TryUpdateRange<TResult>(this HttpResponse, int, int, Nullable<int>) Method”Attempts to update the content range header if the response has not started yet.
public static HAKOM.ErrorHandling.Core.Net.Api.Result TryUpdateRange<TResult>(this Microsoft.AspNetCore.Http.HttpResponse response, int start, int count, System.Nullable<int> total=null);Type parameters
Section titled “Type parameters”TResult
The type of data for which a partial range is returned.
Parameters
Section titled “Parameters”response Microsoft.AspNetCore.Http.HttpResponse
The Microsoft.AspNetCore.Http.HttpResponse to modify.
start System.Int32
The actual start of the range returned.
count System.Int32
The number of items returned.
total System.Nullable<System.Int32>
When available the total number of available results that are not being included in the partial result.
Returns
Section titled “Returns”Result
A Result indicating whether the response was successfully update.
Remarks
Section titled “Remarks”TrySetRange<TResult>(this HttpResponse, Range<TResult>, Nullable<int>) should always be called when limiting results. However, when data is streamed (i.e. from a repository), the final range may not be known at this point in time, resulting in an incorrect Content-Range header. For this reason, this method should always be called after streaming. This ensures that - for small ranges where the service buffers the entire result before starting to send response headers, the Content-Range header will be set properly.