1

I call an async service that takes ~80 seconds to respond. I run:

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

The command specifies wait=200 but curl returns in ~60 seconds. And since the service takes ~80 seconds to respond, I get no response (but I do get a response if I use wait=1000). Why?


Output of the curl query with -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
Franck Dernoncourt
  • 4,749
  • 15
  • 48
  • 79

1 Answers1

1

The HTTP response HTTP/1.1 202 Accepted indicates that the request has been accepted for processing, but the processing has not been completed yet.

The key is:

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

It means the output will be available at https://hostname.com/service/v2/status/longfiles once the processing has been completed. retry-after: 1 means one can retry looking at that location at most 1 time per second.

The command specifies wait=200 but curl returns in ~60 seconds.

The service may have a timeout of 60 seconds to send an HTTP 202 Accepted response.

Flowchart of the call scheme:

enter image description here

Franck Dernoncourt
  • 4,749
  • 15
  • 48
  • 79