public void SetHttpMessageContentTransferEncodingFromRequestInsteadOfPayloadHandler() { // the TestPayloadHandler has a ContentType of "foo" var testPayloadHandler = new TestPayloadHandler(); // register the payload handler so that it is found when the ContentType of the request is set PayloadHandler.TryRegister(testPayloadHandler); // set the ContentType of the request to match the ContentType of the TestPayloadHandler so that the request uses the TestPayloadHandler var testHttpRequest = new HttpRequest { ContentType = "foo", ContentTransferEncoding = "testContentTransferEncoding-fromRequest", }; var testContentTransferEncoding = "testContentTransferEncoding-fromPayloadHandler"; testPayloadHandler.SetContentTransferEncoding(testContentTransferEncoding); var httpRequestMessage = new HttpRequestMessage(); testPayloadHandler.SetHttpRequestMessageContent(testHttpRequest, httpRequestMessage); httpRequestMessage.Headers.Contains("Content-Transfer-Encoding").Should().BeTrue(); // the content transfer encoding set on the request should win over the content transfer encoding set on the payload handler httpRequestMessage.Headers.ToString().Should().BeOneOf( "Content-Transfer-Encoding: testContentTransferEncoding-fromRequest\n", "Content-Transfer-Encoding: testContentTransferEncoding-fromRequest\r\n"); httpRequestMessage.Content.Should().NotBeNull(); httpRequestMessage.Content.GetType().Should().Be(typeof(StringContent)); }
public void SetHttpMessageContentTransferEncodingHeader() { // the TestPayloadHandler has a ContentType of "foo" var testPayloadHandler = new TestPayloadHandler(); // register the payload handler so that it is found when the ContentType of the request is set. The OktaClient will register payload handlers as appropriate. PayloadHandler.TryRegister(testPayloadHandler); // set the ContentType of the request to match the ContentType of the TestPayloadHandler so that the request uses the TestPayloadHandler var testHttpRequest = new HttpRequest { ContentType = "foo" }; var testContentTransferEncoding = "testContentTransferEncoding-fromPayloadHandler"; testPayloadHandler.SetContentTransferEncoding(testContentTransferEncoding); var httpRequestMessage = new HttpRequestMessage(); testPayloadHandler.SetHttpRequestMessageContent(testHttpRequest, httpRequestMessage); httpRequestMessage.Headers.Contains("Content-Transfer-Encoding").Should().BeTrue(); // if there is no content transfer encoding on the request then the value from the PayloadHandler is used httpRequestMessage.Headers.ToString().Should().BeOneOf( "Content-Transfer-Encoding: testContentTransferEncoding-fromPayloadHandler\n", "Content-Transfer-Encoding: testContentTransferEncoding-fromPayloadHandler\r\n"); httpRequestMessage.Content.Should().NotBeNull(); httpRequestMessage.Content.GetType().Should().Be(typeof(StringContent)); }