[x] I have verified that I am running the latest version of Nancy
[x] I have verified if the problem exist in both DEBUG and RELEASE mode
[x] I have searched open and closed issues to ensure it has not already been reported
Description
If a POST request is sent with a body and a parameter then when deserializing Request.Body to string via .AsString() the POST data is correct but the parameter appears in the data and with the value 'null'.
For example, a JSON object would then have an extra field and this would be the parameter but with a null value.
Steps to Reproduce
Define a simple module and add an implementation of IApplicationStartup where pipelines.BeforeRequest.AddItemToStartOfPipeline has an implementation that desearilizes the Request.Body as a string.
For example (hand typed - not tested):
public class SomeModule : NancyModule
{
public RestServiceApi() : base("v1")
{
Post["SomeCommand"] = _ =>
{
var request = this.Bind<SomeCommandRequest>();
return Response.AsJson(new SomeCommandResponse {Status = "Unavailable"});
};
}
}
public class BeforeAllRequests : IApplicationStartup
{
public void Initialize(IPipelines pipelines)
{
pipelines.BeforeRequest.AddItemToStartOfPipeline(ctx =>
{
if (ctx.Request.Body.Length <= 0)
{
return ctx.Response;
}
var test = ctx.Request.Body.AsString(); <--- Partial parameter
return ctx.Response;
});
}
}
public void WhenSomeCommandCalledWithAParameterTheResponseContainsUnavailable()
{
var response = _testContext.Browser.Post("v1/SomeCommand", with =>
{
with.HttpRequest();
with.Query("SomeParameter", "123456789009876");
with.JsonBody(new SomeCommandRequest
{
SomeField = 111,
SomeOtherField = "TEST"
});
});
Assert.That(response.Body.DeserializeJson<SomeCommandResponse>().Status, Is.EqualTo("Unavailable"));
}
DEBUG
andRELEASE
modeDescription
If a POST request is sent with a body and a parameter then when deserializing Request.Body to string via .AsString() the POST data is correct but the parameter appears in the data and with the value 'null'.
For example, a JSON object would then have an extra field and this would be the parameter but with a null value.
Steps to Reproduce
Define a simple module and add an implementation of IApplicationStartup where
pipelines.BeforeRequest.AddItemToStartOfPipeline
has an implementation that desearilizes the Request.Body as a string.For example (hand typed - not tested):
Result:
{"someField":"111","someOtherField":"TEST","SomeParameter":null}