node-http-server – Diff between revs 26 and 27

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 26 Rev 27
Line 21... Line 21...
21 // Serves files. 21 // Serves files.
22 function files(config, request, response, requestPath, callback) { 22 function files(config, request, response, requestPath, callback) {
23 // Check if the file is accessible. 23 // Check if the file is accessible.
24 fs.access(requestPath, fs.constants.R_OK, (error) => { 24 fs.access(requestPath, fs.constants.R_OK, (error) => {
25 if (error) { 25 if (error) {
-   26 process.nextTick(() => {
-   27 const requestAddress = request.socket.address();
-   28 callback('Client: ' +
-   29 requestAddress.address + ':' +
-   30 requestAddress.port +
-   31 ' requesting inaccessible path: ' +
-   32 requestPath,
-   33 module.exports.error.level.WARN
-   34 );
-   35 });
26 response.statusCode = 403; 36 response.statusCode = 403;
27 response.end(); 37 response.end();
28 return; 38 return;
29 } 39 }
Line 55... Line 65...
55 .some((directory) => 65 .some((directory) =>
56 directory.toUpperCase() === requestURL.toUpperCase())) { 66 directory.toUpperCase() === requestURL.toUpperCase())) {
57 fs.readdir(requestPath, (error, paths) => { 67 fs.readdir(requestPath, (error, paths) => {
58 if (error) { 68 if (error) {
59 process.nextTick(() => { 69 process.nextTick(() => {
-   70 const requestAddress = request.socket.address();
-   71 callback('Client: ' +
-   72 requestAddress.address + ':' +
-   73 requestAddress.port +
60 callback('Could not list directory: ' + 74 ' could not access directory: ' +
61 requestPath, 75 requestPath,
62 module.exports.error.level.ERROR 76 module.exports.error.level.WARN
63 ); 77 );
64 }); 78 });
65 response.statusCode = 500; 79 response.statusCode = 500;
66 response.end(); 80 response.end();
67 return; 81 return;
68 } 82 }
69 process.nextTick(() => { 83 process.nextTick(() => {
-   84 const requestAddress = request.socket.address();
-   85 callback('Client: ' +
-   86 requestAddress.address + ':' +
-   87 requestAddress.port +
70 callback('Directory listing requested for: ' + 88 ' accessed directory listing: ' +
71 requestPath, 89 requestPath,
72 module.exports.error.level.INFO 90 module.exports.error.level.WARN
73 ); 91 );
74 }); 92 });
75 response.statusCode = 200; 93 response.statusCode = 200;
76 response.write(JSON.stringify(paths)); 94 response.write(JSON.stringify(paths));
77 response.end(); 95 response.end();
78 }); 96 });
Line 79... Line 97...
79   97  
80 return; 98 return;
-   99 }
-   100 process.nextTick(() => {
-   101 const requestAddress = request.socket.address();
-   102 callback('Client: ' +
-   103 requestAddress.address + ':' +
-   104 requestAddress.port +
-   105 ' accessing forbiden index: ' +
-   106 requestURL,
81 } 107 module.exports.error.level.WARN
-   108 );
82   109 });
83 // Could not access directory index file and directory listing not allowed. 110 // Could not access directory index file and directory listing not allowed.
84 response.statusCode = 404; 111 response.statusCode = 404;
85 response.end(); 112 response.end();
Line 89... Line 116...
89   116  
90 // Serve the document index. 117 // Serve the document index.
91 fs.access(root, fs.constants.R_OK, (error) => { 118 fs.access(root, fs.constants.R_OK, (error) => {
92 if (error) { 119 if (error) {
-   120 process.nextTick(() => {
-   121 const requestAddress = request.socket.address();
-   122 callback('Client: ' +
-   123 requestAddress.address + ':' +
93 process.nextTick(() => { 124 requestAddress.port +
94 callback('The server was unable to access the filesystem path: ' + 125 ' unable to access path: ' +
95 requestPath, 126 requestPath,
96 module.exports.error.level.WARN 127 module.exports.error.level.WARN
97 ); 128 );
98 }); 129 });
Line 141... Line 172...
141   172  
142 // If the file matches the reject list or is not in the accept list, 173 // If the file matches the reject list or is not in the accept list,
143 // then there is no file to serve. 174 // then there is no file to serve.
144 if (config.site.reject.some((expression) => expression.test(file)) || 175 if (config.site.reject.some((expression) => expression.test(file)) ||
-   176 !config.site.accept.some((expression) => expression.test(file))) {
-   177 process.nextTick(() => {
-   178 const requestAddress = request.socket.address();
-   179 callback('Client: ' +
-   180 requestAddress.address + ':' +
-   181 requestAddress.port +
-   182 ' requested disallowed file: ' +
-   183 file,
-   184 module.exports.error.level.WARN
-   185 );
145 !config.site.accept.some((expression) => expression.test(file))) { 186 });
146 response.statusCode = 404; 187 response.statusCode = 404;
147 response.end(); 188 response.end();
148 return; 189 return;
Line 166... Line 207...
166 process.nextTick(() => { 207 process.nextTick(() => {
167 const requestAddress = request.socket.address(); 208 const requestAddress = request.socket.address();
168 const requestURL = url.parse( 209 const requestURL = url.parse(
169 request.url, true 210 request.url, true
170 ); 211 );
-   212
-   213 // Perform URL re-writes.
-   214 Object.keys(config.site.rewrite).forEach((key, index) => {
-   215 if(config.site.rewrite[key].test(requestURL.path)) {
-   216 const originalPath = requestURL.path;
-   217 requestURL.path = requestURL
-   218 .path
-   219 .replace(
-   220 config.site.rewrite[key], key
-   221 );
-   222 requestURL.pathname = url.parse(
-   223 requestURL
-   224 .pathname
-   225 .replace(
-   226 config.site.rewrite[key], key
-   227 ),
-   228 true
-   229 )
-   230 .pathname;
-   231 callback('Rewrite path: ' +
-   232 originalPath +
-   233 ' to: ' +
-   234 requestURL.path,
-   235 module.exports.error.level.INFO
-   236 );
-   237 }
-   238 });
Line 171... Line 239...
171   239  
172 const trimmedPath = requestURL 240 const trimmedPath = requestURL
173 .pathname 241 .pathname
174 .split('/') 242 .split('/')