在Python WSGI中处理HTTP PUT方法
我目前有一个 bash 应用程序,除其他外,它使用 cURL 通过 PUT 方法将文件上传到 Web 应用程序。我试图复制 Web 应用程序,因为客户端 (bash) 部分是 GPL,但 Web 部分不是。我也无法更改客户端应用程序,因为它会从开发人员的网站自动更新。 我找到了大量关于如何使用 WSGI、CherryPy、Twisted 处理 HTTP POST 方法的信息,以及几乎所有在 WWW 上运行 Python 脚本的方法。但是,我找不到任何有关 PUT 方法的信息。有谁知道如何使用 WSGI 处理 PUT 请求,或者是否有其他一些我缺少的具有 PUT 功能的框架?
I currently have a bash application that, among other things, uses cURL to upload a file to a web application with the PUT method. I am attempting to duplicate the web application as the client (bash) portion is GPL but the web portion is not. I also cannot alter the client application as it auto-updates itself from the developers' website.
I have found multitudes of information on how to handle the HTTP POST method with WSGI, CherryPy, Twisted, and practically every way of having Python scripts working on the WWW. However, I can't find a single thing about the PUT method. Does anyone know how to process a PUT request with WSGI, or is there some other framework with PUT functionality that I am missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我了解,您只想读取流
environ['wsgi.input']
,因为PUT
请求将发送的全部内容PUT
作为请求的正文。我不知道您需要处理任何编码问题(除了它是二进制的事实)。
前段时间,我编写了一组简单的 PHP 脚本,用于从 LAN 上的另一台服务器获取和提供大文件。我们从 POST 开始,但很快就耗尽了较大文件的内存。因此,我们切换到 PUT,其中 PHP 脚本可以花很长时间循环遍历
php://input
一次 4096 个字节(或其他)...它工作得很好。这是 PHP 代码:
根据我在 WSGI 中使用
POST
处理multipart/form-data
的经验,我毫不怀疑您可以处理PUT
code> 只需读取输入流即可。python 代码应该是这样的:
As I understand it, you will just want to read the stream
environ['wsgi.input']
, because aPUT
request will send the entire contents of thePUT
as the body of the request.I am not aware of any encoding issues you will have to deal with (other than the fact that it is binary).
Some time ago, I wrote a simple set of PHP scripts to take and give huge files from another server on a LAN. We started with POST, but quickly ran out of memory on the larger files. So we switched to PUT, where the PHP script could take it's good time looping through
php://input
4096 bytes at a time (or whatever)... It works great.Here is the PHP code:
From my experience in handling
multipart/form-data
in WSGI withPOST
, I have little doubt that you can handle aPUT
by just reading the input stream.The python code should be like this: