public void HeaderShouldBeCaseInsensitive() { HeaderCollection headers = new HeaderCollection(); headers.SetHeader("Accept", MimeType); headers.SetHeader("Content-Type", MimeType); BuildingRequestEventArgs requestEventArgs = new BuildingRequestEventArgs("GET", new Uri("http://localhost"), headers, null, HttpStack.Auto); DataServiceClientRequestMessageArgs args = new DataServiceClientRequestMessageArgs( requestEventArgs.Method, requestEventArgs.RequestUri, false, false, requestEventArgs.Headers); HttpWebRequestMessage request = new HttpWebRequestMessage(args); const int maxPageSize = 10; ODataPreferenceHeader preferHeader = new ODataPreferenceHeader(request); preferHeader.MaxPageSize = maxPageSize; Assert.Equal(maxPageSize, preferHeader.MaxPageSize); string expected = $"{MaxPageSizePreference}={maxPageSize}"; Assert.Equal(expected, request.GetHeader("pReFer")); Assert.Equal(MimeType, request.GetHeader("accepT")); }
protected internal async override Task <Stream> OnGetResponse(HttpWebRequestMessage requestMessage, Stream requestStream) { Stream response; IOdataWcf client = null; try { client = _channelFactory.CreateChannel(); if (requestStream == null) { String accept = requestMessage.GetHeader("Accept"); response = await client.Get(requestMessage.Url.PathAndQuery, accept); } else { String contentType = requestMessage.GetHeader(ODataConstants.ContentTypeHeader); requestStream.Position = 0; OdataWcfPostResponse postResponse = await client.Post(new OdataWcfPostRequest() { ContentType = contentType, RequestStream = requestStream }); response = postResponse.ResponseStream; } } finally { if (client != null) { var clientChannel = (IClientChannel)client; clientChannel.Close(); } } return(response); }
protected internal async override Task <OdataWcfQuery> OnGetResponse(HttpWebRequestMessage requestMessage, Stream requestStream) { OdataWcfQuery response; IOdataWcf client = null; try { client = _channelFactory.CreateChannel(); if (requestStream == null || requestStream.Length == 0) { String accept = requestMessage.GetHeader("Accept"); String prefer = requestMessage.GetHeader("Prefer"); var query = new MemoryStream(Encoding.UTF8.GetBytes(requestMessage.Url.PathAndQuery)); response = await client.Get(new OdataWcfQuery() { Content = query, ContentType = accept, Prefer = prefer }); } else { String contentType = requestMessage.GetHeader(ODataConstants.ContentTypeHeader); requestStream.Position = 0; response = await client.Post(new OdataWcfQuery() { Content = requestStream, ContentType = contentType }); } } finally { if (client != null) { var clientChannel = (IClientChannel)client; clientChannel.Close(); } } return(response); }