Mercurial > hg > rlgwebd
comparison rlgwebd.js @ 34:57f4b36ef06b
rlgwebd.js: handle HTTP HEAD properly.
Prevent a message body from being sent in response to HTTP HEAD.
author | John "Elwin" Edwards <elwin@sdf.org> |
---|---|
date | Tue, 05 Jun 2012 20:13:47 -0700 |
parents | c75fc4b1d13d |
children | a0387f112bcf |
comparison
equal
deleted
inserted
replaced
33:23a495e81725 | 34:57f4b36ef06b |
---|---|
516 res.writeHead(500, {}); | 516 res.writeHead(500, {}); |
517 res.end(); | 517 res.end(); |
518 } | 518 } |
519 else { | 519 else { |
520 res.writeHead(200, resheaders); | 520 res.writeHead(200, resheaders); |
521 res.write(data); | 521 if (req.method != 'HEAD') |
522 res.write(data); | |
522 res.end(); | 523 res.end(); |
523 } | 524 } |
524 }); | 525 }); |
525 } | 526 } |
526 else { | 527 else { |
527 res.writeHead(404, resheaders); | 528 res.writeHead(404, resheaders); |
528 res.write("<html><head><title>" + nname + "</title></head>\n<body><h1>" + nname + " Not Found</h1></body></html>\n"); | 529 if (req.method != 'HEAD') { |
530 res.write("<html><head><title>" + nname + "</title></head>\n<body><h1>" | |
531 + nname + " Not Found</h1></body></html>\n"); | |
532 } | |
529 res.end(); | 533 res.end(); |
530 } | 534 } |
531 }); | 535 }); |
532 return; | 536 return; |
533 } | 537 } |
571 gamedesc["g"] = sessions[sessid].game.name; | 575 gamedesc["g"] = sessions[sessid].game.name; |
572 reply["g"].push(gamedesc); | 576 reply["g"].push(gamedesc); |
573 } | 577 } |
574 } | 578 } |
575 res.writeHead(200, { "Content-Type": "application/json" }); | 579 res.writeHead(200, { "Content-Type": "application/json" }); |
576 res.write(JSON.stringify(reply)); | 580 if (req.method != 'HEAD') |
581 res.write(JSON.stringify(reply)); | |
577 res.end(); | 582 res.end(); |
578 } | 583 } |
579 | 584 |
580 var errorcodes = [ "Generic Error", "Not logged in", "Invalid data", | 585 var errorcodes = [ "Generic Error", "Not logged in", "Invalid data", |
581 "Login failed", "Already playing", "Game launch failed", | 586 "Login failed", "Already playing", "Game launch failed", |
607 } | 612 } |
608 req.on('data', moredata); | 613 req.on('data', moredata); |
609 | 614 |
610 /* This will send the response once the whole request is here. */ | 615 /* This will send the response once the whole request is here. */ |
611 function respond() { | 616 function respond() { |
612 //formdata = getFormValues(reqbody); | |
613 formdata = getMsg(reqbody); | 617 formdata = getMsg(reqbody); |
614 var target = url.parse(req.url).pathname; | 618 var target = url.parse(req.url).pathname; |
615 var cterm = findTermSession(formdata); | 619 var cterm = findTermSession(formdata); |
616 /* First figure out if the client is POSTing to a command interface. */ | 620 /* First figure out if the client is POSTing to a command interface. */ |
617 if (req.method == 'POST') { | 621 if (req.method == 'POST') { |
648 res.end(); | 652 res.end(); |
649 } | 653 } |
650 } | 654 } |
651 else if (req.method == 'GET' || req.method == 'HEAD') { | 655 else if (req.method == 'GET' || req.method == 'HEAD') { |
652 if (target == '/feed') { | 656 if (target == '/feed') { |
657 if (req.method == 'HEAD') { | |
658 res.writeHead(200, {"Content-Type": "application/json"}); | |
659 res.end(); | |
660 return; | |
661 } | |
653 if (!cterm) { | 662 if (!cterm) { |
654 sendError(res, 1, null); | 663 sendError(res, 1, null); |
655 return; | 664 return; |
656 } | 665 } |
657 readFeed(res, cterm); | 666 readFeed(res, cterm); |