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     readyState : 0,
72
73     // request
74     open : function ( method,  url, async, user, password) {
75         async = async || false;
76         user = user || false;
77         password = password || false;
78     },
79     
80     setRequestHeader : function ( header,  value);
81            
82     readonly attribute XMLHttpRequestUpload upload;
83     void send(data);
84     void send(ArrayBuffer data);
85     void send(Blob data);
86     void send(Document data);
87     void send(DOMString? data);
88     void send(FormData data);
89     void abort();
90     
91     // response
92     readonly attribute unsigned short status;
93     readonly attribute DOMString statusText;
94     DOMString getResponseHeader(DOMString header);
95     DOMString getAllResponseHeaders();
96     void overrideMimeType(DOMString mime);
97              attribute XMLHttpRequestResponseType responseType;
98     readonly attribute any response;
99     readonly attribute DOMString responseText;
100     readonly attribute Document responseXML;
101 };