Incorrect Content-Length Header Causes Request Cancellation
Author: biscuitWizardCreated Aug 21, 2017Updated Jan 6, 2020
Prerequisites
- I have written a descriptive issue title
- I have verified that I am running the latest version of Nancy
- I have verified if the problem exist in both
DEBUGandRELEASEmode - I have searched open and closed issues to ensure it has not already been reported
Description
If Content-Length is set to an incorrect number on purpose (IE: Not matching content body length) the Pipeline fails with exception:
42568 [ 38] ERROR Program (null) - Unhandled
Exception Caught in NancyFX
System.Net.HttpListenerException (0x80004005): An operation was attempted on a n
onexistent network connection
at System.Net.HttpRequestStream.BeginRead(Byte[] buffer, Int32 offset, Int32
size, AsyncCallback callback, Object state)
at Nancy.Extensions.StreamExtensions.CopyTo(Stream source, Stream destination
, Action`3 onComplete)
at Nancy.IO.RequestStream.MoveToWritableStream()
at Nancy.IO.RequestStream..ctor(Stream stream, Int64 expectedLength, Int64 th
resholdLength, Boolean disableStreamSwitching)
at Nancy.Hosting.Self.NancyHost.ConvertRequestToNancyRequest(HttpListenerRequ
est request)
at Nancy.Hosting.Self.NancyHost.Process(HttpListenerContext ctx)before even reaching the BeforeRequest pipeline hooks. This is a concern because in cases where the two do not match (Example: During 29%~ Packet Loss, actual content stream malformation) it is impossible to deal with and recover from this issue.
Steps to Reproduce
- Create a simple route in NancyFX
- Make a request to that route with some sample data in the body, and a random content-length.
- Observe OnError thrown in the pipeline
System Configuration
- Nancy version: 1.4.1
- Nancy host
- ASP.NET
- OWIN
- Self-Hosted
- Other Nancy packages and versions:
- Environment (Operating system, version and so on): windows 8.1, windows 10
- .NET Framework version: 4.5
- Additional information:
Source: NancyFx/Nancy