Fix for bug #1331802.
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:
parent
8d0f9cc73d
commit
2675cd745b
|
@ -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")]
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue