/// <summary>
        /// Sets the request's content type header.
        /// </summary>
        /// <param name="headers">Dictionary of request headers.</param>
        /// <param name="mediaType">content type</param>
        private void SetRequestContentTypeHeader(HeaderCollection headers, string mediaType)
        {
            if (mediaType == MimeApplicationJsonODataLight)
            {
                // set the request version to 4.0
                headers.SetRequestVersion(Util.ODataVersion4, this.context.MaxProtocolVersionAsVersion);
            }

            headers.SetHeaderIfUnset(XmlConstants.HttpContentType, mediaType);
        }
示例#2
0
        /// <summary>
        /// Creates HTTP request for the media resource (MR)
        /// </summary>
        /// <param name="requestUri">The URI to request</param>
        /// <param name="method">The HTTP method to use (POST or PUT)</param>
        /// <param name="version">version to be sent in the DSV request header.</param>
        /// <param name="sendChunked">Send the request using chunked encoding to avoid buffering.</param>
        /// <param name="applyResponsePreference">If the response preference setting should be applied to the request
        /// (basically means if the response is expected to contain an entity or not).</param>
        /// <param name="headers">Collection of request headers</param>
        /// <param name="descriptor">Descriptor for this media resource request.</param>
        /// <returns>An instance of ODataRequestMessage.</returns>
        private ODataRequestMessageWrapper CreateMediaResourceRequest(Uri requestUri, string method, Version version, bool sendChunked, bool applyResponsePreference, HeaderCollection headers, Descriptor descriptor)
        {
            headers.SetHeaderIfUnset(XmlConstants.HttpContentType, XmlConstants.MimeAny);

            if (applyResponsePreference)
            {
                ApplyPreferences(headers, method, this.RequestInfo.AddAndUpdateResponsePreference, ref version);
            }

            // Set the request DSV and request MDSV headers
            headers.SetRequestVersion(version, this.RequestInfo.MaxProtocolVersionAsVersion);
            this.RequestInfo.Format.SetRequestAcceptHeader(headers);

            ODataRequestMessageWrapper requestMessage = this.CreateRequestMessage(method, requestUri, headers, this.RequestInfo.HttpStack, descriptor, null /*contentId*/);

            // TODO: since under the hood this is a header, we should put it in our dictionary of headers that the user gets in BuildingRequest
            // and later on handle the setting of the strongly named property on the underlying request
            requestMessage.SendChunked = sendChunked;
            return(requestMessage);
        }
示例#3
0
        /// <summary>
        /// Creates HTTP request for the media resource (MR)
        /// </summary>
        /// <param name="requestUri">The URI to request</param>
        /// <param name="method">The HTTP method to use (POST or PUT)</param>
        /// <param name="version">version to be sent in the DSV request header.</param>
        /// <param name="sendChunked">Send the request using chunked encoding to avoid buffering.</param>
        /// <param name="applyResponsePreference">If the response preference setting should be applied to the request
        /// (basically means if the response is expected to contain an entity or not).</param>
        /// <param name="headers">Collection of request headers</param>
        /// <param name="descriptor">Descriptor for this media resource request.</param>
        /// <returns>An instance of ODataRequestMessage.</returns>
        private ODataRequestMessageWrapper CreateMediaResourceRequest(Uri requestUri, string method, Version version, bool sendChunked, bool applyResponsePreference, HeaderCollection headers, Descriptor descriptor)
        {
            headers.SetHeaderIfUnset(XmlConstants.HttpContentType, XmlConstants.MimeAny);

            if (applyResponsePreference)
            {
                ApplyPreferences(headers, method, this.RequestInfo.AddAndUpdateResponsePreference, ref version);
            }

            // Set the request DSV and request MDSV headers
            headers.SetRequestVersion(version, this.RequestInfo.MaxProtocolVersionAsVersion);
            this.RequestInfo.Format.SetRequestAcceptHeader(headers);

            ODataRequestMessageWrapper requestMessage = this.CreateRequestMessage(method, requestUri, headers, this.RequestInfo.HttpStack, descriptor, null /*contentId*/);

            // TODO: since under the hood this is a header, we should put it in our dictionary of headers that the user gets in BuildingRequest
            // and later on handle the setting of the strongly named property on the underlying request
            requestMessage.SendChunked = sendChunked;
            return requestMessage;
        }
 private void SetAcceptHeaderAndCharset(HeaderCollection headers, string mediaType)
 {
     // NOTE: we intentionally do NOT set the DSV header for 'accept' as content-negotiation
     // is primarily about determining how to respond and not how to interpret the request.
     // It is entirely valid to send a V1 request and get a V3 response.
     // (We do set the DSV to 3 for Content-Type above)
     headers.SetHeaderIfUnset(XmlConstants.HttpAccept, mediaType);
     headers.SetHeaderIfUnset(HttpAcceptCharset, Utf8Encoding);
 }
        /// <summary>
        /// Sets the request's content type header.
        /// </summary>
        /// <param name="headers">Dictionary of request headers.</param>
        /// <param name="mediaType">content type</param>
        private void SetRequestContentTypeHeader(HeaderCollection headers, string mediaType)
        {
            if (mediaType == MimeApplicationJsonODataLight)
            {
                // set the request version to 4.0
                headers.SetRequestVersion(Util.ODataVersion4, this.context.MaxProtocolVersionAsVersion);
            }

            headers.SetHeaderIfUnset(XmlConstants.HttpContentType, mediaType);
        }