Where are queries to the REST API handled in the source code?

I am trying to optimize data transfers from the REST API to my conky instance. Internally, conky is using libcurl to perform the operations. I'm doing periodic queries at about 1Hz per endpoint (/api/job, /api/printer, etc.). Curl reports that it is trying to reuse connections, but every time the connection seems to be dead and so it makes a new one. Ideally, connections would not be recreated.

I don't see anything on the conky/libcurl side that would explain this. So how does OctoPrint handle the REST API queries? I can't seem to find the right place to look in the source to get my head around it.

OctoPrint uses a combination of Tornado and Flask for the actual HTTP communication, and then the API responses are handled in src/octoprint/server/api. There's some wrappers in src/octoprint/server/util for adding some stuff to the requests/responses, but most of it is handled in Flask.

A typical request would go Tornado -> Flask -> OctoPrint's API, and then back out again. Not the most ideal combination, but it's hard to change once it is done...

I don't know enough about either (or HTTP) to say who's problem it might be though.