Check if a response has been sent?

Is there any way to test if a response has been sent already?

For context, I’m finding that some non-existing url queries end up just hanging, so I created

# Timeout Handling
((req,res) ->
    setTimeout(
        ->
            # Prepare
            requestInfo = {url: req.headers.host+req.url, ip: req.connection.remoteAddress, status: res.statusCode}

            # Attempt Timeout
            try
                res.send(408) # Request Timeout
                console.log 'request timeout:', requestInfo
                #res.end() # End Response
                #console.log 'end response:', requestInfo
            catch err
                # Chances are the request sent fine
                false
        30*1000
    )                       
)(req,res)

but even with the catch it restarts the entire process

Author: Fantashit

1 thought on “Check if a response has been sent?

  1. typically you just keep next()ing and connect 404s the response if you dont intervene, so I dont think this is the right way to go about it. However I believe node only sets some internal flags such as res._headerSent (or something like, can’t remember)

Comments are closed.