Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/Microsoft.AspNet.OData.Shared/Query/ODataQueryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,22 @@ public bool IsSupportedQueryOption(string queryOptionName)
return IsSystemQueryOption(lowcaseQueryOptionName, this._enableNoDollarSignQueryOptions);
}

/// <summary>
/// Gets the maxpagesize from the request Prefer header.
/// </summary>
public int? RequestPrefersMaxPageSize
{
get
{
if (RequestPreferenceHelpers.RequestPrefersMaxPageSize(InternalRequest.Headers, out int pageSize))
{
return pageSize;
}

return null;
}
}

/// <summary>
/// Apply the individual query to the given IQueryable in the right order.
/// </summary>
Expand Down Expand Up @@ -428,10 +444,10 @@ internal IQueryable ApplyPaging(IQueryable result, ODataQuerySettings querySetti
pageSize = querySettings.ModelBoundPageSize.Value;
}

int preferredPageSize = -1;
if (RequestPreferenceHelpers.RequestPrefersMaxPageSize(InternalRequest.Headers, out preferredPageSize))
int? preferredPageSize = RequestPrefersMaxPageSize;
if (preferredPageSize.HasValue)
{
pageSize = Math.Min(pageSize, preferredPageSize);
pageSize = Math.Min(pageSize, preferredPageSize.Value);
}

if (pageSize > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2454,6 +2454,7 @@ public class Microsoft.AspNet.OData.Query.ODataQueryOptions {
OrderByQueryOption OrderBy { public get; }
ODataRawQueryOptions RawValues { public get; }
System.Net.Http.HttpRequestMessage Request { public get; }
System.Nullable`1[[System.Int32]] RequestPrefersMaxPageSize { public get; }
SelectExpandQueryOption SelectExpand { public get; }
SkipQueryOption Skip { public get; }
SkipTokenQueryOption SkipToken { public get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2609,6 +2609,7 @@ public class Microsoft.AspNet.OData.Query.ODataQueryOptions {
OrderByQueryOption OrderBy { public get; }
ODataRawQueryOptions RawValues { public get; }
Microsoft.AspNetCore.Http.HttpRequest Request { public get; }
System.Nullable`1[[System.Int32]] RequestPrefersMaxPageSize { public get; }
SelectExpandQueryOption SelectExpand { public get; }
SkipQueryOption Skip { public get; }
SkipTokenQueryOption SkipToken { public get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2780,6 +2780,7 @@ public class Microsoft.AspNet.OData.Query.ODataQueryOptions {
OrderByQueryOption OrderBy { public get; }
ODataRawQueryOptions RawValues { public get; }
Microsoft.AspNetCore.Http.HttpRequest Request { public get; }
System.Nullable`1[[System.Int32]] RequestPrefersMaxPageSize { public get; }
SelectExpandQueryOption SelectExpand { public get; }
SkipQueryOption Skip { public get; }
SkipTokenQueryOption SkipToken { public get; }
Expand Down