4 idea is a async http request.
6 -- question is are we creating a generic request.. or just doing a silly wrapper of Soup?
11 x.connect.complete((headers, body, body_len) => {
15 x.run(); // returns instantly...
19 a - json fetches from main server.. (async not needed)
20 b - head request on page to see if it's changed -- async usefull - we might want to be doing a few at the same time..
21 c - body requests on a page... async usefull - we might want to be doing a few at the same time..
25 valac --thread -g Request.vala --pkg glib-2.0 --pkg gee-1.0 --pkg libsoup-2.4 --pkg gio-2.0 -o /tmp/req --target-glib=2.32 -X -lm -X -pg
31 var loop = new MainLoop();
32 var x = new Request("HEAD", "http://jobsonboats.com/");
33 x.complete.connect((uri, headers, body, body_len) => {
34 print("ct: %s", headers.get("Content-type"));
35 print("got body %d\n", (int)body_len);
42 public class Request : Object
46 public string method = "GET";
47 public signal void complete( Soup.URI uri, Gee.HashMap<string,string> head, uint8[]? body, int64 length);
49 public Request(string method, string url)
59 Soup.Session session = new Soup.Session ();
61 session.use_thread_context = true;
63 var msg = new Soup.Message(this.method, this.url);
65 var headers= new Gee.HashMap<string,string>();
67 session.queue_message (msg, (obj, mess) => {
68 print ("Status Code: %u\n", mess.status_code);
69 print ("Final URL: %s\n", mess.uri.to_string (false));
71 mess.response_headers.foreach ((name, val) => {
72 print("HEADER %s: %s\n", name,val);
73 headers.set(name, val);
75 if (this.method == "HEAD") {
76 this.complete(mess.uri, headers, null, 0);
78 this.complete(mess.uri, headers, mess.response_body.data, mess.response_body.length);