diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2012-11-02 09:26:06 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2012-11-02 09:26:06 -0700 |
commit | 94a7276b4aad80faa0ccbe8d754f63d8d1d7c9fa (patch) | |
tree | d6f5242584ca06b923d113a2ad0c869fe2306d48 /src | |
parent | 46ed7ca81f78f70557ee9d02cdc69608d6fe1dc9 (diff) | |
download | DotNetOpenAuth-94a7276b4aad80faa0ccbe8d754f63d8d1d7c9fa.zip DotNetOpenAuth-94a7276b4aad80faa0ccbe8d754f63d8d1d7c9fa.tar.gz DotNetOpenAuth-94a7276b4aad80faa0ccbe8d754f63d8d1d7c9fa.tar.bz2 |
Fixes AsHttpResposneMessage() exception when response has no stream.
Fixes #226
Diffstat (limited to 'src')
-rw-r--r-- | src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs | 7 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs | 11 |
2 files changed, 15 insertions, 3 deletions
diff --git a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs index ab56d8b..b266a62 100644 --- a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs +++ b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs @@ -171,9 +171,10 @@ namespace DotNetOpenAuth.Messaging { /// <param name="outgoingResponse">The response to send to the user agent.</param> /// <returns>The <see cref="HttpResponseMessage"/> instance to be returned by the Web API method.</returns> public static HttpResponseMessage AsHttpResponseMessage(this OutgoingWebResponse outgoingResponse) { - HttpResponseMessage response = new HttpResponseMessage(outgoingResponse.Status) { - Content = new StreamContent(outgoingResponse.ResponseStream) - }; + HttpResponseMessage response = new HttpResponseMessage(outgoingResponse.Status); + if (outgoingResponse.ResponseStream != null) { + response.Content = new StreamContent(outgoingResponse.ResponseStream); + } var responseHeaders = outgoingResponse.Headers; foreach (var header in responseHeaders.AllKeys) { diff --git a/src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs b/src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs index 45583bf..8620b93 100644 --- a/src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/MessagingUtilitiesTests.cs @@ -91,6 +91,17 @@ namespace DotNetOpenAuth.Test.Messaging { } [Test] + public void AsHttpResponseMessageNoContent() { + var outgoingResponse = new OutgoingWebResponse(); + outgoingResponse.Headers.Add("X-SOME-HEADER", "value"); + + var httpResponseMessage = outgoingResponse.AsHttpResponseMessage(); + Assert.That(httpResponseMessage, Is.Not.Null); + Assert.That(httpResponseMessage.Headers.GetValues("X-SOME-HEADER").ToList(), Is.EqualTo(new[] { "value" })); + Assert.That(httpResponseMessage.Content, Is.Null); + } + + [Test] public void ToDictionary() { NameValueCollection nvc = new NameValueCollection(); nvc["a"] = "b"; |