Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

statusCode and HEAD requests #4

Open
wants to merge 1 commit into from

1 participant

Mark Bogdanoff
Mark Bogdanoff
bog commented

I've modified quip to handle two scenarios it wasn't handling as well as it could:

  1. Since quip didn't set res.statusCode, other middleware such as connect's logger couldn't read the statusCode and therefore reported improper status codes.

  2. Since quip provides a response body for redirections, it needs to prevent writing to the body when dealing with a HEAD request. I've now corrected the middleware to not write if the request is a HEAD request.

Mark Bogdanoff bog set res.statusCode so other middleware can get the statusCode properly.
Proxying res.write to prevent writing on HEAD requests in the case of using redirection
854e84e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 5, 2011
  1. Mark Bogdanoff

    set res.statusCode so other middleware can get the statusCode properly.

    bog authored
    Proxying res.write to prevent writing on HEAD requests in the case of using redirection
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 1 deletion.
  1. +9 −1 lib/quip.js
10 lib/quip.js
View
@@ -2,6 +2,13 @@
var exports = module.exports = function(){
return function(req, res, next){
exports.update(res);
+ // proxy write to prevent writing on HEAD requests
+ var write = res.write;
+ res.write = function(chunk, encoding) {
+ res.write = write;
+ if (req.method == 'HEAD') return true;
+ return res.write(chunk, encoding);
+ };
next();
};
};
@@ -46,7 +53,8 @@ exports.update = function(res){
///// exported methods /////
res.status = function(code){
- res._quip_status = code;
+ // set statusCode on res so other middleware (such as logger) can access it
+ res._quip_status = res.statusCode = code;
return res;
};
res.headers = function(headers){
Something went wrong with that request. Please try again.