Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / phantomjs / lib / phantom / examples / server.js
1 var page = require('webpage').create();
2 var server = require('webserver').create();
3 var system = require('system');
4 var host, port;
5
6 if (system.args.length !== 2) {
7     console.log('Usage: server.js <some port>');
8     phantom.exit(1);
9 } else {
10     port = system.args[1];
11     var listening = server.listen(port, function (request, response) {
12         console.log("GOT HTTP REQUEST");
13         console.log(JSON.stringify(request, null, 4));
14
15         // we set the headers here
16         response.statusCode = 200;
17         response.headers = {"Cache": "no-cache", "Content-Type": "text/html"};
18         // this is also possible:
19         response.setHeader("foo", "bar");
20         // now we write the body
21         // note: the headers above will now be sent implictly
22         response.write("<html><head><title>YES!</title></head>");
23         // note: writeBody can be called multiple times
24         response.write("<body><p>pretty cool :)</body></html>");
25         response.close();
26     });
27     if (!listening) {
28         console.log("could not create web server listening on port " + port);
29         phantom.exit();
30     }
31     var url = "http://localhost:" + port + "/foo/bar.php?asdf=true";
32     console.log("SENDING REQUEST TO:");
33     console.log(url);
34     page.open(url, function (status) {
35         if (status !== 'success') {
36             console.log('FAIL to load the address');
37         } else {
38             console.log("GOT REPLY FROM SERVER:");
39             console.log(page.content);
40         }
41         phantom.exit();
42     });
43 }