Created
April 30, 2013 18:44
-
-
Save minitech/5490934 to your computer and use it in GitHub Desktop.
JavaSckript Moste Evile. Run with node --harmony-proxies, then just run.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with(evil()) { | |
get /user | |
(response) ( | |
response.write("Hello, world!") | |
) | |
post /user | |
(response) ( | |
response.write("Unauthorized!") | |
) | |
serve(8080) | |
} | |
function evil() { | |
var state = 0; | |
var method; | |
var path; | |
var argumentName; | |
var responses = {}; | |
return Proxy.create({ | |
getPropertyDescriptor: function(name) { | |
if(name === "serve") { | |
return {value: function(port) { | |
return require("http").createServer(function(req, res) { | |
var content = responses[req.method] && responses[req.method][req.url]; | |
if(!content) { | |
res.writeHead(404, {"Content-Type": "text/html"}); | |
res.end("<h1>404 Not Found</h1>"); | |
return; | |
} | |
res.writeHead(200, {"Content-Type": "text/html"}); | |
res.end(content); | |
}).listen(port); | |
}}; | |
} | |
switch(state / 2 | 0) { | |
case 0: | |
method = name.toUpperCase(); | |
state++; | |
return {value: 1}; | |
case 1: | |
path = "/" + name; | |
state++; | |
return {value: function() { | |
return function(content) { | |
if(!responses[method]) responses[method] = {}; | |
responses[method][path] = content; | |
state = 0; | |
}; | |
}}; | |
case 2: | |
argumentName = name; | |
state++; | |
return {value: null}; | |
case 3: | |
if(name === argumentName) { | |
return {value: {write: function(x) { return x; }}}; | |
} | |
} | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment