Skip to content

Instantly share code, notes, and snippets.

@craigyk
Created January 31, 2012 23:32
Show Gist options
  • Save craigyk/1713802 to your computer and use it in GitHub Desktop.
Save craigyk/1713802 to your computer and use it in GitHub Desktop.
Cancel request transfer, send response
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)
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