在 Mono + FastCGI 中托管 ServiceStack 时二进制数据损坏 [英] Binary data corrupted when hosting ServiceStack in Mono + FastCGI

查看:25
本文介绍了在 Mono + FastCGI 中托管 ServiceStack 时二进制数据损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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 时它可以正常工作,但是当我在 Linux 中使用 Mono+FastCGI 运行它时,我下载的数据不一样.

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 + 
 + original data + 

0


为什么会发生这种情况以及如何解决?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆