Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added requestTime environment variable
requestTime records the time the request was received by the server.
  • Loading branch information
mjackson committed Sep 20, 2011
1 parent 8647fb1 commit 75344f8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGES
@@ -1,3 +1,7 @@
= HEAD

* Added requestTime environment variable.

= 0.5.3 / 2011-09-20

* Removed multipart.File#unlink
Expand Down
2 changes: 2 additions & 0 deletions SPEC
Expand Up @@ -21,6 +21,7 @@ the following:
required.
- requestMethod The request method (e.g. "GET" or "POST"). This cannot
ever be an empty string, and is always required.
- requestTime A Date that indicates the time the request was received.
- serverName, When combined with scriptName and pathInfo these
serverPort variables may be used to reconstruct the original
request URL. Note, however, that if httpHost is present,
Expand Down Expand Up @@ -63,6 +64,7 @@ There are the following restrictions:

- protocol must be either "http:" or "https:"
- requestMethod must be a valid HTTP verb as an uppercase String
- requestTime must be a Date
- scriptName and pathInfo, if not empty, should start with a "/"
- scriptName should never be "/" but instead be empty
- pathInfo should be "/" if scriptName is empty
Expand Down
3 changes: 3 additions & 0 deletions lib/index.js
Expand Up @@ -104,6 +104,7 @@ function createServer(app, opts) {
protocol: protocol,
protocolVersion: req.httpVersion,
requestMethod: req.method,
requestTime: new Date,
serverName: serverName,
serverPort: serverPort,
pathInfo: uri.pathname,
Expand Down Expand Up @@ -141,6 +142,7 @@ function createServer(app, opts) {
* - protocol The protocol being used (i.e. "http:" or "https:")
* - protocolVersion The protocol version
* - requestMethod The request method (e.g. "GET" or "POST")
* - requestTime A Date that indicates the time the request was received
* - serverName The host name of the server
* - serverPort The port number the request was made on
* - scriptName The virtual location of the application
Expand All @@ -162,6 +164,7 @@ function makeEnv(opts) {
env.protocol = opts.protocol || "http:";
env.protocolVersion = opts.protocolVersion || "1.0";
env.requestMethod = (opts.requestMethod || "GET").toUpperCase();
env.requestTime = opts.requestTime || new Date;
env.serverName = opts.serverName || "";
env.serverPort = opts.serverPort || (env.protocol == "https:" ? "443" : "80");
env.scriptName = opts.scriptName || "";
Expand Down
5 changes: 5 additions & 0 deletions lib/lint.js
Expand Up @@ -54,6 +54,8 @@ function checkEnv(env) {
assert(typeof env[p] == "string", 'Property "' + p + '" must be a string');
});

assert("requestTime" in env, 'Environment missing required property "requestTime"');

// The environment must not contain the properties httpContentType or
// httpContentLength (use contentType and contentLength instead).
assert(typeof env.httpContentType == "undefined", 'Environment must not contain property "httpContentType", use "contentType" instead');
Expand All @@ -75,6 +77,9 @@ function checkEnv(env) {
// - requestMethod must be a valid HTTP verb as an uppercase String
assert((/^[A-Z]+$/).test(env.requestMethod), "Request method must be a valid HTTP verb");

// - requestTime must be a Date
assert(env.requestTime instanceof Date, "Request time must be a Date");

// - scriptName, if not empty, should start with a "/"
// - pathInfo should be "/" if scriptName is empty
// - scriptName should never be "/" but instead be empty
Expand Down
2 changes: 2 additions & 0 deletions test/lint_test.js
Expand Up @@ -43,6 +43,8 @@ vows.describe("lint").addBatch({
assertStringProperty(p);
});

assertRequiredProperty("requestTime");

assert.throws(function () {
var env = mock.env();
env.httpContentType = "text/plain";
Expand Down

0 comments on commit 75344f8

Please sign in to comment.