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:
@@ -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]
|
[TestMethod]
|
||||||
[TestCategory("Integration")]
|
[TestCategory("Integration")]
|
||||||
[TestCategory("LongRunning")]
|
[TestCategory("LongRunning")]
|
||||||
|
|||||||
@@ -79,10 +79,13 @@ namespace OpenStack.Common.Http
|
|||||||
|
|
||||||
if (this.Method == HttpMethod.Post || this.Method == HttpMethod.Put)
|
if (this.Method == HttpMethod.Post || this.Method == HttpMethod.Put)
|
||||||
{
|
{
|
||||||
requestMessage.Content = new StreamContent(this.Content);
|
if (this.Content != null)
|
||||||
if (this.ContentType != string.Empty)
|
|
||||||
{
|
{
|
||||||
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user