Content-Length compared to actual size before caching

If my upstream goes away I get an error

upstream prematurely closed connection while reading response header
from upstream


recv() failed (104: Connection reset by peer) while reading response
header from upstream

unfortunately, this still gives me a 200 code and this return is entered
incomplete into my memcache. Is there some way to get the size of the
current request from proxy_pass so I can compare it to the
Content_Length and discard it if it’s mismatched?

Ideally the system wouldn’t tag incomplete responses as 200 OK, so they
wouldn’t end up as short returns in my memcache for their cache

Posted at Nginx Forum: