Curl 返回没有响应并且不等待 `wait=x 秒`

Curl 返回没有响应并且不等待 `wait=x 秒`

我调用一个异步服务,大约需要 80 秒才能响应。我跑:

curl -v -X POST https://hostname.com/service/v2/predict \
  -H 'x-api-key: somekey' \
  -H 'x-request-id: longfiles' \
  -H "Authorization: Bearer dfv651df8fdvd" \
  -H 'Prefer: respond-async, wait=200' \
  -F 'contentAnalyzerRequests={"inputtest": "this is a test"}
  -F infile=@/mnt/file/stream-01865caa-b2e0-40e4-b298-1502fcc65045.json

该命令指定了wait=200但curl 在约60 秒内返回。由于该服务需要约 80 秒的时间来响应,因此我没有得到任何响应(但如果我使用 ,我确实会得到响应wait=1000)。为什么?


卷曲查询的输出-v

> Prefer: respond-async, wait=200
> Content-Length: 19271573
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------5873f0b92dd68547
>
< HTTP/1.1 100 Continue
< HTTP/1.1 202 Accepted
< Server: openresty
< Date: Fri, 07 Oct 2022 21:55:33 GMT
< Content-Length: 0
< Connection: keep-alive
< x-request-id: longfiles
< vary: Origin,Access-Control-Request-Method,Access-Control-Request-Headers
< location: https://hostname.com/service/v2/status/longfiles
< retry-after: 1
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: Authorization,Content-Type,X-Api-Key,User-Agent,If-Modified-Since,Prefer,location,x-transaction-id,retry-after,cache-control
< Access-Control-Allow-Methods: GET, POST, PUT ,DELETE, OPTIONS,PATCH
< Access-Control-Expose-Headers: location, retry-after, x-request-id, x-transaction-id, cache-control
< Access-Control-Max-Age: 86400
<
* Connection #0 to host hostname.com left intact

答案1

HTTP 响应HTTP/1.1 202 Accepted 表示请求已被接受处理,但处理尚未完成。

关键是:

< location: https://hostname.com/service/v2/status/longfiles
< retry-after: 1

这意味着输出将在https://hostname.com/service/v2/status/longfiles一旦处理完成。retry-after: 1意味着每秒最多可以重试查看该位置 1 次。

该命令指定 wait=200,但curl 在大约 60 秒内返回。

该服务可能有 60 秒的超时时间来发送HTTP 202 Accepted响应。

调用方案流程图:

在此输入图像描述

相关内容