Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed use of deprecated process.mixin function.

  • Loading branch information...
commit 59d82287788ddeb15c452d53075ebadbd2ea623d 1 parent f761250
@gjritter authored
Showing with 42 additions and 47 deletions.
  1. +27 −30 lib/http_state.js
  2. +15 −17 lib/nerve.js
View
57 lib/http_state.js
@@ -6,40 +6,37 @@
idgen = require('./idgen'),
sessions = {};
- process.mixin(http.IncomingMessage.prototype, {
- get_cookie: function (name) {
- var cookies = this.headers.cookie && this.headers.cookie.split(";"),
- cookie, parts;
- while ((cookie = (cookies && cookies.shift()))) {
- parts = cookie.split("=");
- if (parts[0].trim() === name) {
- return parts[1];
- }
+ http.IncomingMessage.prototype.get_cookie = function get_cookie (name) {
+ var cookies = this.headers.cookie && this.headers.cookie.split(";"),
+ cookie, parts;
+ while ((cookie = (cookies && cookies.shift()))) {
+ parts = cookie.split("=");
+ if (parts[0].trim() === name) {
+ return parts[1];
}
- },
- get_or_create_session: function (req, res, options) {
- var session_id = req.get_cookie("session_id");
- if (!session_id) {
- session_id = idgen.generate_id(22);
- res.set_cookie("session_id", session_id);
- }
- sessions[session_id] = (sessions[session_id] || {
- session: {session_id: session_id},
- touch: function () {
- this.expiration = (+ new Date()) + (options.duration || 30 * 60 * 1000);
- return this;
- }
- }).touch();
- return sessions[session_id].session;
}
- });
+ };
- process.mixin(http.ServerResponse.prototype, {
- set_cookie: function (name, value) {
- this.cookies = this.cookies || [];
- this.cookies.push(name + "=" + value + "; path=/;");
+ http.IncomingMessage.prototype.get_or_create_session = function get_or_create_session (req, res, options) {
+ var session_id = req.get_cookie("session_id");
+ if (!session_id) {
+ session_id = idgen.generate_id(22);
+ res.set_cookie("session_id", session_id);
}
- });
+ sessions[session_id] = (sessions[session_id] || {
+ session: {session_id: session_id},
+ touch: function () {
+ this.expiration = (+ new Date()) + (options.duration || 30 * 60 * 1000);
+ return this;
+ }
+ }).touch();
+ return sessions[session_id].session;
+ };
+
+ http.ServerResponse.prototype.set_cookie = function set_cookie (name, value) {
+ this.cookies = this.cookies || [];
+ this.cookies.push(name + "=" + value + "; path=/;");
+ };
function cleanup_sessions() {
for (var session_id in sessions) {
View
32 lib/nerve.js
@@ -9,25 +9,23 @@
fs = require('fs'),
mime = require('./mime');
- process.mixin(http.ServerResponse.prototype, {
- respond: function (response_data) {
- var headers = {
- 'Content-Type': 'text/html',
- 'Content-Length': (response_data.content && response_data.content.length) || response_data.length || 0
- }, name;
- if (this.cookies) {
- headers['Set-Cookie'] = this.cookies.join(', ');
- }
- for (name in response_data.headers) {
- if (response_data.headers.hasOwnProperty(name)) {
- headers[name] = response_data.headers[name];
- }
+ http.ServerResponse.prototype.respond = function respond (response_data) {
+ var headers = {
+ 'Content-Type': 'text/html',
+ 'Content-Length': (response_data.content && response_data.content.length) || response_data.length || 0
+ }, name;
+ if (this.cookies) {
+ headers['Set-Cookie'] = this.cookies.join(', ');
+ }
+ for (name in response_data.headers) {
+ if (response_data.headers.hasOwnProperty(name)) {
+ headers[name] = response_data.headers[name];
}
- this.writeHeader(response_data.status_code || 200, headers);
- this.write(response_data.content || response_data, 'binary');
- this.close();
}
- });
+ this.writeHeader(response_data.status_code || 200, headers);
+ this.write(response_data.content || response_data, 'binary');
+ this.close();
+ };
function match_request(matcher, req) {
if (typeof matcher === 'string') {
Please sign in to comment.
Something went wrong with that request. Please try again.