在Mono + FastCGI中托管ServiceStack时二进制数据损坏 [英] Binary data corrupted when hosting ServiceStack in Mono + FastCGI
问题描述
我有一个ServiceStack服务,该服务具有处理GET请求的方法.此方法返回二进制数据.
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);
}
当主机是Windows时,它可以正常工作,但是当我在具有Mono + FastCGI的Linux中运行它时,我下载的数据并不相同.
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?
事实证明,这是由于HTTP 1.1中的分块传输所致.
Turns out this is due to chunked transfers which are part of HTTP 1.1.
Knocte的答案为我指明了正确的方向,我能够通过强制我的请求使用HTTP 1.0来解决此问题:
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");
我不需要尝试knocte建议的补丁,但是看起来这是解决问题的正确方法,而不是像我那样避免.
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.
推荐答案
我认为您正受到此错误.
如果附加的修补程序对您有用,那么您可以清理它,并将其作为请求发送到github中的mono.
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.
这篇关于在Mono + FastCGI中托管ServiceStack时二进制数据损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!