[Twisted-Python] Returning a response for an HTTP query that requires upstream IO.
Go Luhng
goluhng at gmail.com
Wed Apr 22 10:13:06 MDT 2020
I'd like to develop a server that maintains a TCP connection to an
upstream server, and listens for HTTP requests. Upon receiving an HTTP
request, the server will send a message upstream, wait for a response,
and return an HTTP response to the client which made the request.
My background is in writing blocking web services, so my natural
instinct is to write a `get_result_for(query)` method that will take a
`query` string and return a result from the upstream TCP connection.
I'm not sure whether writing such a method is possible in Twisted,
since it's basically a blocking method. I suspect I may have to use
Continuation-Passing Style instead, that is: provide a callback to
`get_result_for(query, callback)`.
Even if that's the case, how do I return an HTTP response to the HTTP
client once the query result is available?
More information about the Twisted-Python
mailing list