Created
January 31, 2012 23:32
-
-
Save craigyk/1713802 to your computer and use it in GitHub Desktop.
Cancel request transfer, send response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
express = require 'express' | |
app = express.createServer() | |
app.put '/uploads/:fileid', (request,response) -> | |
isvalid = false # ...code to determine validity of file being sent in the ServerRequest | |
if isvalid | |
# continue handling the upload | |
else | |
# the following two options are both unreliable | |
response.connection.allowHalfOpen = false | |
response.send 500, | |
'Access-Control-Allow-Origin' : '*' | |
# OR -------------------------------------------- | |
response.on 'finish', -> request.connection.destroy() | |
response.send 500, | |
'Access-Control-Allow-Origin' : '*' | |
app.listen(8888) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I'm trying to cancel an incoming ServerRequest and send back an appropriate ServerResponse. I'm using the express framework, and coffeescript. The code below does not work reliably, my guess is that the response is not being sent before the socket is closed, or the socket isn't closing on the response ending, even though allowHalfOpen is set to false. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment