-
I attempted to use YARP for HTTP 202 mechanism. To avoid waiting for backend API long-running response. Instead of modifying the backend API directly (actually, it is not modifiable). It is Async Request-Reply pattern in Microsoft docs mentioned. Wounder how should I call IHttpForwarder.SendAsync in another thread correctly. And receive HTTP response for next time client fetching? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
That's an interesting challenge, I'm not sure if YARP is your best option here. YARP copies the entire request to the destination, waits for the response, and copies the entire response back to the client. For this flow you'd need to copy the entire request to the destination, return a 202 with a status URI, capture the eventual response in local storage, and then serve it from the status endpoint. The simplest version of this would copy the request headers to a new fake DefaultHttpContext, buffer the request body and assign it to the fake context, return the 202, and then call IHttpForwarder using the fake context. Correlating the response with the status URI then becomes a matter of bookkeeping. |
Beta Was this translation helpful? Give feedback.
That's an interesting challenge, I'm not sure if YARP is your best option here. YARP copies the entire request to the destination, waits for the response, and copies the entire response back to the client.
For this flow you'd need to copy the entire request to the destination, return a 202 with a status URI, capture the eventual response in local storage, and then serve it from the status endpoint.
The simplest version of this would copy the request headers to a new fake DefaultHttpContext, buffer the request body and assign it to the fake context, return the 202, and then call IHttpForwarder using the fake context. Correlating the response with the status URI then becomes a matter of boo…