Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable v4.01 requests #2386

Draft
wants to merge 6 commits into
base: release-7.x
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion src/Microsoft.OData.Client/ALinq/ExpressionWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private ExpressionWriter(DataServiceContext context, bool inPath)
this.builder = new StringBuilder();
this.expressionStack = new Stack<Expression>();
this.expressionStack.Push(null);
this.uriVersion = Util.ODataVersion4;
this.uriVersion = context.MaxProtocolVersionAsVersion;
this.scopeCount = 0;
this.writingFunctionsInQuery = false;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Microsoft.OData.Client/ALinq/ProjectionAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ private static void Analyze(MemberInitExpression mie, SelectExpandPathBuilder pb
/// <param name="context">Context of expression to analyze.</param>
private static void AnalyzeResourceExpression(LambdaExpression lambda, ResourceExpression resource, DataServiceContext context)
{
SelectExpandPathBuilder pb = new SelectExpandPathBuilder();
SelectExpandPathBuilder pb = new SelectExpandPathBuilder()
{
UriVersion = context.MaxProtocolVersionAsVersion
};
ProjectionAnalyzer.Analyze(lambda, pb, context);
resource.Projection = new ProjectionQueryOptionExpression(lambda.Body.Type, lambda, pb.ProjectionPaths.ToList());
resource.ExpandPaths = pb.ExpandPaths.Union(resource.ExpandPaths, StringComparer.Ordinal).ToList();
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.OData.Client/ALinq/ResourceBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,7 @@ internal static bool MatchPropertyAccess(Expression e, DataServiceContext contex
{
instance = null;
propertyPath = null;
uriVersion = Util.ODataVersion4;
uriVersion = context.MaxProtocolVersionAsVersion;

MemberExpression me = StripTo<MemberExpression>(e);
member = me;
Expand Down Expand Up @@ -1774,7 +1774,7 @@ internal static bool MatchPropertyAccess(Expression e, DataServiceContext contex
{
instance = null;
propertyPath = null;
uriVersion = Util.ODataVersion4;
uriVersion = context.MaxProtocolVersionAsVersion;

MemberExpression me = StripTo<MemberExpression>(e);
member = me;
Expand Down Expand Up @@ -2946,7 +2946,7 @@ internal static void DisallowExpressionEndWithTypeAs(Expression exp, string meth
internal static void ValidateExpandPath(Expression input, DataServiceContext context, out string expandPath, out Version uriVersion)
{
expandPath = null;
uriVersion = Util.ODataVersion4;
uriVersion = context.MaxProtocolVersionAsVersion;
LambdaExpression le;
if (PatternRules.MatchSingleArgumentLambda(input, out le))
{
Expand Down
7 changes: 5 additions & 2 deletions src/Microsoft.OData.Client/ALinq/SelectExpandPathBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ internal class SelectExpandPathBuilder
public SelectExpandPathBuilder()
{
firstSegmentInNewPath = true;
this.uriVersion = Util.ODataVersion4;
}

/// <summary>
Expand Down Expand Up @@ -107,7 +106,11 @@ public Version UriVersion
{
get
{
return this.uriVersion;
return this.uriVersion ?? Util.ODataVersion4;
}
set
{
this.uriVersion = value;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OData.Client/ALinq/UriWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private UriWriter(DataServiceContext context)
{
Debug.Assert(context != null, "context != null");
this.context = context;
this.uriVersion = Util.ODataVersion4;
this.uriVersion = context.MaxProtocolVersionAsVersion;
}

/// <summary>
Expand Down
5 changes: 3 additions & 2 deletions src/Microsoft.OData.Client/BaseSaveResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ protected ODataRequestMessageWrapper CreateRequest(LinkDescriptor binding)

HeaderCollection headers = new HeaderCollection();

headers.SetRequestVersion(Util.ODataVersion4, this.RequestInfo.MaxProtocolVersionAsVersion);
headers.SetRequestVersion(this.RequestInfo.MaxProtocolVersionAsVersion, this.RequestInfo.MaxProtocolVersionAsVersion);
this.RequestInfo.Format.SetRequestAcceptHeader(headers);

// if (EntityStates.Deleted || (EntityState.Modifed && null == TargetResource))
Expand Down Expand Up @@ -936,7 +936,8 @@ protected ODataRequestMessageWrapper CreateRequest(EntityDescriptor entityDescri

ClientEdmModel model = this.RequestInfo.Model;
ClientTypeAnnotation clientType = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(entityDescriptor.Entity.GetType()));
Version requestVersion = DetermineRequestVersion(clientType);
//Version requestVersion = DetermineRequestVersion(clientType);
Version requestVersion = this.RequestInfo.MaxProtocolVersionAsVersion;
string httpMethod = this.GetHttpMethod(state, ref requestVersion);

HeaderCollection headers = new HeaderCollection();
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OData.Client/BatchSaveResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private ODataRequestMessageWrapper CreateBatchRequest()
{
Uri requestUri = UriUtil.CreateUri(this.RequestInfo.BaseUriResolver.GetBaseUriWithSlash(), UriUtil.CreateUri("$batch", UriKind.Relative));
HeaderCollection headers = new HeaderCollection();
headers.SetRequestVersion(Util.ODataVersion4, this.RequestInfo.MaxProtocolVersionAsVersion);
headers.SetRequestVersion(this.RequestInfo.MaxProtocolVersionAsVersion, this.RequestInfo.MaxProtocolVersionAsVersion);
if (useJsonBatch)
{
headers.SetHeader(XmlConstants.HttpContentType, CreateApplicationJsonContentType());
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OData.Client/DataServiceClientFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ private void SetRequestContentTypeHeader(HeaderCollection headers, string mediaT
{
if (mediaType == MimeApplicationJsonODataLight)
{
// set the request version to 4.0
headers.SetRequestVersion(Util.ODataVersion4, this.context.MaxProtocolVersionAsVersion);
// set the request version to 4.0 or 4.01 depending on what is set in tha DataServiceContext.
headers.SetRequestVersion(this.context.MaxProtocolVersionAsVersion, this.context.MaxProtocolVersionAsVersion);
}

headers.SetHeaderIfUnset(XmlConstants.HttpContentType, mediaType);
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OData.Client/DataServiceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3648,7 +3648,7 @@ private LoadPropertyResult CreateLoadPropertyRequest(object entity, string prope
}
}

requestVersion = Util.ODataVersion4;
requestVersion = this.MaxProtocolVersionAsVersion;

HeaderCollection headers = new HeaderCollection();

Expand Down Expand Up @@ -3812,7 +3812,7 @@ private GetReadStreamResult CreateGetReadStreamResult(
}
else
{
version = Util.ODataVersion4;
version = this.MaxProtocolVersionAsVersion;
if (!entityDescriptor.TryGetNamedStreamInfo(name, out streamDescriptor))
{
throw new ArgumentException(Strings.Context_EntityDoesNotContainNamedStream(name), nameof(name));
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OData.Client/DataServiceRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ internal TElement GetValue<TElement>(DataServiceContext context, Func<QueryResul
Version requestVersion = queryComponents.Version;
if (requestVersion == null)
{
requestVersion = Util.ODataVersion4;
requestVersion = context.MaxProtocolVersionAsVersion;
}

Uri requestUri = queryComponents.Uri;
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.OData.Client/SaveResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ private ODataRequestMessageWrapper CheckAndProcessMediaEntryPost(EntityDescripto
mediaRequest = this.CreateMediaResourceRequest(
entityDescriptor.GetResourceUri(this.RequestInfo.BaseUriResolver, false /*queryLink*/),
XmlConstants.HttpMethodPost,
Util.ODataVersion4,
this.RequestInfo.MaxProtocolVersionAsVersion,
type.MediaDataMember == null, // sendChunked
true, // applyResponsePreference
headers,
Expand All @@ -623,7 +623,7 @@ private ODataRequestMessageWrapper CheckAndProcessMediaEntryPost(EntityDescripto
mediaRequest = this.CreateMediaResourceRequest(
entityDescriptor.GetResourceUri(this.RequestInfo.BaseUriResolver, false /*queryLink*/),
XmlConstants.HttpMethodPost,
Util.ODataVersion4,
this.RequestInfo.MaxProtocolVersionAsVersion,
type.MediaDataMember == null, // sendChunked
true, // applyResponsePreference
headers,
Expand Down Expand Up @@ -667,7 +667,7 @@ private ODataRequestMessageWrapper CheckAndProcessMediaEntryPut(EntityDescriptor
return this.CreateMediaResourceRequest(
requestUri,
XmlConstants.HttpMethodPut,
Util.ODataVersion4,
this.RequestInfo.MaxProtocolVersionAsVersion,
true, // sendChunked
false, // applyResponsePreference
headers,
Expand Down Expand Up @@ -925,7 +925,7 @@ private ODataRequestMessageWrapper CreateNamedStreamRequest(StreamDescriptor nam
ODataRequestMessageWrapper mediaRequestMessage = this.CreateMediaResourceRequest(
requestUri,
XmlConstants.HttpMethodPut,
Util.ODataVersion4,
this.RequestInfo.MaxProtocolVersionAsVersion,
true, // sendChunked
false, // applyResponsePreference
headers,
Expand Down
4 changes: 4 additions & 0 deletions src/Microsoft.OData.Client/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ internal static Version GetVersionFromMaxProtocolVersion(ODataProtocolVersion ma
{
case ODataProtocolVersion.V4:
return Util.ODataVersion4;
case ODataProtocolVersion.V401:
return Util.ODataVersion401;
default:
Debug.Assert(false, "Unexpected max protocol version values.");
return Util.ODataVersion4;
Expand Down Expand Up @@ -231,6 +233,8 @@ internal static ODataProtocolVersion CheckEnumerationValue(ODataProtocolVersion
{
case ODataProtocolVersion.V4:
return value;
case ODataProtocolVersion.V401:
return value;
default:
throw Error.ArgumentOutOfRange(parameterName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,14 @@ public void SaveChangesWithBatchWithIndependentOperationsAndContinueOnErrorShoul
test.ShouldThrow<ArgumentOutOfRangeException>().WithMessage("options", ComparisonMode.Substring);
}
#endif
[Fact]
public void DataServiceContextCanInitializev401WithoutException()
{
DataServiceContext dsContext = null;
Action test = () => dsContext = new DataServiceContext(new Uri("http://base.org/"), ODataProtocolVersion.V401);
test.ShouldNotThrow();
dsContext.MaxProtocolVersion.ShouldBeEquivalentTo(ODataProtocolVersion.V401);
}

[Fact]
public void DataServiceContextDoesNotRestrictBaseUriScheme()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ Partial Public Class ClientModule
New MaxProtocolVersionTestCase() {
New MaxProtocolVersionTestCase() With {.MaxProtocolVersion = ODataProtocolVersion.V4},
New MaxProtocolVersionTestCase() With {.MaxProtocolVersion = CType(-1, ODataProtocolVersion), .ExpectedExceptionMessage = "Specified argument was out of the range of valid values." & vbCrLf & "Parameter name: maxProtocolVersion"},
New MaxProtocolVersionTestCase() With {.MaxProtocolVersion = CType(ODataProtocolVersion.V4 + 1, ODataProtocolVersion), .ExpectedExceptionMessage = "Specified argument was out of the range of valid values." & vbCrLf & "Parameter name: maxProtocolVersion"}
New MaxProtocolVersionTestCase() With {.MaxProtocolVersion = CType(ODataProtocolVersion.V4 + 1, ODataProtocolVersion)}
},
Sub(testCase)
Dim context = New DataServiceContext(New Uri("http://host/service"))
Expand Down