tests/soup.js
[gitlive] / tests / soup.js
1 #!/usr/bin/env seed
2
3 Soup = imports.gi.Soup;
4 GLib = imports.gi.GLib;
5
6 var session = new Soup.SessionSync();
7 File  = imports['../File.js'].File;
8
9 var netrc = File.read(GLib.get_home_dir() + "/.netrc");
10 var lines = {};
11 netrc.split("\n").forEach(function(nl) {
12     var line = {};
13     var k = false
14     print(JSON.stringify(nl));
15
16     nl.replace(/\s+$/,'').replace(/^\s+/,'').split(/\s+/).forEach(function(kv) {
17         print(JSON.stringify(kv));
18
19         if (!k) {
20             k = kv;
21             return
22         }
23         line[k] = kv
24         k = false;
25    });
26         print(JSON.stringify(line));
27
28    lines[line.machine] = line;
29     
30 });
31 print(JSON.stringify(lines));
32
33 // Soup.URI is a struct.
34 var uri = new Soup.URI.c_new("http://www.roojs.com/admin.php/Roo/person");
35 var msg = new Soup.Message({method:"GET", uri:uri});
36
37 var auth = new Soup.Auth.c_new(Soup.AuthBasic.type, msg, "Basic realm=\"Test\"");
38 print(auth);
39 print(auth.authenticate);
40 auth.authenticate('aaaa','bbbb');
41 var authmsg = auth.get_authorization(msg);
42
43 msg.request_headers.append('Authorization', authmsg + '==')
44
45 //request.headers_append...
46 var status = session.send_message(msg);
47 // session.queue_message(function(ses, msg) {
48 //
49 //}
50 //)
51 print(status);
52
53 print(msg.response_body.data);