예제 #1
0
 public void AnnotationFilterShouldNotBeSetAndRequiredResponseVersionShouldBe10WhenTheODataAnnotationsPreferenceIsMissing()
 {
     RequestDescription descrption = new RequestDescription(RequestTargetKind.Link, RequestTargetSource.ServiceOperation, new Uri("http://service/set"));
     IODataRequestMessage requestMessage = new ODataRequestMessageSimulator();
     ClientPreference preference = new ClientPreference(descrption, HttpVerbs.None, requestMessage, effectiveMaxResponseVersion: VersionUtil.Version4Dot0);
     preference.AnnotationFilter.Should().BeNull();
     preference.RequiredResponseVersion.Should().Be(VersionUtil.Version4Dot0);
 }
예제 #2
0
 public void AnnotationFilterShouldBeSetWithODataAnnotationsPreferenceAndRequiredResponseVersionShouldBe30WhenEffectiveMaxResponseVersionIs30()
 {
     RequestDescription descrption = new RequestDescription(RequestTargetKind.Link, RequestTargetSource.ServiceOperation, new Uri("http://service/set"));
     IODataRequestMessage requestMessage = new ODataRequestMessageSimulator();
     requestMessage.PreferHeader().AnnotationFilter = "*";
     ClientPreference preference = new ClientPreference(descrption, HttpVerbs.None, requestMessage, effectiveMaxResponseVersion: VersionUtil.Version4Dot0);
     preference.AnnotationFilter.Should().Be("*");
     preference.RequiredResponseVersion.Should().Be(VersionUtil.Version4Dot0);
 }
예제 #3
0
        /// <summary>Sets the response status code and the default caching and versioning headers.</summary>
        /// <param name="description">The request description for the current request.</param>
        /// <param name="statusCode">The status code for the response.</param>
        internal void SetResponseHeaders(RequestDescription description, int statusCode)
        {
            // Set the caching policy appropriately - for the time being, we disable caching.
            this.SetHeader(XmlConstants.HttpResponseCacheControl, XmlConstants.HttpCacheControlNoCache);

            // If a preference was applied, add corresponding response header.
            ClientPreference preference = description.Preference;

            this.PreferenceAppliedHeader().ReturnContent = preference.ShouldIncludeResponseBody ? true : (preference.ShouldNotIncludeResponseBody ? (bool?)false : null);

            // Only set the annotation filter to the Preference-Applied if we are writing a response body
            // since instance annotations only appear in the response body.
            if (description.ShouldWriteResponseBody && !string.IsNullOrEmpty(preference.AnnotationFilter))
            {
                this.PreferenceAppliedHeader().AnnotationFilter = preference.AnnotationFilter;
            }

            this.SetHeader(XmlConstants.HttpODataVersion, description.ResponseVersion.ToString() + ";");
            this.StatusCode = statusCode;
        }