我如何使用“期望:100-继续”扭曲网络中的标题?

发布于 2024-12-02 04:48:43 字数 1103 浏览 1 评论 0原文

我一直在使用 AkaDAV(一个基于 Twisted 的 WebDAV 服务器),并且我正在尝试支持完整的 < href="http://www.webdav.org/neon/litmus/" rel="nofollow">litmus 测试套件。我目前陷入了 http 子套件的困境。

具体来说,我可以运行:

$ TESTS=http litmus http://localhost:8080/steder/
-> running `http':
 0. init.................. pass
 1. begin................. pass
 2. expect100............. FAIL (timeout waiting for interim response)
 3. finish................ pass

此测试基本上执行以下操作:

  1. 打开 WebDAV 服务器的套接字
  2. 发出以下 PUT:

    PUT /steder/litmus/expect100 HTTP/1.1 主机:本地主机:8080 内容长度:100 预期:100-继续

  3. 等待响应HTTP/1.1 100继续响应。

  4. 上传 100 字节内容有效负载

这里令人困惑的是,看起来这个 PUT 请求从未发送到 Twisted。作为健全性检查,我已经确认通过 curl -X PUT ... 发出的 PUT 请求有效,因此这个测试用例似乎有一些特别之处。

有什么想法我可能做错了吗?如果有帮助的话,我很乐意分享源代码。

编辑:

经过更多查看后,这似乎是一个已知的 twisted.web 问题:http://twistedmatrix.com/trac/ticket/4673

有人知道解决方法吗?

I've been working with AkaDAV, a Twisted based WebDAV server, and I'm trying to support the full litmus test suite. I'm currently stuck on the http sub-suite.

Specifically, I can run:

$ TESTS=http litmus http://localhost:8080/steder/
-> running `http':
 0. init.................. pass
 1. begin................. pass
 2. expect100............. FAIL (timeout waiting for interim response)
 3. finish................ pass

This test basically does the following:

  1. Open a socket to the WebDAV server
  2. Issue the following PUT:

    PUT /steder/litmus/expect100 HTTP/1.1
    Host: localhost:8080
    Content-Length: 100
    Expect: 100-continue

  3. waits for a response HTTP/1.1 100 Continue response.

  4. uploads 100 byte content payload

The confusing thing here is that it looks like this PUT request never makes it to Twisted. As a sanity check I've confirmed that PUT requests issued through curl -X PUT ... work so it seems like there's something special about this testcase.

Any ideas what I may be doing wrong? I'm happy to share sourcecode if that helps.

EDIT:

After a little more looking around it appears that this is a known twisted.web issue: http://twistedmatrix.com/trac/ticket/4673

Does anyone know of a workaround?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素手挽清风 2024-12-09 04:48:43

经过更多调查后,我们很清楚如何修改 HTTP 协议实现来支持此用例。看起来官方修复很快就会在 Twisted 中发布,但与此同时我正在使用它作为解决方法。

只需在实例化您的 Site (或 twhttp.HTTPFactory)之前包含此代码:

from twisted.web import http


class HTTPChannelWithExpectContinue(http.HTTPChannel):
    def headerReceived(self, line):
        """Just extract the header and handle Expect 100-continue:
        """
        header, data = line.split(':', 1)
        header = header.lower()
        data = data.strip()
        if (self._version=="HTTP/1.1" and
            header == 'expect' and data.lower() == '100-continue'):
            self.transport.write("HTTP/1.1 100 Continue\r\n\r\n")
        return http.HTTPChannel.headerReceived(self, line)


http.HTTPFactory.protocol = HTTPChannelWithExpectContinue

我想如果您需要在协议级别进行其他修改,您可以使用相同的方法来修补它们也在。它不一定很漂亮,但对我有用。

After some more investigation it's pretty clear how to modify the HTTP protocol implementation to support this use case. It looks like the official fix will be in Twisted soon but in the meantime I'm using this as a workaround.

Just include this code before you instantiate your Site (or t.w.http.HTTPFactory):

from twisted.web import http


class HTTPChannelWithExpectContinue(http.HTTPChannel):
    def headerReceived(self, line):
        """Just extract the header and handle Expect 100-continue:
        """
        header, data = line.split(':', 1)
        header = header.lower()
        data = data.strip()
        if (self._version=="HTTP/1.1" and
            header == 'expect' and data.lower() == '100-continue'):
            self.transport.write("HTTP/1.1 100 Continue\r\n\r\n")
        return http.HTTPChannel.headerReceived(self, line)


http.HTTPFactory.protocol = HTTPChannelWithExpectContinue

I imagine if you needed other modifications at the protocol level you could use this same method to patch them in as well. It ain't necessarily pretty but it works for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文