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...
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: General (show other bugs)
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-05-14 04:56 UTC by Alexander Voronin
Modified: 2017-01-24 02:59 UTC (History)
6 users (show)

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


Attachments
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
Details

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

b
Hello World
0

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 4.0.3.20 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
Hi, 

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

Thanks
Comment 4 ColmanJ 2016-11-03 12:02:45 UTC
Is there any news about this problem? I'm using mono 4.6.1.5 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.

[code]
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;

		}
[/code]

Note You need to log in before you can comment on or make changes to this bug.