Permalink
Browse files

view

  • Loading branch information...
1 parent 32a6cee commit 1bee78fbdfa7880c1d5b9069b8e348a9d2d7df39 @vovazolotoy vovazolotoy committed Jun 5, 2012
Showing with 137 additions and 49 deletions.
  1. +4 −2 application/bootstrap.js
  2. +82 −0 application/logs/2011/11/05.log
  3. +2 −2 application/views/hello.tpl
  4. +49 −45 system/prototypes/johana/request.js
View
6 application/bootstrap.js
@@ -43,8 +43,10 @@ Johana.conf.attach(new ConfigFile());
Johana.onRequest = function(req, res) {
- Request.factory(req.url, req);
- Johana.log.add(Log.ERROR, 'vova');
+ var r = Request.factory(true, req);
+
+// Johana.log.add(Log.ERROR, 'vova');
+ console.log(r);
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(View.factory('hello').render());
View
82 application/logs/2011/11/05.log
@@ -0,0 +1,82 @@
+
+Mon Dec 05 2011 16:21:05 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:21:05 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:21:06 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:21:06 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:21:07 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:21:07 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:21:07 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:21:07 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:22:07 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:22:07 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:22:08 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:22:08 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:22:08 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:22:08 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:22:19 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:22:20 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:22:20 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:22:20 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:22:20 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:22:20 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:22:20 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:22:20 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:34:12 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:34:12 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:35:17 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:35:17 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:40:22 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:40:22 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:40:28 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:40:48 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:41:44 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:41:44 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:41:45 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:41:45 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:41:50 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:41:51 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:41:51 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:41:58 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:41:58 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:42:10 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:42:10 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:42:11 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:42:11 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:42:11 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:42:11 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:42:13 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:42:16 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:42:39 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:42:39 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:42:41 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:42:44 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:42:54 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:42:54 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:42:58 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:49:15 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:49:23 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:49:28 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:49:29 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:51:06 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:52:13 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:52:36 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:52:37 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:52:47 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:55:34 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:55:34 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:55:59 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:55:59 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:58:39 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:58:39 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:58:40 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:58:40 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:58:40 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 16:58:40 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 17:00:58 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 17:00:58 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 17:03:57 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 17:03:57 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 17:03:58 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 17:03:58 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 17:03:58 GMT+0200 (EET) --- ERROR: vova
+Mon Dec 05 2011 17:03:59 GMT+0200 (EET) --- ERROR: vova
View
4 application/views/hello.tpl
@@ -1,7 +1,7 @@
<h1>Hello</h1>
- <form action="?" method="post" name="123">
+ <form action="?" method="post" name="form name">
<input type="text" name="t" value="" />
- <input type="submit" name="456"/>
+ <input type="submit" name="subbutton"/>
</form>
View
94 system/prototypes/johana/request.js
@@ -48,137 +48,141 @@ JohanaRequest.current;
* @uses Route.all
* @uses Route.matches
*/
-JohanaRequest.factory = function(uri, req)
+JohanaRequest.factory = function(uri, request)
{
- uri = uri || true; req = req || false;
+ if (uri == undefined)
+ {
+ uri = true;
+ }
+ request = request || false;
- var protocol, method, referrer, userAgent, clientIp, requestedWith, body = '';
+ var protocol, secure, method, referrer, userAgent, clientIp, requestedWith, body = '';
// If this is the initial request
- if ( 1 )
+ if (uri === true)
{
- if (req.method)
+ if (request.connection.encrypted !== undefined)
{
- // Use the server request method
- method = req.method;
+ // This request is secure
+ secure = true;
+ protocol = 'HTTPS/' + request.httpVersion;
}
else
{
- // Default to GET requests
- method = HttpRequest.GET;
+ protocol = 'HTTP/' + request.httpVersion;
}
- if (req.connection.encrypted !== undefined)
+ if (request.method)
{
- // This request is secure
- protocol = 'https';
+ // Use the server request method
+ method = request.method;
}
else
{
- protocol = 'http';
+ // Default to GET requests
+ method = HttpRequest.GET; // TODO:
}
- if (req.headers['referer'] !== undefined)
+ if (request.headers['referer'] !== undefined)
{
// There is a referrer for this request
- referrer = req.headers['referer'];
+ referrer = request.headers['referer'];
}
- if (req.connection.socket !== undefined)
+ if (request.connection.socket !== undefined)
{
// Client ip
- clientIp = req.connection.socket.remoteAddress;
+ clientIp = request.connection.socket.remoteAddress;
}
- else if (req.connection.remoteAddress)
+ else if (request.connection.remoteAddress)
{
// Client ip
- clientIp = req.connection.remoteAddress;
+ clientIp = request.connection.remoteAddress;
}
- if (req.headers['user-agent'] !== undefined)
+ if (request.headers['user-agent'] !== undefined)
{
// Browser type
- userAgent = req.headers['user-agent'];
+ userAgent = request.headers['user-agent'];
}
- if (req.headers['x-requested-with'] !== undefined)
+ if (request.headers['x-requested-with'] !== undefined)
{
// Typically used to denote AJAX requests
- requestedWith = req.headers['x-requested-with'];
+ requestedWith = request.headers['x-requested-with'];
}
if (method !== 'GET')
{
// Ensure the raw body is saved for future use
- req.on('data', function(data) {
+ request.on('data', function(data) {
body += data;
});
- req.on('end', function(){
+ request.on('end', function(){
// Set the request body (probably a PUT type)
- request.body(require('querystring').parse(body));
- console.log(require('querystring').parse(body));
+ instance.post(require('querystring').parse(body));
});
}
-// if (uri === true)
-// {
-// // Attempt to guess the proper URI
-// uri = Request.detect_uri();
-// }
+ if (uri === true)
+ {
+ // Attempt to guess the proper URI
+ uri = request.uri;
+ }
// Create the instance singleton
- var request = new Request(uri);
+ var instance = new Request(uri);
- Request.initial = request;
+ Request.initial = instance;
- //console.log(req);
// Store global GET and POST data in the initial request only
- request.query(require('querystring').parse(req.url));
-// request.post(_POST);
+ var query = request.url.replace(/[^\?]*\?/, '');
+ query = require('querystring').parse(query);
+ instance.query(query);
if (protocol !== undefined)
{
// Set the request protocol
- request.protocol(protocol);
+ instance.protocol(protocol);
}
if (method !== undefined)
{
// Set the request method
- request.method(method);
+ instance.method(method);
}
if (referrer !== undefined)
{
// Set the referrer
- request.referrer(referrer);
+ instance.referrer(referrer);
}
if (userAgent !== undefined)
{
// Set the referrer
- request.userAgent(userAgent);
+ instance.userAgent(userAgent);
}
if (clientIp !== undefined)
{
// Set the referrer
- request.clientIp(clientIp);
+ instance.clientIp(clientIp);
}
if (requestedWith !== undefined)
{
// Apply the requested with variable
- request.requestedWith(requestedWith);
+ instance.requestedWith(requestedWith);
}
}
else
{
- var request = new Request(uri);
+ var instance = new Request(uri);
}
- return request;
+ return instance;
};
/**

0 comments on commit 1bee78f

Please sign in to comment.