Bug 30065 - OWIN based self hosted app returns invalid HTTP response on windows mono build 4.0.1
Summary: OWIN based self hosted app returns invalid HTTP response on windows mono buil...
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-05-14 04:56 UTC by Alexander Voronin
Modified: 2018-03-13 15:24 UTC (History)
7 users (show)

Is this bug a regression?: ---
Last known good build:

Attachmanet contains simple test solution that haple to reproduce this error. (10.62 KB, application/octet-stream)
2015-05-14 04:56 UTC, Alexander Voronin

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Alexander Voronin 2015-05-14 04:56:58 UTC
Created attachment 11199 [details]
Attachmanet contains simple test solution that haple to reproduce this error.

Simple OWIN based self hosted server sends invalid HTTP response when running under windows mono 4.0.1 build. On native .net and linix build environment everythig works fine. Here is example of request:

telnet localhost 8080
GET / HTTP/1.0
Host: locahost

Server gives following answer:

P/1.1 200 OK
Content-Type: text/plain
Server: Mono-HTTPAPI/1.0
Date: Thu, 14 May 2015 08:51:03 GMT
Transfer-Encoding: chunked
Keep-Alive: timeout=15,max=100

Hello World

So "HTT" characters lost somewhere.
Please note - this is only windows mono build issue.

Thanx in advance.
Comment 1 Seth Wenzel 2015-07-26 14:54:28 UTC
My team is seeing the same behavior listed in this bug report.  This appears to be the same issue as Bug 32128.

We are able to run the self-hosted nancy and webapi owin apps in linux without seeing this issue, but it's making debugging difficult.  We are able to downgrade mono to 3.x which doesn't seem to be truncating the first 3 letters of the responses.
Comment 2 David Stahl 2015-09-05 20:02:56 UTC
Is there any update on this issue? I'm seeing it as well with Mono 

I haven't checked the attached project but if you follow the steps here (https://github.com/NancyFx/Nancy/wiki/Hosting-Nancy-with-Nginx-on-Ubuntu) for just the "Create a Nancy Website" portion, you'll have the simplest example which reproduces the issue.

I have done that and can post a link to a git repo that illustrates it as well with Mono on Windows 7 64-bit. It works correctly on Linux (tested 64-bit Ubuntu, Centos and even an ARM cross-compiled Mono).
Comment 3 Chris Mcvittie 2016-01-13 16:29:35 UTC

I just recreated it with the latest stable mono (4.2). Is anything else needed to get a resolution for this?

Comment 4 ColmanJ 2016-11-03 12:02:45 UTC
Is there any news about this problem? I'm using mono x64 and there the problem still exists
Comment 6 secondary.programmer 2017-01-24 02:59:09 UTC
This bug also occurs under Linux very infrequently.  The result is a dump of the http response as a text file under the browser.  Hitting reload often resolves the problem under Linux.

I wonder if this bug has anything to do with the following code in HttpListenerResponse.cs.

The StreamWriter constructor does not set whether or not it should close the memorystream ms upon disposal, which means that it should default to closing on upon disposal.  The constructor should use a constructor that sets the parameter leaveOpen to true.

internal void SendHeaders (bool closing, MemoryStream ms)


			StreamWriter writer = new StreamWriter (ms, encoding, 256);

			writer.Write ("HTTP/{0} {1} {2}\r\n", version, status_code, status_description);

			string headers_str = FormatHeaders (headers);

			writer.Write (headers_str);

			writer.Flush ();

			/* Assumes that the ms was at position 0 */

			ms.Position = preamble;

			HeadersSent = true;

Comment 7 Marek Safar 2018-03-13 15:24:11 UTC
The original issue works for me as expected with Mono master