Hi, I've written some code to perform simple http POST/GET operations using a GNet GConn. So far it seems to work quite okay, but it hasn't been extensively tested, nor has HTTP/1.1-compliance been checked thoroughly. Basically I would like to get some comments on the API at this point. Some notes: * I was aiming for a minimal API. Currently, the shortest way to retrieve a file goes like this (without much error checking): httpconn = gnet_conn_http_new(); gnet_conn_http_set_uri (httpconn, "http://www.google.com"); if (gnet_conn_http_run (httpconn, NULL,NULL)) { if (gnet_conn_http_steal_buffer(httpconn, &buf, &len)) { g_print("Retrieved %u bytes:\n%s\n", len, buf); g_free(buf); } } * Rather than going for a trizillion _get functions I decided to use a callback mechanism (which is optional) with event-dependent event structs similar to how the GdkEvent stuff works. Arguably this might be a bit overdone, but I find it more convenient and easier to expand than having loads of _get functions. Also, it resembles how GConn and much else of the GNet API works. * I decided not to 'derive' explicitely from GConn, but keep the GConnHttp structure opaque. I don't see a reason why people would need to mess with the underlying GConn, so hiding it completely seems best to me. * The namespace is a bit awkward, but still better than creating confusion by clashing with the (abandoned?) ghttp library namespace. Attached some code including a test program. Set verbose to TRUE in main() to get a better idea what's happening. Currently supported: * GET method * POST method * automatic redirections * persistent connections * chunked transfer-encoding TODO: * support for http proxies * authentication support * checking for HTTP/1.1 standard compliance (or even 1.0 really) Any comments would be much appreciated. Cheers -Tim
Attachment:
gnet-conn-http-0.1.tar.gz
Description: application/tgz