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    nl.split(/\s+/).foreach(function(kv) {
15         if (!k) {
16             k = kv;
17             return
18         }
19         line[k] = kv
20         k = false;
21    });
22    
23    lines[line.machine] = line;
24     
25 });
26
27 // Soup.URI is a struct.
28 var uri = new Soup.URI.c_new("http://www.roojs.com/admin.php/Roo/person");
29 var msg = new Soup.Message({method:"GET", uri:uri});
30
31 var auth = new Soup.Auth.c_new(Soup.AuthBasic.type, msg, "Basic realm=\"Test\"");
32 print(auth);
33 print(auth.authenticate);
34 auth.authenticate('aaaa','bbbb');
35 var authmsg = auth.get_authorization(msg);
36
37 msg.request_headers.append('Authorization', authmsg + '==')
38
39 //request.headers_append...
40 var status = session.send_message(msg);
41 // session.queue_message(function(ses, msg) {
42 //
43 //}
44 //)
45 print(status);
46
47 print(msg.response_body.data);