Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Small bug fixes

  • Loading branch information...
commit 42426c8076537c1ee416ec39223340f41df02d1b 1 parent 3a672b9
@brokenseal authored
View
8 broke/core/handlers/base.js
@@ -67,7 +67,7 @@
utils.forEach(settings.MIDDLEWARE_CLASSES, function(){
var
middleware
- ,middlewareModule
+ ,middlewareModule
,middlewareInstance
;
@@ -79,8 +79,8 @@
if(!middleware) {
throw new exceptions.ImproperlyConfigured("%s isn't a middleware module" % this);
- }
-
+ }
+
middlewareInstance= middleware();
if(middlewareInstance.processRequest !== undefined) {
@@ -96,7 +96,7 @@
// We only assign to this when initialization is complete as it is used
// as a flag for initialization being complete.
_this.requestMiddleware= requestMiddleware;
- });
+ });
},
getResponse: function(request){
var
View
4 broke/core/handlers/node.js
@@ -17,10 +17,6 @@
;
this._super(nodeRequest);
- utils.forEach(nodeRequest.connection.server, function(key){
- require('sys').puts('name: ' + key + ' :: ' + this);
- });
-
this.initMeta(nodeRequest);
this.method= nodeRequest.method;
View
145 broke/middleware/common.js
@@ -4,10 +4,10 @@
,GenericError= require('broke/core/exceptions').GenericError
,gettext= require('broke/utils/translation').gettext.gettext
,http= require('broke/http/http')
- ,exceptions= require('broke/core/exceptions')
- //,urlquote= require('broke/utils/http').urlquote
- //,mailManagers= request('broke/core/mail').mailManagers
- ,md5Constructor= require('dependencies/md5').hex_md5
+ ,exceptions= require('broke/core/exceptions')
+ //,urlquote= require('broke/utils/http').urlquote
+ //,mailManagers= request('broke/core/mail').mailManagers
+ ,md5Constructor= require('dependencies/md5').hex_md5
,utils= require('broke/core/utils')
,Class= require('dependencies/pyjammin/class').Class
@@ -68,11 +68,10 @@
// Append a slash if APPEND_SLASH is set and the URL doesn't have a
// trailing slash and there is no pattern for the current path
if(settings.APPEND_SLASH && !utils.endsWith(oldUrl[0]), '/'){
- urlConf= getattr(request, 'urlConf', null);
+ urlConf= utils.getattr(request, 'urlConf', null);
if(!_isValidPath(request.pathInfo, urlConf) && _isValidPath(utils.interpolate('%s/', request.pathInfo), urlConf)){
newUrl[1]= newUrl[1] + '/';
- require('sys').puts('changing newUrl to ' + newUrl);
if(settings.DEBUG && request.method == 'POST'){
throw exceptions.RuntimeError(utils.interpolate("You called this URL via POST, but the URL doesn't end "+
@@ -83,77 +82,75 @@
"settings.", newUrl[0], newUrl[1]));
}
}
- }
+ }
- require('sys').puts('newUrl: ' + newUrl);
- require('sys').puts('oldUrl: ' + oldUrl);
if(utils.eq(newUrl, oldUrl)){
return;
- }
-
- if(newUrl[0]) {
- newUrl = utils.interpolate("%s://%s%s", [ (request.isSecure()?'https':'http'), newUrl[0], urlquote(newUrl[1]) ]);
- } else {
- newUrl= urlquote(newUrl[1]);
- }
-
- if(utils.len(request.GET)) {
- newUrl+= '?' + request.META.QUERY_STRING;
- }
-
- return http.HttpResponsePermanentRedirect(newurl);
- }
- ,processResponse: function(request, response){
- var
- domain
- ,referer
- ,isInternal
- ,path
- ,ua
- ,ip
- ,etag
- ,cookies
- ;
- // Check for a flat page (for 404s) and calculate the Etag, if needed."
- if(response.statusCode == 404) {
- if(settings.SEND_BROKEN_LINK_EMAILS) {
- // If the referrer was from an internal link or a non-search-engine site,
- // send a note to the managers.
- domain= request.getHost();
- referer= request.META.HTTP_REFERER || null;
- isInternal= _isInternalRequest(domain, referer);
- path= request.getFullPath();
-
- if(referer && !_isIgnorable404(path) && referer[(isInternal || '?')] === undefined) {
- ua= request.META.HTT_USER_AGENT || '<none>';
- ip= request.META.REMOTE_ADDR || '<none>';
- mailManagers(
- utils.interpolate("Broken %slink on %s", [(isInternal ? 'INTERNAL ' : ''), domain ]),
- utils.interpolate("Referrer: %s\nRequested URL: %s\nUser agent: %s\nIP address: %s\n", [ referer, request.getFullPath(), ua, ip ])
- );
- }
-
- return response;
- }
- }
- // Use ETags, if requested.
- if(settings.USE_ETAGS) {
- if(response.hasHeader('ETag')) {
- etag= response.getHeader('ETag');
- } else {
- utils.interpolate('"%s"', [ md5Contructor(response.content) ]);
- }
-
- if(response.statusCode >= 200 && response.statusCode < 300 && request.META.HTTP_IF_NONE_MATCH == etag) {
- cookies= response.cookies;
- response= http.HttpResponseNotModified();
- response.cookies= cookies;
- } else {
- response.setHeader('ETag', etag);
- }
- }
-
- return response
+ }
+
+ if(newUrl[0]) {
+ newUrl = utils.interpolate("%s://%s%s", [ (request.isSecure()?'https':'http'), newUrl[0], urlquote(newUrl[1]) ]);
+ } else {
+ newUrl= urlquote(newUrl[1]);
+ }
+
+ if(utils.len(request.GET)) {
+ newUrl+= '?' + request.META.QUERY_STRING;
+ }
+
+ return http.HttpResponsePermanentRedirect(newurl);
+ }
+ ,processResponse: function(request, response){
+ var
+ domain
+ ,referer
+ ,isInternal
+ ,path
+ ,ua
+ ,ip
+ ,etag
+ ,cookies
+ ;
+ // Check for a flat page (for 404s) and calculate the Etag, if needed."
+ if(response.statusCode == 404) {
+ if(settings.SEND_BROKEN_LINK_EMAILS) {
+ // If the referrer was from an internal link or a non-search-engine site,
+ // send a note to the managers.
+ domain= request.getHost();
+ referer= request.META.HTTP_REFERER || null;
+ isInternal= _isInternalRequest(domain, referer);
+ path= request.getFullPath();
+
+ if(referer && !_isIgnorable404(path) && referer[(isInternal || '?')] === undefined) {
+ ua= request.META.HTT_USER_AGENT || '<none>';
+ ip= request.META.REMOTE_ADDR || '<none>';
+ mailManagers(
+ utils.interpolate("Broken %slink on %s", [(isInternal ? 'INTERNAL ' : ''), domain ]),
+ utils.interpolate("Referrer: %s\nRequested URL: %s\nUser agent: %s\nIP address: %s\n", [ referer, request.getFullPath(), ua, ip ])
+ );
+ }
+
+ return response;
+ }
+ }
+ // Use ETags, if requested.
+ if(settings.USE_ETAGS) {
+ if(response.hasHeader('ETag')) {
+ etag= response.getHeader('ETag');
+ } else {
+ utils.interpolate('"%s"', [ md5Contructor(response.content) ]);
+ }
+
+ if(response.statusCode >= 200 && response.statusCode < 300 && request.META.HTTP_IF_NONE_MATCH == etag) {
+ cookies= response.cookies;
+ response= http.HttpResponseNotModified();
+ response.cookies= cookies;
+ } else {
+ response.setHeader('ETag', etag);
+ }
+ }
+
+ return response
}
});
View
2  examples/node/settings.js
@@ -24,7 +24,7 @@
,PATHS: ['/media/broke']
}
,MIDDLEWARE_CLASSES: [
- //'broke.middleware.common.CommonMiddleware'
+ 'broke.middleware.common.CommonMiddleware'
]
,DEBUG_PROPAGATE_EXCEPTIONS: true
,ADDRESS_BAR: {
Please sign in to comment.
Something went wrong with that request. Please try again.