TIdHTTPServer 与 Microsoft BITS 兼容吗
我们正在尝试使用 TIdHTTPServer 组件为我们的软件编写更新服务器。目前,我们正在提供一个 XML 文件,其中列出了可用的更新及其文件版本等。当客户端程序找到更新版本时,它应该开始使用 BITS 下载它。
现在这就是我们遇到问题的地方,我们的程序正在请求 XML 文件并查看是否有可用的更新。然后,它创建一个 BITS 作业来下载它,但 BITS 不断报告下载失败。我们可以使用相同的 URL 和 IE/Firefox/Chrome 下载该文件。
所以我的问题是:
TIdHTTPServer 与 BITS 兼容吗?
我问这个是因为我发现位的工作有这些下载要求。
BITS 下载的 HTTP 要求
BITS支持HTTP和HTTPS下载和上传,要求服务器支持HTTP/1.1协议。对于下载,HTTP 服务器的 Head 方法必须返回文件大小,并且其 Get 方法必须支持 Content-Range 和 Content-Length 标头。因此,BITS 仅传输静态文件内容,如果您尝试传输动态内容,则会生成错误,除非 ASP、ISAPI 或 CGI 脚本支持 Content-Range 和 Content-Length 标头。
只要满足 Head 和 Get 方法要求,BITS 就可以使用 HTTP/1.0 服务器。
为了支持文件的下载范围,服务器必须支持以下要求:
允许 MIME 标头包含标准 Content-Range 和 Content-Type 标头,以及最多 180 字节的其他标头。 HTTP 标头和第一个边界字符串之间最多允许有两个 CR/LF。
We are trying to write an update server for our software using the TIdHTTPServer component. Currently we are serving an XML file that lists the available updates and their file versions etc.., when the client program finds a updated version it should start to download it using BITS.
Now this is where we have a problem, our programs are requesting the XML file and seeing there is an update available. It then creates a BITS job to download it, however BITS keeps reporting that the download failed. We can download the file using the same URL and IE/Firefox/Chrome.
so my question:
Is TIdHTTPServer compatible with BITS?
I ask this as I have discovered that there are these download requirements for bits to work.
HTTP Requirements for BITS Downloads
BITS supports HTTP and HTTPS downloads and uploads and requires that the server supports the HTTP/1.1 protocol. For downloads, the HTTP server's Head method must return the file size and its Get method must support the Content-Range and Content-Length headers. As a result, BITS only transfers static file content and generates an error if you try to transfer dynamic content, unless the ASP, ISAPI, or CGI script supports the Content-Range and Content-Length headers.
BITS can use an HTTP/1.0 server as long as it meets the Head and Get method requirements.
To support downloading ranges of a file, the server must support the following requirements:
Allow MIME headers to include the standard Content-Range and Content-Type headers, plus a maximum of 180 bytes of other headers.
Allow a maximum of two CR/LFs between the HTTP headers and the first boundary string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
刚刚在 indy 中发现了一个错误,该错误会在使用范围请求时阻止传输超过 2.1GB 的文件。
这里是
IdHTTPHeaderInfo.pas
大约第 770 行这应该是
Remy 需要修复的一个
Just found a bug in indy that prevents transfer of files over 2.1GB when using range requests.
here it is
IdHTTPHeaderInfo.pas
aprox line 770This should be
One for Remy to fix
当您处理
OnCommandGet
事件时,您将获得一个TIdRequestHeaderInfo
,它源自TIdEntityHeaderInfo
;包含请求包含的所有标头,它甚至解析出一些标头值以作为属性读取,包括ContentRangeStart
、ContentRangeEnd
和ContentLength
。您可以使用这些属性来填充分配给
TIdHTTPResponseInfo.ContentStream
属性的流。 整个流将被发送。您的工作是区分 GET 和 HEAD 请求;无论哪种方式,
OnCommandGet
都会被触发。检查IdHTTPRequestInfo.CommandType
属性。因此,尽管 Indy 可能不支持 BITS,但它提供了编写支持 BITS 的程序所需的所有工具。
When you handle the
OnCommandGet
event, you are given aTIdRequestHeaderInfo
, which descends fromTIdEntityHeaderInfo
; that contains all the headers the request contained, and it even parses out some header values to read as properties, includingContentRangeStart
,ContentRangeEnd
, andContentLength
.You can use those properties to populate the stream that you assign to the
TIdHTTPResponseInfo.ContentStream
property. The entire stream will get sent.It's your job to differentiate between GET and HEAD requests;
OnCommandGet
will get triggered either way. Check theIdHTTPRequestInfo.CommandType
property.So, although Indy may not support BITS, it provides all the tools you need to write a program that does support BITS.
所以这个问题的答案是:
是的,TIdHTTPServer 是位兼容的。
但前提是您准备好自己完成这项工作。
正如 @Rob Kennedy 和我自己所建议的那样可以读取标头并使用请求的范围将数据发送回,一次一个块。
这是我在 OnCommandGet 事件中所做的示例
这还没有完成,但它显示了响应来自 BITS 的范围请求的基础知识。最重要的是它有效。
对代码的任何评论将不胜感激,建设性的批评总是受欢迎的。
So the answer to this question is:
Yes TIdHTTPServer is Bits Compatible.
But only if you are prepared to do the work yourself.
As suggested by @Rob Kennedy and Myself it is possible to read the headers and send the data back using the requested ranges, one chunk at a time.
Here is an example of what I am doing in the
OnCommandGet
eventThis is by no means finished but it shows the basics of responding to the range requests from BITS. Most importantly it works.
Any comments on the code would be appreciated, constructive criticism always welcome.