node.js - "Can't set headers after they are send" even though the code isn't doing it -


i'm using express 2.5.8 (not want to), , node 0.8.15 (again, i'd love upgrade).

here's piece of code:

unless apikey   res.writehead 400, { "content-type": "text/plain" }   res.end "api key must provided api access."   return 

edit: broke writehead statuscode , setheader, , worked. know why?

working code:

unless apikey   res.statuscode = 400   res.setheader "content-type", "text/plain"   res.end "api key must provided api access."   return 

end edit

i know being executed, , return works, because when try

unless apikey   res.end('wtf')   return   res.writehead 400, { "content-type": "text/plain" }   res.end "api key must provided api access."   return 

i 'wtf' without server crashing.

when try

unless apikey   res.writehead 400, { "content-type": "text/plain" }   return   res.end "api key must provided api access."   return 

i wait forever , timeout, writehead part works, , when try

unless apikey   # res.writehead 400, { "content-type": "text/plain" }   res.end "api key must provided api access."   return 

i right response.

so why can't original code work???


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -