Browse files

Initial commit.

  • Loading branch information...
0 parents commit a7626710b00d67bec0614de138718f884ffbd5f3 @jaredhanson committed Apr 6, 2012
Showing with 261 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +8 −0 .npmignore
  3. +20 −0 LICENSE
  4. +19 −0 Makefile
  5. +66 −0 README.md
  6. +4 −0 lib/index.js
  7. +18 −0 lib/poweredBy.js
  8. +28 −0 package.json
  9. +14 −0 test/index-test.js
  10. +82 −0 test/poweredBy-test.js
2 .gitignore
@@ -0,0 +1,2 @@
+.DS_Store
+node_modules
8 .npmignore
@@ -0,0 +1,8 @@
+*.md
+.DS_Store
+.git*
+Makefile
+docs/
+examples/
+support/
+test/
20 LICENSE
@@ -0,0 +1,20 @@
+(The MIT License)
+
+Copyright (c) 2011 Jared Hanson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 Makefile
@@ -0,0 +1,19 @@
+NODE = node
+TEST = ./node_modules/.bin/vows
+TESTS ?= test/*-test.js
+
+test:
+ @NODE_ENV=test NODE_PATH=lib $(TEST) $(TEST_FLAGS) $(TESTS)
+
+docs: docs/api.html
+
+docs/api.html: lib/connect-powered-by/*.js
+ dox \
+ --title connect-powered-by \
+ --desc "X-Powered-By header middleware for Connect" \
+ $(shell find lib/connect-powered-by/* -type f) > $@
+
+docclean:
+ rm -f docs/*.{1,html}
+
+.PHONY: test docs docclean
66 README.md
@@ -0,0 +1,66 @@
+# connect-powered-by
+
+This middleware sets or removes the `X-Powered-By` header on HTTP responses.
+`X-Powered-By` is a de facto standard that specifies the technology supporting
+a web application. This header is used by services that gather metrics about
+the web, including [Alexa](http://www.alexa.com/) and [Netcraft](http://www.netcraft.com/).
+
+## Installation
+
+ $ npm install connect-powered-by
+
+## Usage
+
+To set the `X-Powered-By` header on responses, simply use `poweredBy` middleware
+with a technology string.
+
+ var poweredBy = require('connect-powered-by');
+
+ app.configure(function() {
+ app.use(poweredBy('Locomotive'));
+ });
+
+To remove the `X-Powered-By` header, use `poweredBy` middleware and specify
+`null` as the technology string. This is useful if you want to remove this
+header when it is set unconditionally by your application framework, for example
+[Express](http://expressjs.com/).
+
+ var poweredBy = require('connect-powered-by');
+
+ app.configure(function() {
+ app.use(poweredBy(null));
+ });
+
+## Tests
+
+ $ npm install --dev
+ $ make test
+
+[![Build Status](https://secure.travis-ci.org/jaredhanson/connect-powered-by.png)](http://travis-ci.org/jaredhanson/connect-powered-by)
+
+## Credits
+
+ - [Jared Hanson](http://github.com/jaredhanson)
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2011 Jared Hanson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4 lib/index.js
@@ -0,0 +1,4 @@
+/**
+ * Expose middleware.
+ */
+exports = module.exports = require('./poweredBy');
18 lib/poweredBy.js
@@ -0,0 +1,18 @@
+/**
+ * Set `X-Powered-By` header on response.
+ *
+ * @return {Function}
+ * @api public
+ */
+module.exports = function poweredBy(tech) {
+ tech = tech || null;
+
+ return function(req, res, next) {
+ if (tech) {
+ res.setHeader('X-Powered-By', tech);
+ } else {
+ res.removeHeader('X-Powered-By');
+ }
+ next();
+ }
+}
28 package.json
@@ -0,0 +1,28 @@
+{
+ "name": "connect-powered-by",
+ "version": "0.1.0",
+ "description": "X-Powered-By header middleware for Connect.",
+ "author": { "name": "Jared Hanson", "email": "jaredhanson@gmail.com", "url": "http://www.jaredhanson.net/" },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/jaredhanson/connect-powered-by.git"
+ },
+ "bugs": {
+ "url": "http://github.com/jaredhanson/connect-powered-by/issues"
+ },
+ "main": "./lib",
+ "dependencies": {
+ },
+ "devDependencies": {
+ "vows": "0.6.x"
+ },
+ "scripts": {
+ "test": "NODE_PATH=lib node_modules/.bin/vows test/*-test.js"
+ },
+ "engines": { "node": ">= 0.4.0" },
+ "licenses": [ {
+ "type": "MIT",
+ "url": "http://www.opensource.org/licenses/MIT"
+ } ],
+ "keywords": ["connect", "express", "header", "x-powered-by"]
+}
14 test/index-test.js
@@ -0,0 +1,14 @@
+var vows = require('vows');
+var assert = require('assert');
+var poweredBy = require('index');
+
+
+vows.describe('connect-powered-by').addBatch({
+
+ 'module': {
+ 'should export middleware': function () {
+ assert.isFunction(poweredBy);
+ },
+ },
+
+}).export(module);
82 test/poweredBy-test.js
@@ -0,0 +1,82 @@
+var vows = require('vows');
+var assert = require('assert');
+var util = require('util');
+var poweredBy = require('poweredBy');
+
+
+function MockRequest() {
+}
+
+function MockResponse() {
+ this.headers = {};
+}
+
+MockResponse.prototype.setHeader = function(name, value) {
+ this.headers[name] = value;
+}
+
+MockResponse.prototype.removeHeader = function(name, value) {
+ delete this.headers[name];
+}
+
+
+vows.describe('poweredBy').addBatch({
+
+ 'middleware with a technology string': {
+ topic: function() {
+ return poweredBy('Foo');
+ },
+
+ 'when handling a request': {
+ topic: function(poweredBy) {
+ var self = this;
+ var req = new MockRequest();
+ var res = new MockResponse();
+
+ function next(err) {
+ self.callback(err, req, res);
+ }
+ process.nextTick(function () {
+ poweredBy(req, res, next)
+ });
+ },
+
+ 'should not error' : function(err, req, res) {
+ assert.isNull(err);
+ },
+ 'should set header' : function(err, req, res) {
+ assert.equal(res.headers['X-Powered-By'], 'Foo');
+ },
+ },
+ },
+
+ 'middleware without a technology string': {
+ topic: function() {
+ return poweredBy(null);
+ },
+
+ 'when handling a request': {
+ topic: function(poweredBy) {
+ var self = this;
+ var req = new MockRequest();
+ var res = new MockResponse();
+ res.headers['X-Powered-By'] = 'Foo';
+
+ function next(err) {
+ self.callback(err, req, res);
+ }
+ process.nextTick(function () {
+ poweredBy(req, res, next)
+ });
+ },
+
+ 'should not error' : function(err, req, res) {
+ assert.isNull(err);
+ },
+ 'should remove header' : function(err, req, res) {
+ assert.isUndefined(res.headers['X-Powered-By']);
+ },
+ },
+ },
+
+}).export(module);

0 comments on commit a762671

Please sign in to comment.