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