internal void InitializeRequestVersionHeaders(Version maxProtocolVersion)
        {
            Version maxRequestVersionAllowed = GetMaxRequestVersionAllowed(maxProtocolVersion);

            this.requestVersionString = this.host.RequestVersion;
            this.requestMinVersion    = this.GetMinDataServiceVersion(maxRequestVersionAllowed);
            this.requestVersion       = ValidateVersionHeader("DataServiceVersion", this.requestVersionString);
            this.requestMaxVersion    = ValidateVersionHeader("MaxDataServiceVersion", this.host.RequestMaxVersion);
            if (this.requestVersion == null)
            {
                if (this.requestMaxVersion != null)
                {
                    if ((this.requestMaxVersion >= RequestDescription.Version2Dot0) && (maxProtocolVersion >= RequestDescription.Version2Dot0))
                    {
                        this.requestVersion = (this.requestMaxVersion < maxProtocolVersion) ? this.requestMaxVersion : maxProtocolVersion;
                    }
                    else
                    {
                        this.requestVersion = (maxProtocolVersion < RequestDescription.Version2Dot0) ? maxProtocolVersion : RequestDescription.Version2Dot0;
                    }
                }
                else
                {
                    this.requestVersion = maxProtocolVersion;
                }
                this.requestVersionString = this.requestVersion.ToString(2);
            }
            else
            {
                if (this.requestVersion > maxRequestVersionAllowed)
                {
                    throw DataServiceException.CreateBadRequestError(Strings.DataService_RequestVersionMustBeLessThanMPV(this.requestVersion, maxProtocolVersion));
                }
                if (!RequestDescription.IsKnownRequestVersion(this.requestVersion))
                {
                    throw DataServiceException.CreateBadRequestError(Strings.DataService_InvalidRequestVersion(this.requestVersion.ToString(2), KnownDataServiceVersionsToString(maxRequestVersionAllowed)));
                }
            }
            if (this.requestMaxVersion == null)
            {
                this.requestMaxVersion = maxProtocolVersion;
            }
            else if (this.requestMaxVersion < RequestDescription.DataServiceDefaultResponseVersion)
            {
                throw DataServiceException.CreateBadRequestError(Strings.DataService_MaxDSVTooLow(this.requestMaxVersion.ToString(2), RequestDescription.DataServiceDefaultResponseVersion.Major, RequestDescription.DataServiceDefaultResponseVersion.Minor));
            }
            if (this.requestMaxVersion < this.requestMinVersion)
            {
                throw DataServiceException.CreateBadRequestError(Strings.DataService_MaxDSVLowerThanMinDSV(this.requestMaxVersion.ToString(2), this.requestMinVersion.ToString(2)));
            }
        }
Beispiel #2
0
 internal static bool TryGetMinResponseVersionForError(DataServiceHostWrapper host, Version maxProtocolVersion, out Version responseVersion)
 {
     responseVersion = null;
     try
     {
         Version version;
         if (((maxProtocolVersion > RequestDescription.Version2Dot0) && (host.RequestMaxVersion > RequestDescription.Version2Dot0)) && WebUtil.ResponseMediaTypeWouldBeJsonLight(host.RequestAccept, false))
         {
             responseVersion = RequestDescription.Version3Dot0;
         }
         if (!host.TryGetMinDataServiceVersionFromWrappedHost(out version))
         {
             return(responseVersion != null);
         }
         if ((responseVersion == null) || (version > responseVersion))
         {
             responseVersion = version;
         }
         if (maxProtocolVersion < RequestDescription.Version3Dot0)
         {
             responseVersion = RequestDescription.DataServiceDefaultResponseVersion;
             return(true);
         }
         if (!RequestDescription.IsKnownRequestVersion(responseVersion) || (responseVersion > maxProtocolVersion))
         {
             return(false);
         }
         return(true);
     }
     catch (Exception exception)
     {
         if (!CommonUtil.IsCatchableExceptionType(exception))
         {
             throw;
         }
     }
     return(false);
 }
 private Version GetMinDataServiceVersion(Version maxProtocolVersion)
 {
     if (this.requestMinVersion == null)
     {
         this.TryGetMinDataServiceVersionFromWrappedHost(out this.requestMinVersion);
         if ((maxProtocolVersion < RequestDescription.Version3Dot0) || (this.requestMinVersion == null))
         {
             this.requestMinVersion = RequestDescription.DataServiceDefaultResponseVersion;
         }
         else
         {
             if (this.requestMinVersion > maxProtocolVersion)
             {
                 throw DataServiceException.CreateBadRequestError(Strings.DataService_MinDSVGreaterThanMPV(this.requestMinVersion.ToString(2), maxProtocolVersion.ToString(2)));
             }
             if (!RequestDescription.IsKnownRequestVersion(this.requestMinVersion))
             {
                 throw DataServiceException.CreateBadRequestError(Strings.DataService_InvalidMinDSV(this.requestMinVersion.ToString(2), KnownDataServiceVersionsToString(GetMaxRequestVersionAllowed(maxProtocolVersion))));
             }
         }
     }
     return(this.requestMinVersion);
 }