Updated the HttpAbstractionClient code to check for a null content buffer when trying to send a POST or PUT request.
Added a unit test case to check for this bug.

Closes-Bug: #1331802
Change-Id: I99d93e77a0a5ca4c3678c825517050ab4e3f6789
This commit is contained in:
Wayne Foley 2014-06-30 13:57:13 -07:00
parent 8d0f9cc73d
commit 2675cd745b
2 changed files with 30 additions and 3 deletions

View File

@ -135,6 +135,30 @@ namespace OpenStack.Test.HttpAbstraction
}
}
[TestMethod]
[TestCategory("Integration")]
[TestCategory("LongRunning")]
public void CanMakePostRequestWithNullContent()
{
using (var client = new HttpAbstractionClientFactory().Create())
{
client.Uri = new Uri("http://httpbin.org/post");
client.Method = HttpMethod.Post;
var responseTask = client.SendAsync();
responseTask.Wait();
var response = responseTask.Result;
Assert.IsNotNull(response);
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
var stringContent = TestHelper.GetStringFromStream(response.Content);
Assert.IsTrue(stringContent.Contains("\"data\": \"\""));
}
}
[TestMethod]
[TestCategory("Integration")]
[TestCategory("LongRunning")]

View File

@ -79,10 +79,13 @@ namespace OpenStack.Common.Http
if (this.Method == HttpMethod.Post || this.Method == HttpMethod.Put)
{
requestMessage.Content = new StreamContent(this.Content);
if (this.ContentType != string.Empty)
if (this.Content != null)
{
requestMessage.Content.Headers.ContentType = new MediaTypeHeaderValue(this.ContentType);
requestMessage.Content = new StreamContent(this.Content);
if (this.ContentType != string.Empty)
{
requestMessage.Content.Headers.ContentType = new MediaTypeHeaderValue(this.ContentType);
}
}
}