Binary data corrupted when hosting ServiceStack in Mono + FastCGI

混江龙づ霸主 提交于 2019-11-28 05:33:05

问题


I have a ServiceStack service with a method to handle a GET request. This method returns binary data.

public object Get(DownloadFile request) {
  return new HttpResult(new FileInfo("some file"), "application/octet-stream", asAttachment: true);
}

When the host is Windows it works fine but when I'm running it in Linux with Mono+FastCGI the data I download is not the same.

I analyzed the returned bytes for a few files and concluded that there is a pattern. The data is getting wrapped in this way:

original data size + \r\n + original data + \r\n\r\n0\r\n\r\n

Why is this happening and how to fix it?

Edit:

Turns out this is due to chunked transfers which are part of HTTP 1.1.

Knocte's answer pointed me in the right direction and I was able to work around the problem by forcing my request to use HTTP 1.0:

var req = (HttpWebRequest)WebRequest.Create(url);
req.ProtocolVersion = new Version("1.0");

I didn't need to try the patch suggested by knocte but it looks like it's the proper way to fix the problem instead of avoiding it like I did.


回答1:


I think you're being affected by this bug.

If the patch that is attached to it works for you, then you could clean it up, and propose it as a pull request to mono in github.



来源:https://stackoverflow.com/questions/17755322/binary-data-corrupted-when-hosting-servicestack-in-mono-fastcgi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!