tests/soup.js
[gitlive] / tests / soup.js
1 #!/usr/bin/env seed
2
3 Soup = imports.gi.Soup;
4 Netrc = imports['../Netrc.js'].Netrc;
5
6 GLib = imports.gi.GLib;
7
8 var session = new Soup.SessionSync();
9 File  = imports['../File.js'].File;
10
11  
12 // Soup.URI is a struct.
13 var uri = new Soup.URI.c_new("http://www.roojs.com/admin.php/Roo/Events");
14 //var uri = new Soup.URI.c_new("http://www.roojs.com/head.php");
15
16 var msg = new Soup.Message({method:"POST", uri:uri});
17 //var msg = new Soup.Message({method:"GET", uri:uri});
18
19 // post..
20 buftxt =  "remarks=test";
21  
22 msg.set_request('application/x-www-form-urlencoded', Soup.MemoryUse.COPY, buftxt, buftxt.length)
23
24
25 var auth = new Soup.Auth.c_new(Soup.AuthBasic.type, msg, "Basic realm=\"Test\"");
26  
27 var authvals = Netrc.forHost('git.roojs.com');
28
29 auth.authenticate(authvals.login ,authvals.password);
30 var authmsg = auth.get_authorization(msg);
31 //print(authmsg);
32 msg.request_headers.append('Authorization', authmsg)
33
34 //request.headers_append...
35 var status = session.send_message(msg);
36 // session.queue_message(function(ses, msg) {
37 //
38 //}
39 //)
40 print(status);
41
42 print(msg.response_body.data);
43
44
45 function XMLHttpRequest() {
46     
47     
48 }
49
50 XObject.extend(XMLHttpRequest,{ 
51     // event handlers
52     //onreadystatechange;
53     //onloadstart;
54     //onprogress;
55     //onabort;
56     //onerror;
57     //onload;
58     //ontimeout;
59     //onloadend;
60     
61     timeout : 0,
62     withCredentials : false,
63     
64     // states
65     UNSENT : 0,
66     OPENED : 1,
67     HEADERS_RECEIVED : 2,
68     LOADING : 3,
69     DONE : 4,
70     
71     // readonly..
72     readyState : 0,
73     upload: null,
74     
75     // request
76     open : function ( method,  url, async, user, password) {
77         async = async || false;
78         user = user || false;
79         password = password || false;
80     },
81     
82     setRequestHeader : function ( header,  value)
83     {
84            
85     },
86      overrideMimeType : function ( mime)
87     {
88         
89     },
90     send  : function(data)
91     {
92         
93     },
94     abort : function()
95     {
96         
97     },
98     
99     // response (all readonly...)
100     status : false,
101     statusText : false,
102     //readonly attribute any response
103     responseText : false,
104     responseXML : false,
105     responseType : false, 
106     
107     // response - read
108     getResponseHeader : function(  header)
109     {
110         
111     },
112     getAllResponseHeaders : function ()
113     {
114         
115     }
116    
117     
118 });