Skip to content

Commit

Permalink
Merge branch 'master' into jasmine-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan committed May 31, 2013
2 parents 2d1b814 + cb8a5b5 commit 30046b0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
47 changes: 32 additions & 15 deletions lib/bogart.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var
inherits = require('util').inherits,
EventEmitter = require('events').EventEmitter;

exports.version = [0,4,2];
exports.version = [0,4,3];

exports.util = require('./util');

Expand Down Expand Up @@ -220,6 +220,24 @@ exports.start = function(jsgiApp, options) {
return require("jsgi").start(jsgiApp, options);
};

function jsgiResponse(body, opts, defaultHeaders) {
defaultHeaders = defaultHeaders || {};

opts = opts || {};
opts.status = opts.status || 200;
opts.headers = opts.headers || {};

if (!Array.isArray(body) && !(typeof body.forEach === 'function')) {
body = [ body ];
}

return {
status: opts.status,
body: body,
headers: merge(defaultHeaders, opts.headers)
};
}

/**
* Text response. Bogart helper method to create a JSGI response.
* Returns a default JSGI response with body containing the specified text, a status of 200,
Expand All @@ -228,12 +246,13 @@ exports.start = function(jsgiApp, options) {
*
* @param {String} txt Text for the body of the response.
*/
exports.text = function(txt) {
return {
status: 200,
body: [txt],
headers: { "content-type": "text", "content-length": Buffer.byteLength(txt, 'utf-8') }
};
exports.text = function(txt, opts) {
txt = txt || '';

return jsgiResponse(txt, opts, {
'content-type': 'text',
'content-length': Buffer.byteLength(txt, 'utf-8')
});
};

/**
Expand All @@ -250,14 +269,12 @@ exports.text = function(txt) {
* @type Object
*/
exports.html = function(html, opts) {
opts = opts || {};
html = html || "";

return {
status: opts.status || 200,
body: [html],
headers: { "content-type": "text/html", "content-length": Buffer.byteLength(html, 'utf-8') }
};
html = html || '';

return jsgiResponse(html, opts, {
'content-type': 'text/html',
'content-length': Buffer.byteLength(html, 'utf-8')
});
};

/**
Expand Down
11 changes: 5 additions & 6 deletions lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ exports.gzip = exports.Gzip = function(nextApp) {
exports.methodOverride = exports.MethodOverride = function(nextApp) {
return function(request) {
if (request.body && typeof request.body == "object") {
if ((request.method == "POST") && (!request.headers["content-type"].match(/^multipart\/form-data/))) {
if ((request.method.toUpperCase() == "POST") && (!request.headers["content-type"].match(/^multipart\/form-data/))) {
var method = request.headers[HTTP_METHOD_OVERRIDE_HEADER] || request.body[METHOD_OVERRIDE_PARAM_KEY];
if (method && HTTP_METHODS[method.toUpperCase()] === true) {
request.env.original_method = request.method;
Expand Down Expand Up @@ -544,10 +544,7 @@ exports.facebook = function(config,nextApp) {
var facebook_strategy = {
authorizationURL: 'https://www.facebook.com/dialog/oauth',
tokenURL: 'https://graph.facebook.com/oauth/access_token',
resourceURL: 'https://graph.facebook.com/me',
clientId: config.clientId,
clientSecret: config.clientSecret,
host: config.host,
resourceURL: 'https://graph.facebook.com/me',
parse: function(body) {
if (body){
o = JSON.parse(body);
Expand All @@ -573,7 +570,9 @@ exports.facebook = function(config,nextApp) {
}
};

return exports.oauth2(facebook_strategy, nextApp);
var oauth2Options = _.extend(facebook_strategy, config);

return exports.oauth2(oauth2Options, nextApp);
}

exports.session = exports.Session = require("./session/session").Session;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bogart",
"description": "Fast JSGI web framework taking inspiration from Sinatra",
"version": "0.4.2",
"version": "0.4.3",
"keywords": ["bogart", "framework", "sinatra", "REST"],
"author": "Nathan Stott <nrstott@gmail.com>",
"email": "nathan.stott@whiteboard-it.com",
Expand Down

0 comments on commit 30046b0

Please sign in to comment.