我开发了一个服务器应用程序,其中包括处理大块数据的上传。当上传请求开始时,服务器应用程序甚至在接收到块之前就进行了一些检查,以使客户端在出现问题时中止操作,而不是仅在他发送了千兆字节的数据后才发现问题。 / p>
使用curl
玩服务器应用程序时,我发现了一个奇怪的行为。
curl
启动请求,已准备好流式传输数据。 curl
失败,退出代码18和以下输出:
卷曲:(18)传输关闭,剩余30个字节可供读取
启用详细输出时,这是我看到的内容:
$ curl -X PUT --limit-rate 2M http://127.0.0.1/blob -F files[]=@/tmp/tmp75hw30vc -v
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> PUT /blob HTTP/1.1
> Host: 127.0.0.1
> User-Agent: curl/7.58.0
> Accept: */*
> Content-Length: 2439352842
> Content-Type: multipart/form-data; boundary=------------------------32c442f4cf8abe0c
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
< HTTP/1.1 403 FORBIDDEN
< Server: nginx/1.10.3
< Date: Sat, 29 Sep 2018 22:03:16 GMT
< Content-Type: application/json
< Content-Length: 30
< Connection: keep-alive
* HTTP error before end of send, stop sending
<
* transfer closed with 30 bytes remaining to read
* stopped the pause stream!
* Closing connection 0
curl: (18) transfer closed with 30 bytes remaining to read
在服务器端,代码(使用Flask)如下:
def receive_blob():
if _can_upload():
return flask.jsonify({"error": "already-uploading"}), 403
...
我不确定问题是否与我使用Flask的方式或我正在使用的curl
选项有关。
如何避免这种情况,即让curl
显示服务器返回的JSON错误消息?
该问题不是How to handle "100 continue" HTTP message?的重复项,因为我的明确询问如何使curl
显示JSON错误消息。链接的问题邀请添加--fail
,这将导致输出“ curl:(22)请求的URL返回错误:403 FORBIDDEN”